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

As of 25.04.2015. See апошняя версія.

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.

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.avsow.com/*
// @include     http://www.avmask.com/*
// @include     http://www.javlibrary.com/*
// @include     http://www.dmm.co.jp/digital/videoa/*
// @include     http://www.libredmm.com/products/*
// @include     http://www.minnano-av.com/av*
// @include     http://www.oisinbosoft.com/dera/*
// @include     http://www.javbus.com/*
// @include     http://avdb.la/movie/*
// @include     http://www.141jav.com/view/*
// @include     http://pan.baidu.com/disk/home
// @include     http://115.com/?tab=offline&mode=wangpan
// @include     http://cloud.letv.com/webdisk/home/index
// @include     https://www.furk.net/users/files/add
// @include     *.yunpan.360.cn/my/
// @version     1.07
// @run-at      document-end
// @grant       GM_xmlhttpRequest
// @grant       GM_setClipboard
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       GM_addStyle
// ==/UserScript==
var $ = function (selector) {
  var result = document.querySelectorAll(selector);
  if(selector[0] == "#"){
    return result[0];
  }
  else{
    return result;
  }
};
var $ib = function (target, a, b) {
  target.parentElement.insertBefore(a, b);
}
var xhr = function (url, cb) {
  GM_xmlhttpRequest({
    method: 'GET',
    url: url,
    onload: function (result) {
      console.log('番号搜索', url);
      cb(result.responseText);
    },
    onerror: function (e) {
      console.log(e);
    }
  });
};
var exist_magnet = function (callback) {
  var magnet = GM_getValue('magnet');
  if (magnet) {
    GM_setValue('magnet', '');
    callback(magnet);
  }
};
var insert_js = function (magnet, func) {
  var js = document.createElement('script');
  js.innerHTML = '(' + func.toString() + ')(\'' + magnet + '\');';
  document.body.appendChild(js);
};
var hostmatch = function (url) {
  if (location.host == url) {
    return true;
  }
  return false;
};
var add_style = function (css) {
  if (css) {
    GM_addStyle(css);
  } 
  else {
    GM_addStyle([
      '#magnet-tab table{margin:10px auto;border:1px solid #cad9ea;color:#666;font-size:12px;text-align:center;}',
      '.magnet-th,.magnet-td{height:30px; border:1px solid #cad9ea;padding:0 1em 0;}',
      '.magnet-copy{color:#08c;}',
      '.magnet-download{color: #d22222;margin-right: 4px;border: solid 1px #000;}'
      ].join(""));
  }
};
var shorten_str = function(str){
    return str.length>35 ? str.slice(0,35)+"..." : str;
};
var offline_url = function(html){
  var d = {
    baidu:{
      url:"http://pan.baidu.com/disk/home",
      name:"百度云",
    },
    115:{
      name:"115离线",
      url:"http://115.com/?tab=offline&mode=wangpan"
    },
    letv:{
      name:"乐视云",
      url:"http://cloud.letv.com/webdisk/home/index"
    },
    360:{
      name:"360云",
      url:"http://yunpan.360.cn/my/"
    },
    furk:{
      name:"Furk",
      url:"https://www.furk.net/users/files/add"
    }
  }
  var text = "";
  for(var key in d){
    text += html.replace("%url%",d[key].url).replace("%name%",d[key].name);
  }
  return text;
};
var create_wrapper = function (data) {
  var html = '';
  if (data) {
    html = [
        '<tr>',
        '<th class=\'mgnet-th\'><a id=\'switch_engine\' href=\'javascript:void(0);\'>标题</a></th>',
        '<th class=\'magnet-th\'>大小</th>',
        '<th class=\'magnet-th\'>操作</th>',
        '<th class=\'magnet-th\'>离线下载</th>',
        '</tr>'
        ].join("");
    var str = [
        '<td class=\'magnet-td\'><a class=\'magnet-copy\' href=\'javascript:void(0);\'>复制</a></td>',
        '<td class=\'magnet-td\'>',
        offline_url('<a class=\'magnet-download\' target=\'_blank\' href=\'%url%\'>%name%</a>'),
        '</td>',
        ].join("");
    for (var i = 0; i < data.length; i++) {
      html += '<tr hash=\'' + data[i].hash + '\'><td class=\'magnet-td\' title=\''+ data[i].title +'\'>' + shorten_str(data[i].title) + '</td>';
      html += '<td class=\'magnet-td\'>' + data[i].size + '</td>';
      html += str;
      html += '</tr>';
    }
  } 
  else {
    html = '<tr><th class=\'magnet-th\'>没有搜索结果</th></tr>';
  }
  var table = document.createElement('table');
  table.innerHTML = html;
  var wrapper = document.createElement('div');
  wrapper.id = 'magnet-tab';
  wrapper.appendChild(table);
  return wrapper;
};
var gethash = function (vid, callback) {
  var search_url = 'http://www.btspread.com/search/';
  xhr(search_url + vid, function (html) {
    var doc = document.implementation.createHTMLDocument('');
    doc.documentElement.innerHTML = html;
    var data = [];
    if (search_url == 'http://www.btspread.com/search/') { //搜索引擎切换?
      var t = doc.getElementsByTagName('tbody') [0];
      if (t) {
        var elems = t.getElementsByClassName('files-size');
        for (var i = 0; i < elems.length; i++) {
          data.push({
            'title': elems[i].previousElementSibling.firstChild.title,
            'hash': elems[i].previousElementSibling.firstChild.href.replace(/.*hash\//, ''),
            'size': elems[i].textContent
          });
        }
        callback(create_wrapper(data));
      } 
      else {
        callback(create_wrapper(false));
      }
    }
  });
};

var handle_event = function (event) {
  if (event.target.className == 'magnet-copy') {
    event.target.innerHTML = '成功';
    GM_setClipboard('magnet:?xt=urn:btih:' + event.target.parentElement.parentElement.getAttribute('hash'));
    setTimeout(function () {
      event.target.innerHTML = '复制';
    }, 1000);
  } 
  else if (event.target.className == 'magnet-download') {
    GM_setValue('magnet', 'magnet:?xt=urn:btih:' + event.target.parentElement.parentElement.getAttribute('hash'));
  }
};
var reg_event = function () {
  var elem_copy = $('.magnet-copy');
  var elem_down = $('.magnet-download');
  for (var i = 0; i < elem_copy.length; i++) {
    elem_copy[i].addEventListener('click', handle_event, false);
  }
  for (var j = 0; j < elem_down.length; j++) {
    elem_down[j].addEventListener('click', handle_event, false);
  }
  $('#switch_engine').addEventListener('click', function () {
  }, false);
};
var main = {
  avsow: {
    regexp: /avsow.*movie.*/,
    vid: function () {
      return $('.header') [0].nextElementSibling.innerHTML;
    },
    proc: function (wrapper) {
      add_style();
      var title = document.createElement('h4');
      title.innerHTML = '磁链接';
      var tmp = $('#movie-share');
      $ib(tmp, wrapper, tmp.nextElementSibling);
      $ib(tmp, title, tmp.nextElementSibling);
      reg_event();
    }
  },
  avmask: {
    regexp: /avmask.*movie/,
    vid: function () {
      return $('.header') [0].nextElementSibling.innerHTML;
    },
    proc: function (wrapper) {
      add_style();
      var title = document.createElement('h4');
      title.innerHTML = '磁链接';
      var tmp = $('#movie-share');
      $ib(tmp, wrapper, tmp.nextElementSibling);
      $ib(tmp, title, tmp.nextElementSibling);
      reg_event();
    }
  },
  javlibrary: {
    regexp: /javlibrary.*\?v=.*/,
    vid: function () {
      return $('#video_id').getElementsByClassName('text') [0].innerHTML;
    },
    proc: function (wrapper) {
      add_style();
      var tmp = $('#video_favorite_edit');
      $ib(tmp, wrapper, tmp.nextElementSibling);
      reg_event();
    }
  },
  libredmm: {
    regexp: /libredmm/,
    vid: function () {
      return location.pathname.substr(10);
    },
    proc: function (wrapper) {
      add_style();
      var tmp = $('.container') [0];
      $ib(tmp, wrapper, tmp.nextElementSibling);
      reg_event();
    }
  },
  dmm: {
    regexp: /dmm\.co\.jp/,
    vid: function () {
      var result = location.href.replace(/.*cid=/, '').replace(/\/\??.*/, '').match(/[^h_0-9].*/);
      if (result[0]) {
        return result[0].replace('00', '');
      } 
      else {
        return '';
      }
    },
    proc: function (wrapper) {
      add_style();
      var tmp = $('.lh4') [0];
      $ib(tmp, wrapper, tmp.previousElementSibling);
      reg_event();
    }
  },
  minnano: {
    regexp: /minnano-av/,
    vid: function () {
      var elems = $('.t11');
      var r = '';
      for (var i = 0; i < elems.length; i++) {
        if (elems[i].textContent == '品番') {
          r = elems[i].nextElementSibling.textContent;
          break;
        }
      }
      return r;
    },
    proc: function (wrapper) {
      add_style();
      var tmp = (function () {
        var a = $('table');
        for (var i = 0; i < a.length; i++) {
          if (a[i].bgColor == '#EEEEEE') {
            return a[i];
          }
        }
      }) ();
      $ib(tmp, wrapper, tmp.nextElementSibling);
      reg_event();
    }
  },
  oisinbosoft: {
    regexp: /oisinbosoft/,
    vid: function () {
      var r = location.pathname.replace(/.*\/+/, '').replace('.html', '');
      if (r.indexOf('-') == r.lastIndexOf('-')) {
        return r;
      } 
      else {
        return r.replace(/\w*-?/, '');
      }
    },
    proc: function (wrapper) {
      add_style();
      add_style('#magnet-tab table{clear:both;}');
      var tmp = $('#detail_info');
      $ib(tmp, wrapper, tmp.nextElementSibling);
      reg_event();
    }
  },
  javbus: {
    regexp: /javbus/,
    vid: function () {
      var result = $('.movie-code');
      if (result) {
        return result[0].textContent;
      } 
      else {
        return '';
      }
    },
    proc: function (wrapper) {
      add_style();
      var tmp = $('.movie') [0].parentElement;
      $ib(tmp, wrapper, tmp.nextElementSibling);
      reg_event();
    }
  },
  avdb: {
    regexp: /avdb\.la/,
    vid: function () {
      return $('.info') [0].firstElementChild.innerHTML.replace(/<.*>/, '');
    },
    proc: function (wrapper) {
      add_style();
      wrapper.className = 'movie';
      var tmp = $('#downs');
      var title = document.createElement('h4');
      title.innerHTML = '磁链接';
      $ib(tmp, title, tmp);
      $ib(tmp, wrapper, tmp)
      reg_event()
    }
  },
  baidu: {
    regexp: /pan\.baidu\.com/,
    proc: 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);
    }
  },
  115: {
    regexp: /115\.com/,
    proc: function (link) {
      var readyStareChange = setInterval(function () {
        if (document.readyState == 'complete') {
          clearInterval(readyStareChange);
          setTimeout(function () {
            Core['OFFL5Plug'].OpenLink();
            setTimeout(function () {
              $('#js_offline_new_add').val(link);
            }, 0);
          }, 1000);
        }
      }, 200);
    }
  },
  letv: {
    regexp: /cloud\.letv\.com/,
    proc: function (link) {
      setTimeout(function () {
        $('#offline-btn').click();
        setTimeout(function () {
          $('#offline_clear_complete').prev().click();
          setTimeout(function () {
            $('#offline-add-link').val(link);
          }, 500);
        }, 1000);
      }, 2000);
    }
  },
  furk: {
    regexp: /www\.furk\.net/,
    proc: function (link) {
      setTimeout(function () {
        $('#url').val(link.replace('magnet:?xt=urn:btih:', ''));
      }, 1500);
    }
  },
  360:{
    regexp: /yunpan\.360\.cn\/my/,
    proc: function(link){
        yunpan.cmdCenter.showOfflineDia();
        setTimeout(function(){
            $(".offdl-btn-create").click();
            setTimeout(function(){
                $("#offdlUrl").val(link)
            },500)
        },1000);
    }
  }
};
for (var key in main) {
  if (location.href.match(main[key].regexp)) {
    if (main[key].vid) {
      gethash(main[key].vid(), main[key].proc);
    } 
    else {
      exist_magnet(function (link) {
        insert_js(link, main[key].proc);
      });
    }
    break;
  }
}
/*
  GM_xmlhttpRequest({
    method: 'POST',
    url: "http://btkitty.org",
    data:"keyword="+vid,
    headers: {
    "Content-Type": "application/x-www-form-urlencoded"
    },
    onload: function (result) {
      console.log("番号搜索",url);
      cb(result.responseText);
    },
    onerror: function (e) {
      console.log(e);
    }
  });*/