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

Adds direct [FL] button to all notifications and better pages listings

目前为 2022-11-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name [RED/OPS] FL link in notifications/better.php
  3. // @namespace https://greasyfork.org/users/321857-anakunda
  4. // @version 1.02
  5. // @description Adds direct [FL] button to all notifications and better pages listings
  6. // @author Anakunda
  7. // @match https://redacted.ch/torrents.php?action=notify*
  8. // @match https://redacted.ch/torrents.php?page=*&action=notify*
  9. // @match https://redacted.ch/better.php?method=*
  10. // @match https://redacted.ch/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. if (document.getElementById('fl_tokens') == null) return;
  20. switch (document.location.pathname) {
  21. case '/torrents.php':
  22. document.body.querySelectorAll('span.torrent_action_buttons > a.button_dl').forEach(function(a) {
  23. if (a.parentNode.parentNode.querySelector('strong.tl_free') != null) return;
  24. let ref = a.parentNode.parentNode.parentNode.parentNode.querySelector(':scope > td:nth-of-type(6)');
  25. if (ref != null && /^(\d+(?:\.\d+))\s*(\w?B)\b/.test(ref.textContent.trim())) {
  26. let size = Math.round(RegExp.$1 * (2**10)**['B', 'KB', 'MB', 'GB', 'TB', 'PB'].indexOf(RegExp.$2.toUpperCase()));
  27. if (size > 2 * 2**20) return; // tokens apply only on torrents up to 2GB
  28. }
  29. ref = a.nextElementSibling;
  30. const button_fl = a.cloneNode(true);
  31. const searchParams = new URLSearchParams(button_fl.search);
  32. searchParams.set('usetoken', 1);
  33. button_fl.search += searchParams;
  34. button_fl.className = 'tooltip button_fl';
  35. button_fl.text = 'FL';
  36. button_fl.title = 'Use a FL Token';
  37. button_fl.style.fontWeight = 700;
  38. button_fl.onclick = evt => confirm('Are you sure you want to use a freeleech token here?');
  39. a.parentNode.insertBefore(button_fl, ref);
  40. a.parentNode.insertBefore(document.createTextNode(' | '), ref);
  41. });
  42. break;
  43. case '/better.php':
  44. document.body.querySelectorAll('table.torrent_table > tbody > tr span.torrent_links_block').forEach(function(span) {
  45. if (span.querySelector('a.tl_free') != null) return;
  46. let button_fl = Array.prototype.find.call(span.getElementsByTagName('A'), a => a.textContent.trim() == 'DL');
  47. if (button_fl) button_fl = button_fl.cloneNode(true); else return;
  48. const searchParams = new URLSearchParams(button_fl.search);
  49. searchParams.set('usetoken', 1);
  50. button_fl.search += searchParams;
  51. button_fl.className = 'brackets tooltip button_fl';
  52. button_fl.text = 'FL';
  53. button_fl.title = 'Use a FL Token';
  54. button_fl.style.fontWeight = 700;
  55. button_fl.onclick = evt => confirm('Are you sure you want to use a freeleech token here?');
  56. span.prepend(button_fl, ' ');
  57. });
  58. break;
  59. }