自动地获取磁链接并自动离线下载

Versione datata 04/03/2015. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        拤
// @namespace   撸
// @description 自动地获取磁链接并自动离线下载
// @include     http://www.javzoo.com/*
// @include     http://www.avmask.com/*
// @include     http://pan.baidu.com/disk/home*
// @version     1.0
// @grant       GM_xmlhttpRequest
// @grant       GM_setClipboard
// ==/UserScript==
if(location.host=="www.javzoo.com" || location.host=="www.avmask.com"){
  //if(!location.pathname.match("/cn")) location.pathname = "/cn";
  var gethashs = function(av_id,callback){
    var hash_list = [];
    var doc = document.implementation.createHTMLDocument("");
      GM_xmlhttpRequest({
      method: 'GET',
      url: "http://www.btspread.com/search/"+ av_id,
      onload: function(result){
        doc.documentElement.innerHTML = result.responseText;
        if(!doc.getElementsByTagName("tbody")[0]){return;}
        var eles = doc.getElementsByTagName("tbody")[0].getElementsByClassName("action");
        for(var i=0;i<eles.length;i++){
          var tmp = eles[i].firstChild.href;
          hash_list.push(tmp.substring(tmp.indexOf("hash/")+5));
        }
        callback(hash_list);
      },
      onerror: function (e) {
        console.log(e);
      }
    });
  };
  if(location.href.match("movie")){//介绍页面
    var av_id = document.getElementsByClassName("header")[0].nextElementSibling.innerHTML;//番号
    gethashs(av_id,function(hash_list){
      var wrapper = document.createElement("div");
      wrapper.id="magnet-wrapper";
      for(var i=0;i<hash_list.length;i++){
        var container = document.createElement("p");
        container.className = "magnet";
        container.setAttribute("hash",hash_list[i]);
        container.innerHTML = "<span>"+hash_list[i]+"</span><a class='magnet-copy' href='javascript:void(0);'>copy</a><a class='magnet-download' target='_blank' href='http://pan.baidu.com/disk/home?magnet="+ hash_list[i] +"'>download</a>";
        wrapper.appendChild(container);
      }

      var tmp = document.getElementById("movie-share");
      tmp.parentElement.insertBefore(wrapper,tmp);//页面添加元素
      
      var elements = document.getElementsByClassName("magnet-copy");
      for(var k=0;k<elements.length;k++){
        elements[k].addEventListener("click",function(event){
          GM_setClipboard("magnet:?xt=urn:btih:" + event.target.parentElement.getAttribute("hash"));//复制磁链接到剪切板
        },false);
      }
    });
  }
}
else if(location.host=="pan.baidu.com"){
  if(location.search.match("magnet")){
    var js = document.createElement("script");
    js.innerHTML = "("+ (function(){
      $(".icon-btn-download").click();
      setTimeout(function(){
        $("#_disk_id_24").click();
        setTimeout(function(){
          $("#_disk_id_12").click();
          $("#share-offline-link").val(location.search.replace("?magnet=","magnet:?xt=urn:btih:"));
          window.history.pushState({},0,"home");
        },500);
      },500);
    }).toString() + ")()";
    document.body.appendChild(js);
  }
}