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

当前为 2015-03-05 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        挊
// @namespace   撸
// @description 自动获取磁链接并自动离线下载
// @include     http://www.javzoo.com/*
// @include     http://www.avmask.com/*
// @include     http://pan.baidu.com/disk/home*
// @version     1.02
// @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 html="<tr><th class='magnet-th'>HASH</th><th class='magnet-th'>操作</th><th class='magnet-th'>下载</th></tr>";
      for(var i=0;i<hash_list.length;i++){
        html += "<tr><td class='magnet-td'>%hash</td><td class='magnet-td'><a class='magnet-copy' href='javascript:void(0);' hash='%hash'>复制</a></td><td class='magnet-td'><a class='magnet-download' target='_blank' href='http://pan.baidu.com/disk/home?magnet=%hash'>离线下载</a></td></tr>".replace(/%hash/g,hash_list[i]);
      }
      var title = document.createElement("h4");
      title.innerHTML = "磁链接";
      var wrapper = document.createElement("div");
      wrapper.id="magnet-table";
      var table = document.createElement("table");
      table.innerHTML = html;
      wrapper.appendChild(table);
      var tmp = document.getElementById("movie-share");
      tmp.parentElement.insertBefore(wrapper,tmp.nextElementSibling);
      tmp.parentElement.insertBefore(title,tmp.nextElementSibling);

      var style = document.createElement("style");
      style.innerHTML = "#magnet-table table{margin:10px auto;border:1px solid #cad9ea;color:#666;}.magnet-th,.magnet-td{height:30px; border:1px solid #cad9ea;padding:0 1em 0;}.magnet-copy{color:#08c;}.magnet-download{color:#0003FF;}";
      document.head.appendChild(style);
      
      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.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);
  }
}