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

Від 07.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 or Violentmonkey 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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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.

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

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

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

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

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

// ==UserScript==
// @name        挊
// @namespace   撸
// @description 自动获取磁链接并自动离线下载
// @include     http://www.javzoo.com/*
// @include     http://www.avmask.com/*
// @include     http://www.javlibrary.com/*
// @include     http://pan.baidu.com/disk/home
// @include     http://115.com/?tab=offline&mode=wangpan
// @include     http://cloud.letv.com/webdisk/home/index
// @version     1.03
// @grant       GM_xmlhttpRequest
// @grant       GM_setClipboard
// @grant       GM_setValue
// @grant       GM_getValue
// ==/UserScript==
var av_id = "";
var xhr = function(url,cb){
  GM_xmlhttpRequest({
      method: 'GET',
      url: url,
      onload: function(result){
        cb(result.responseText);
      },
      onerror: function (e) {
        console.log(e);
      }
  });
};
var exist_magnet = function(callback){
  var magnet = GM_getValue("magnet");
  GM_setValue("magnet","");
  if(magnet){
    callback(magnet);
  }
};
var insert_js = function(magnet,func){
  var js = document.createElement("script");
  js.innerHTML = "("+func.toString()+")('"+ magnet +"');";
  console.log(js);
  document.body.appendChild(js);
};
var hostmatch = function(url,callback){
  if(location.host == url){
    callback();
  }
};
var add_style = function(css){
  var style = document.createElement("style");
  style.innerHTML = css;
  document.head.appendChild(style);
};
var create_table = function(data){
  var table = document.createElement("table");
  var html="<tr><th class='magnet-th'>HASH</th><th class='magnet-th'>大小</th><th class='magnet-th'>操作</th><th class='magnet-th'>离线下载</th></tr>";
  for(var i=0;i<data.length;i++){
    html += "<tr hash='"+ data[i].hash +"'><td class='magnet-td'>"+ data[i].hash +"</td>";
    html += "<td class='magnet-td'>"+ data[i].size +"</td>";
    html += "<td class='magnet-td'><a class='magnet-copy' href='javascript:void(0);'>复制</a></td>";
    html += "<td class='magnet-td'><a class='magnet-download' target='_blank' href='http://pan.baidu.com/disk/home'>百度云</a> | <a class='magnet-download' target='_blank' href='http://115.com/?tab=offline&mode=wangpan'>115离线</a> | <a class='magnet-download' target='_blank' href='http://cloud.letv.com/webdisk/home/index'>乐视云盘</a></td>";//
    html += "</tr>";
  }
  table.innerHTML = html;
  return table;

};

var gethash = function(av_id,search_url,callback){
  xhr(search_url+av_id,function(html){
    var data=[];
    var doc = document.implementation.createHTMLDocument("");
    doc.documentElement.innerHTML = html;
    if(search_url == "http://www.btspread.com/search/"){
      var t = doc.getElementsByTagName("tbody")[0];
      if(!t){return;}
      else{
        var aElems = t.getElementsByClassName("action");
        var bElems = t.getElementsByClassName("files-size");
        var tmp;
        for(var i=0;i<aElems.length;i++){
          tmp = aElems[i].firstChild.href;
          data.push({"hash":tmp.substring(tmp.indexOf("hash/")+5),"size":bElems[i].textContent});
        }
        callback(data);
      }
    }
  });
};
var handle_copy = function(elements){
  for(var i=0;i<elements.length;i++){
    elements[i].addEventListener("click",function(event){
      GM_setClipboard("magnet:?xt=urn:btih:" + event.target.parentElement.parentElement.getAttribute("hash"));
    },false);
  }
};
var handle_download = function(elements){
  for(var i=0;i<elements.length;i++){
    elements[i].addEventListener("click",function(event){
      GM_setValue("magnet","magnet:?xt=urn:btih:"+event.target.parentElement.parentElement.getAttribute("hash"));
    },false);
  }
};
hostmatch("www.javzoo.com",function(){
  if(location.href.match("movie")){
    av_id = document.getElementsByClassName("header")[0].nextElementSibling.innerHTML;
    var search_url = "http://www.btspread.com/search/";
    gethash(av_id,search_url,function(data){
      add_style("#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;}");
      var table = create_table(data);
      var title = document.createElement("h4");
      title.innerHTML = "磁链接";
      var wrapper = document.createElement("div");
      wrapper.id="magnet-table";
      wrapper.appendChild(table);
      var tmp = document.getElementById("movie-share");
      tmp.parentElement.insertBefore(wrapper,tmp.nextElementSibling);
      tmp.parentElement.insertBefore(title,tmp.nextElementSibling);

      handle_copy(document.getElementsByClassName("magnet-copy"));
      handle_download(document.getElementsByClassName("magnet-download"));
    });
  }
});
hostmatch("www.avmask.com",function(){
  if(location.href.match("movie")){
    av_id = document.getElementsByClassName("header")[0].nextElementSibling.innerHTML;
    var search_url = "http://www.btspread.com/search/";
    gethash(av_id,search_url,function(data){
      add_style("#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;}");
      var table = create_table(data);
      var title = document.createElement("h4");
      title.innerHTML = "磁链接";
      var wrapper = document.createElement("div");
      wrapper.id="magnet-table";
      wrapper.appendChild(table);
      var tmp = document.getElementById("movie-share");
      tmp.parentElement.insertBefore(wrapper,tmp.nextElementSibling);
      tmp.parentElement.insertBefore(title,tmp.nextElementSibling);

      handle_copy(document.getElementsByClassName("magnet-copy"));
      handle_download(document.getElementsByClassName("magnet-download"));
    });
  }
});
hostmatch("www.javlibrary.com",function(){
  if(location.search.match("\\?v=")){
    av_id = document.getElementById("video_id").getElementsByClassName("text")[0].innerHTML;
    var search_url = "http://www.btspread.com/search/";
    gethash(av_id,search_url,function(data){
      add_style("#magnet-table table{margin:10px auto;border:1px solid #cad9ea;color:#666;text-align: center;}.magnet-th,.magnet-td{height:30px; border:1px solid #cad9ea;padding:0 1em 0;}.magnet-copy{color:#08c;}.magnet-download{color:#0003FF;}");
      var table = create_table(data);
      var title = document.createElement("h4");
      title.innerHTML = "磁链接";
      var wrapper = document.createElement("div");
      wrapper.id="magnet-table";
      wrapper.appendChild(table);
      var tmp = document.getElementById("video_favorite_edit");
      tmp.parentElement.insertBefore(wrapper,tmp.nextElementSibling);
      tmp.parentElement.insertBefore(title,tmp.nextElementSibling);
      handle_copy(document.getElementsByClassName("magnet-copy"));
      handle_download(document.getElementsByClassName("magnet-download"));
    });
  }
});
hostmatch("pan.baidu.com",function(){
  exist_magnet(function(magnet){
    insert_js(magnet,function(magnet){
      $(".icon-btn-download").click();
      setTimeout(function(){
        $("#_disk_id_24").click();
        setTimeout(function(){
          $("#_disk_id_12").click();
          $("#share-offline-link").val(magnet);
        },500);
      },500);
    });
  });
});
hostmatch("115.com",function(){
  exist_magnet(function(magnet){
    insert_js(magnet,function(magnet){
      setTimeout(function(){
        Core['OFFL5Plug'].OpenLink();
        setTimeout(function(){
          $("#js_offline_new_add").val(magnet);
        },0);
      },1000);
    });
  });
});
hostmatch("cloud.letv.com",function(){
  exist_magnet(function(magnet){
    insert_js(magnet,function(magnet){
      console.log(1);
      setTimeout(function(){
        console.log(2);
        $("#offline-btn").click();
        setTimeout(function(){
          console.log(3);
          $("#offline_clear_complete").prev().click();
          setTimeout(function(){
            $("#offline-add-link").val(magnet);
          },500);
        },1000);
      },3000);
    });
  });
});