NexusPHP PT Helper

Helper script for NexusPHP based PT sites.

目前为 2018-08-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name NexusPHP PT Helper
  3. // @namespace https://greasyfork.org/zh-CN/users/163820-ysc3839
  4. // @version 0.1.2
  5. // @description Helper script for NexusPHP based PT sites.
  6. // @description:zh-cn 基于 NexusPHP 的 PT 站的辅助脚本
  7. // @author ysc3839
  8. // @match *://hdhome.org/*
  9. // @match *://bt.byr.cn/*
  10. // @require https://cdn.jsdelivr.net/npm/jquery@3.3
  11. // @grant GM_setClipboard
  12. // @run-at document-end
  13. // ==/UserScript==
  14.  
  15. (function($) {
  16. 'use strict';
  17.  
  18. function extend(object, method, callback) {
  19. const original = object[method];
  20.  
  21. object[method] = function(...args) {
  22. const value = original ? original.apply(this, args) : undefined;
  23.  
  24. callback.apply(this, [value].concat(args));
  25.  
  26. return value;
  27. };
  28.  
  29. Object.assign(object[method], original);
  30. }
  31. function override(object, method, newMethod) {
  32. const original = object[method];
  33.  
  34. object[method] = function(...args) {
  35. return newMethod.apply(this, [original.bind(this)].concat(args));
  36. };
  37.  
  38. Object.assign(object[method], original);
  39. }
  40.  
  41. $('html > head').append($(`<style>
  42. .my_selected { background-color: #7c98ae; }
  43. td.rowfollow button { font-size: 9pt; }
  44. </style>`));
  45.  
  46. function createTorrentAnchor(title, href, text, nocopy) {
  47. const a = $('<a>');
  48. if (!nocopy) {
  49. a.click(function(event) {
  50. event.preventDefault();
  51. GM_setClipboard(this.href);
  52. if (!$(this).data('copied'))
  53. $(this).data('copied', true).parent().prev().append('(已复制)');
  54. });
  55. }
  56. return a.addClass('altlink_blue').attr('title', title).attr('href', href).text(text);
  57. }
  58.  
  59. if (location.pathname === '/details.php') {
  60. const tr = $('#outer > table > tbody > tr:eq(5)');
  61. if (location.hostname === 'bt.byr.cn') {
  62. const newtr = $('<tr><td class="rowhead nowrap" valign="top" align="right">种子链接</td><td class="rowfollow" valign="top" align="left"><a></a></td></tr>');
  63. const passkey = localStorage.getItem('passkey');
  64. let title = '没有 passkey, 点此打开控制面板获取 passkey';
  65. let href = '/usercp.php';
  66. let text = title;
  67. let nocopy = true;
  68. if (passkey) {
  69. const url = new URL($('#outer > table > tbody > tr:eq(3) a').get(0).href);
  70. url.searchParams.append('passkey', passkey);
  71. text = href = url.href;
  72. title = '';
  73. nocopy = false;
  74. }
  75. newtr.find('a').replaceWith(createTorrentAnchor(title, href, text, nocopy));
  76. tr.before(newtr);
  77. } else {
  78. const b = tr.find('b');
  79. const url = new URL(b.text());
  80. localStorage.setItem('passkey', url.searchParams.get('passkey'));
  81. b.replaceWith(createTorrentAnchor(b.attr('title'), b.text(), b.text(), false));
  82. }
  83. } else if (location.pathname === '/usercp.php') {
  84. const url = new URL(location);
  85. if(!url.searchParams.get('action')) {
  86. let passkey = null;
  87. $('#outer > table > tbody:eq(1) > tr:gt(2)').each(function() {
  88. const names = ['passkey', '密钥'];
  89. const name = $(this).children().eq(0).text();
  90. if (names.includes(name)) {
  91. passkey = $(this).children().eq(1).text();
  92. return false;
  93. }
  94. });
  95. if (passkey)
  96. localStorage.setItem('passkey', passkey);
  97. else
  98. localStorage.removeItem('passkey');
  99. }
  100. }
  101.  
  102. let passkey = null;
  103.  
  104. function getTorrentURL(urltext) {
  105. const url = new URL(urltext);
  106. const id = url.searchParams.get('id');
  107. return `https://hdhome.org/download.php?id=${id}&passkey=${passkey}`;
  108. }
  109.  
  110. override(unsafeWindow, 'getusertorrentlistajax', function(original, userid, type, blockid) {
  111. if (original(userid, type, blockid)) {
  112. const blockdiv = $('#' + blockid);
  113.  
  114. /*blockdiv.prepend($('<button class="btn">打开选中</button>').click(function() {
  115. }));*/
  116. blockdiv.prepend($('<button class="btn">复制选中链接</button>').click(function() {
  117. passkey = localStorage.getItem('passkey');
  118. if (!passkey) {
  119. alert('No passkey!');
  120. return;
  121. }
  122. let text = '';
  123. $(this).parent().find('tr.my_selected > td:nth-child(4) > a').each(function() {
  124. text += getTorrentURL(this.href) + '\n';
  125. });
  126. GM_setClipboard(text);
  127. }));
  128.  
  129. const trlist = blockdiv.find('table > tbody > tr');
  130. trlist.first().prepend('<td class="colhead" align="center">选中</td><td class="colhead" align="center">链接</td>');
  131.  
  132. const seltd = $('<td class="rowfollow nowrap" style="padding: 0px;" align="center"></td>');
  133. const copytd = seltd.clone();
  134. seltd.append($('<input type="checkbox" style="zoom: 1.5;">').click(function(event) {
  135. $(this).parents().eq(1).toggleClass('my_selected');
  136. }).mousedown(function(e) { e.stopPropagation(); }));
  137. copytd.append($('<button class="btn">复制</button>').click(function() {
  138. passkey = localStorage.getItem('passkey');
  139. if (!passkey) {
  140. alert('No passkey!');
  141. return;
  142. }
  143. GM_setClipboard(getTorrentURL($(this).parent().nextAll().eq(1).children('a').get(0).href));
  144. if (!$(this).data('copied'))
  145. $(this).data('copied', true).parent().append('<br>(已复制)');
  146. }));
  147.  
  148. let mousedown = false;
  149. seltd.mousedown(function(event) {
  150. event.preventDefault();
  151. mousedown = true;
  152. $(this).children().click();
  153. }).mouseenter(function() {
  154. if (mousedown)
  155. $(this).children().click();
  156. });
  157. $(document).mouseup(function(event) {
  158. event.preventDefault();
  159. mousedown = false;
  160. });
  161.  
  162. trlist.not(':first').prepend(copytd).prepend(seltd);
  163. }
  164. return true;
  165. });
  166. })($.noConflict());