Torrentz2 Magnet link Support

Shows direct magnet link next to the result table

Click here to install Browse More Scripts
// ==UserScript==
// @name         Torrentz2 Magnet link Support
// @namespace    3f52e415555ea3b97b52cfb2ec72813f68c94215
// @version      0.2
// @description  Shows direct magnet link next to the result table
// @author       /u/AyrA_ch
// @match        https://torrentz2.eu/*
// @match        https://torrentz2.is/*
// @grant        none
// ==/UserScript==

//Version history
//0.2 - Added ".is" domain
//0.1 - Initial version

(function ($, $$) {
	'use strict';
	//Magnet symbol (not used because it's not supported on Win7): 🧲
	var dataURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAq1BM" +
		"VEVDkfj///9jEBBtERFaEBDvKBjnIRhKCQneIRjvKSHnKSHQ1ttSEBBldHrsXVXX3uNWCAhIVVxse4TvMSbf" +
		"5+nxaWPu7O2BEQ+wSUnvSD/vOTBTX2bvUktaa3HnRDvasLC9xcrIztK4cXH79/ivNTDKJR21vMBGSk55hYmE" +
		"jZTeLyersreKLy6Rmp7fwsLn0dHVT0y6HxrKkpLu3NyjFhFje4SgUVGEXWCyXFyZlEHOAAAAAXRSTlMAQObY" +
		"ZgAAAIdJREFUGNNVj90KgzAMhcOEIil64SaCTosXQucqdKPQ938zj50/2bk5+U5ISIh21aUnoXJg5vmKnnew" +
		"YvaCp0+O5GClQubchKmNTQuOKPwv0A/DwaXNGIQt4xgT1y1zgFf2FQ/OU6foT26uy8ywsTsZm2fJtGj9bW7i" +
		"l8q+bSafo74r6F/d7iuCFws3ReCCSgAAAABJRU5ErkJggg==";

	//Get all links from the result table
	var links = $$(".results dt a");
	for (var i = 0; i < links.length; i++) {
		var torrent = links[i];
		//Extract the info hash from the link
		var btih = torrent.href.match(/[\da-f]{40}/i);
		if (btih) {
			//Create magnet URL with hash and torrent name suggestion
			var magnetURL = "magnet:?xt=urn:btih:" + btih[0] + "&dn=" + encodeURIComponent(torrent.textContent);
			//Create magnet image and link
			var magnetImg = document.createElement("img");
			var magnetTag = document.createElement("a");
			magnetImg.src = dataURL;
			magnetTag.href = magnetURL;
			magnetTag.title = "Click to add to your torrent client directly";
			magnetTag.appendChild(magnetImg);
			//Insert before the link text
			torrent.parentNode.insertBefore(magnetTag, torrent);
			//Add a space
			torrent.parentNode.insertBefore(document.createTextNode(' '), torrent);
		}
	}
})(document.querySelector.bind(document), document.querySelectorAll.bind(document));

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 98.80.143.34