Last active
December 23, 2015 11:21
-
-
Save masterofpun/065433ead7a75e197116 to your computer and use it in GitHub Desktop.
Adds a button to kickass to copy magnet link and open transmission web interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name kat.cr magnet link fixer | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description construct a better magnet link | |
// @author You | |
// @match https://kat.cr/* | |
// @grant GM_setClipboard | |
// @grant GM_openInTab | |
// ==/UserScript== | |
/* jshint -W097 */ | |
'use strict'; | |
var piLink = 'http://192.168.1.5:9091/transmission/web/'; | |
var trackerList = document.getElementById('utorrent_textarea').textContent; | |
var torrentId = document.getElementById('report_button').href; | |
trackerList = trackerList.replace(/\s+/g,' '); | |
torrentId = torrentId.split('/')[5]; | |
var trackers = trackerList.split(' '); | |
console.log('id : ' + torrentId); | |
console.log('list : ' + trackerList); | |
var magnetLink = 'magnet:?xt=urn:btih:'+torrentId; | |
for(var i = 0; i < trackers.length; i++){ | |
var tracker = trackers[i]; | |
magnetLink = magnetLink + '&tr=' + tracker; | |
} | |
console.log(magnetLink); | |
var buttonContainer = document.getElementsByClassName('goodFake'); | |
var piButton = document.createElement('a'); | |
piButton.href = piLink; | |
piButton.target = '_blank'; | |
piButton.onclick = function() {GM_setClipboard (magnetLink, "{ type: 'text', mimetype: 'text/plain'}");}; | |
addGlobalStyle('.goodFake { width: 114px; }'); | |
piButton.appendChild(document.createTextNode('Send to Pi')); | |
buttonContainer[0].appendChild(piButton); | |
var allLinks = document.getElementsByTagName('a'); | |
for (var i = 0; i < allLinks.length; i++) | |
if(allLinks[i].title == 'Magnet link') | |
allLinks[i].href = magnetLink; | |
function addGlobalStyle(css) { | |
var head, style; | |
head = document.getElementsByTagName('head')[0]; | |
if (!head) { return; } | |
style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.innerHTML = css; | |
head.appendChild(style); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment