Greasy Fork 支持简体中文。

[RED/OPS] FL link in notifications/better.php

yes

  1. // ==UserScript==
  2. // @name [RED/OPS] FL link in notifications/better.php
  3. // @namespace https://greasyfork.org/users/321857-anakunda
  4. // @version 1.05
  5. // @description yes
  6. // @author Anakunda
  7. // @match https://redacted.sh/torrents.php?action=notify*
  8. // @match https://redacted.sh/torrents.php?page=*&action=notify*
  9. // @match https://redacted.sh/better.php?method=*
  10. // @match https://redacted.sh/better.php?page=*&method=*
  11. // @match https://orpheus.network/torrents.php?action=notify*
  12. // @match https://orpheus.network/torrents.php?page=*&action=notify*
  13. // @match https://orpheus.network/better.php?method=*
  14. // @match https://orpheus.network/better.php?page=*&method=*
  15. // ==/UserScript==
  16.  
  17. 'use strict';
  18.  
  19. function createFlButton(container) {
  20. if (!(container instanceof HTMLElement)) throw 'Invalid argument';
  21. let buttonFl = Array.prototype.find.call(container.getElementsByTagName('A'), a => a.textContent.trim() == 'DL');
  22. if (buttonFl) buttonFl = buttonFl.cloneNode(true); else return null;
  23. buttonFl.className = 'tooltip button_fl';
  24. buttonFl.textContent = 'FL';
  25. buttonFl.title = 'Use a FL Token';
  26. buttonFl.style.fontWeight = 'bold';
  27. const searchParams = new URLSearchParams(buttonFl.search);
  28. searchParams.set('usetoken', 1);
  29. buttonFl.search = searchParams;
  30. buttonFl.onclick = evt => confirm('Are you sure you want to use a freeleech token here?');
  31. return buttonFl;
  32. }
  33.  
  34. if (document.getElementById('fl_tokens') == null) return;
  35. switch (document.location.pathname) {
  36. case '/torrents.php':
  37. for (let span of document.body.querySelectorAll('table.torrent_table > tbody > tr span.torrent_action_buttons')) {
  38. if (span.querySelector('a.button_fl') != null) continue;
  39. let size = span.parentNode.parentNode.parentNode.querySelector(':scope > td:nth-of-type(6)');
  40. if (size != null && (size = /^(\d+(?:\.\d+)?)\s*(\w?B)\b/.exec(size.textContent.trim())) != null) {
  41. size = Math.round(parseFloat(size[1]) * 2 ** (['B', 'KB', 'MB', 'GB', 'TB', 'PB'].indexOf(size[2].toUpperCase()) * 10));
  42. if (size > 2 * 2**30) continue; // tokens apply only on torrents up to 2GB
  43. }
  44. const buttonFl = createFlButton(span);
  45. if (buttonFl != null) span.prepend(buttonFl, ' | ');
  46. }
  47. break;
  48. case '/better.php':
  49. for (let span of document.body.querySelectorAll('table.torrent_table > tbody > tr span.torrent_links_block')) {
  50. if (span.querySelector('a.button_fl') != null) continue;
  51. const buttonFl = createFlButton(span);
  52. if (buttonFl == null) continue;
  53. buttonFl.classList.add('brackets');
  54. span.prepend(buttonFl, ' ');
  55. }
  56. break;
  57. }