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

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

您需要先安装一款用户脚本管理器扩展,例如 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.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);
  }
}