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

اعتبارا من 04-03-2015. شاهد أحدث إصدار.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل 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);
  }
}