Add torrent download button to idope.se

Adds a torrent download button to idope.se

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Add torrent download button to idope.se
// @namespace    http://www.dieterholvoet.com
// @version      1.0
// @description  Adds a torrent download button to idope.se
// @author       Dieter Holvoet
// @match        https://idope.se/torrent/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    
    // Variables
    var styles = "display: block; color: white; background: url(https://idope.se/static/search/pc/img/infodownloadbackground.png); width: 110px; float: left; height: 26px; line-height: 26px; text-align: center; font-size: 12px;";
    
    var btn_magnet = document.getElementById("downloaddiv"),
        btn_magnet_new = document.createElement("a"),
        btn_torrent = document.createElement("a"),
        btn_share = document.getElementsByClassName("share")[0],
        magnet_url = document.getElementById("mangetinfo").getAttribute("href"),
        container = btn_magnet.parentNode;
    
    // Create magnet button
    btn_magnet_new.innerText = "MAGNET";
    btn_magnet_new.setAttribute("style", styles);
    btn_magnet_new.setAttribute("href", magnet_url);
    btn_magnet_new.style.margin = "14px 0 0 0";
    
    // Create torrent button
    btn_torrent.innerText = "TORRENT";
    btn_torrent.setAttribute("style", styles);
    btn_torrent.setAttribute("href", "http://itorrents.org/torrent/"+magnet_url.split(":").slice(-1)[0]+".torrent");
    btn_torrent.style.margin = "14px 0 0 8px";
    
    // Remove and insert buttons
    container.insertBefore(btn_magnet_new, btn_share);
    container.insertBefore(btn_torrent, btn_share);
    
    container.removeChild(btn_magnet);
    document.getElementById("magnet").style.visibility = "hidden";
    
})();