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

目前為 2015-03-04 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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);
  }
}