Greasy Fork

Greasy Fork is available in English.

NexusPHP PT Helper

Helper script for NexusPHP based PT sites.

当前为 2018-08-21 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        NexusPHP PT Helper
// @namespace   http://greasyfork.icu/zh-CN/users/163820-ysc3839
// @version     0.1.1
// @description Helper script for NexusPHP based PT sites.
// @description:zh-cn 基于 NexusPHP 的 PT 站的辅助脚本
// @author      ysc3839
// @match       *://hdhome.org/*
// @require     https://cdn.jsdelivr.net/npm/[email protected]
// @grant       GM_setClipboard
// ==/UserScript==

(function($) {
  'use strict';

  function extend(object, method, callback) {
    const original = object[method];

    object[method] = function(...args) {
      const value = original ? original.apply(this, args) : undefined;

      callback.apply(this, [value].concat(args));

      return value;
    };

    Object.assign(object[method], original);
  }
  
  function override(object, method, newMethod) {
    const original = object[method];

    object[method] = function(...args) {
      return newMethod.apply(this, [original.bind(this)].concat(args));
    };

    Object.assign(object[method], original);
  }

  $('html > head').append($(`<style>
.my_selected { background-color: #7c98ae; }
td.rowfollow button { font-size: 9pt; }
</style>`));

  if (window.location.pathname === '/details.php') {
    const b = $('#outer > table > tbody > tr:eq(5)').find('b');
    const url = new URL(b.text());
    localStorage.setItem('passkey', url.searchParams.get('passkey'));
    b.replaceWith($('<a>').addClass('altlink_blue').attr('title', b.attr('title')).attr('href', b.text()).text(b.text()).click(function(event) {
      event.preventDefault();
      GM_setClipboard(this.href);
      if (!$(this).data('copied'))
        $(this).data('copied', true).parent().prev().append('(已复制)');
    }));
  } else if (window.location.pathname === '/usercp.php') {
    const url = new URL(window.location);
    if(!url.searchParams.get('action')) {
      localStorage.setItem('passkey', $('#outer > table > tbody:eq(1) > tr:eq(3) > td:eq(1)').text());
    }
  }

  let passkey = localStorage.getItem('passkey');

  function getTorrentURL(urltext) {
    const url = new URL(urltext);
    const id = url.searchParams.get('id');
    return `https://hdhome.org/download.php?id=${id}&passkey=${passkey}`;
  }

  override(unsafeWindow, 'getusertorrentlistajax', function(original, userid, type, blockid) {
    if (original(userid, type, blockid)) {
      const blockdiv = $('#' + blockid);

      /*blockdiv.prepend($('<button>打开选中</button>').click(function() {
      }));*/
      blockdiv.prepend($('<button>复制选中链接</button>').click(function() {
        if (!passkey) {
          alert('No passkey!');
          return;
        }
        let text = '';
        $(this).parent().find('tr.my_selected > td:nth-child(4) > a').each(function() {
          text += getTorrentURL(this.href) + '\n';
        });
        GM_setClipboard(text);
      }));

      const trlist = blockdiv.find('table > tbody > tr');
      trlist.first().prepend('<td class="colhead" align="center">选中</td><td class="colhead" align="center">链接</td>');

      const seltd = $('<td class="rowfollow nowrap" style="padding: 0px;" align="center"></td>');
      const copytd = seltd.clone();
      seltd.append($('<input type="checkbox" style="zoom: 1.5;">').click(function(event) {
        $(this).parents().eq(1).toggleClass('my_selected');
      }).mousedown(function(e) { e.stopPropagation(); }));
      copytd.append($('<button>复制</button>').click(function() {
        if (!passkey) {
          alert('No passkey!');
          return;
        }
        GM_setClipboard(getTorrentURL($(this).parent().nextAll().eq(1).children('a').get(0).href));
        if (!$(this).data('copied'))
          $(this).data('copied', true).parent().append('<br>(已复制)');
      }));

      let mousedown = false;
      seltd.mousedown(function(event) {
        event.preventDefault();
        mousedown = true;
        $(this).children().click();
      }).mouseenter(function() {
        if (mousedown)
          $(this).children().click();
      });
      $(document).mouseup(function(event) {
        event.preventDefault();
        mousedown = false;
      });

      trlist.not(':first').prepend(copytd).prepend(seltd);
    }
    return true;
  });
})($.noConflict());