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

Version au 22/04/2015. Voir la dernière version.

Vous devrez installer une extension telle que Tampermonkey, Greasemonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Userscripts pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension de gestionnaire de script utilisateur pour installer ce script.

(J'ai déjà un gestionnaire de scripts utilisateur, laissez-moi l'installer !)

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

(J'ai déjà un gestionnaire de style utilisateur, laissez-moi l'installer!)

// ==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
// @version     1.06
// @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:#0003FF;}');
  }
};
var shorten_str = function(str){
    return str.length>35 ? str.slice(0,35)+"..." : str;
};
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>';
    var str = '<td class=\'magnet-td\'><a class=\'magnet-copy\' href=\'javascript:void(0);\'>复制</a></td><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> | <a class=\'magnet-download\' target=\'_blank\' href=\'https://www.furk.net/users/files/add\'>Furk</a></td>';
    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;
    if (search_url == 'http://www.btspread.com/search/') { //搜索引擎切换?
      var t = doc.getElementsByTagName('tbody') [0];
      if (!t) {
        callback(false);
      } 
      else {
        var data = [
        ];
        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(data);
      }
    }
  });
};

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 (data) {
      add_style();
      var wrapper = create_wrapper(data);
      var title = document.createElement('h4');
      title.innerHTML = '磁链接';
      var tmp = $('#movie-share');
      $ib(tmp, wrapper, tmp.nextElementSibling);
      $ib(tmp, title, tmp.nextElementSibling);
    }
  },
  'avmask': {
    regexp: /avmask.*movie/,
    vid: function () {
      return $('.header') [0].nextElementSibling.innerHTML;
    },
    proc: function (data) {
      add_style();
      var wrapper = create_wrapper(data);
      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 (data) {
      add_style();
      var wrapper = create_wrapper(data);
      var tmp = $('#video_favorite_edit');
      $ib(tmp, wrapper, tmp.nextElementSibling);
      reg_event();
    }
  },
  'libredmm': {
    regexp: /libredmm/,
    vid: function () {
      return location.pathname.substr(10);
    },
    proc: function (data) {
      add_style();
      var wrapper = create_wrapper(data);
      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 (data) {
      add_style();
      var wrapper = create_wrapper(data);
      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 (data) {
      add_style();
      var wrapper = create_wrapper(data);
      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 (data) {
      add_style();
      add_style('#magnet-tab table{clear:both;}');
      var wrapper = create_wrapper(data);
      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 (data) {
      add_style();
      var wrapper = create_wrapper(data);
      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 (data) {
      add_style();
      var wrapper = create_wrapper(data);
      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);
    }
  },
};
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;
  }
}