Greasy Fork

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

yes

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

// ==UserScript==
// @name         [RED/OPS] FL link in notifications/better.php
// @namespace    https://greasyfork.org/users/321857-anakunda
// @version      1.03
// @description  yes
// @author       Anakunda
// @match        https://redacted.ch/torrents.php?action=notify*
// @match        https://redacted.ch/torrents.php?page=*&action=notify*
// @match        https://redacted.ch/better.php?method=*
// @match        https://redacted.ch/better.php?page=*&method=*
// @match        https://orpheus.network/torrents.php?action=notify*
// @match        https://orpheus.network/torrents.php?page=*&action=notify*
// @match        https://orpheus.network/better.php?method=*
// @match        https://orpheus.network/better.php?page=*&method=*
// ==/UserScript==

	'use strict';

if (document.getElementById('fl_tokens') == null) return;
switch (document.location.pathname) {
	case '/torrents.php':
		for (let span of document.body.querySelectorAll('table.torrent_table > tbody > tr span.torrent_action_buttons')) {
			if (span.querySelector('a.tl_free') != null) continue;
			let sizeColumn = span.parentNode.parentNode.parentNode.querySelector(':scope > td:nth-of-type(6)');
			if (sizeColumn != null && (sizeColumn = /^(\d+(?:\.\d+))\s*(\w?B)\b/.exec(sizeColumn.textContent.trim())) != null) {
				const size = Math.round(parseFloat(sizeColumn[1]) * 2 ** (['B', 'KB', 'MB', 'GB', 'TB', 'PB'].indexOf(sizeColumn[2].toUpperCase()) * 10));
				if (size > 2 * 2**30) continue; // tokens apply only on torrents up to 2GB
			}
			let button_fl = Array.prototype.find.call(span.getElementsByTagName('A'), a => a.textContent.trim() == 'DL');
			if (button_fl) button_fl = button_fl.cloneNode(true); else continue;
			const searchParams = new URLSearchParams(button_fl.search);
			searchParams.set('usetoken', 1);
			button_fl.search += searchParams;
			button_fl.className = 'tooltip button_fl';
			button_fl.text = 'FL';
			button_fl.title = 'Use a FL Token';
			button_fl.style.fontWeight = 700;
			button_fl.onclick = evt => confirm('Are you sure you want to use a freeleech token here?');
			span.prepend(button_fl, ' | ');
		}
		break;
	case '/better.php':
		for (let span of document.body.querySelectorAll('table.torrent_table > tbody > tr span.torrent_links_block')) {
			if (span.querySelector('a.tl_free') != null) continue;
			let button_fl = Array.prototype.find.call(span.getElementsByTagName('A'), a => a.textContent.trim() == 'DL');
			if (button_fl) button_fl = button_fl.cloneNode(true); else continue;
			const searchParams = new URLSearchParams(button_fl.search);
			searchParams.set('usetoken', 1);
			button_fl.search += searchParams;
			button_fl.className = 'brackets tooltip button_fl';
			button_fl.text = 'FL';
			button_fl.title = 'Use a FL Token';
			button_fl.style.fontWeight = 700;
			button_fl.onclick = evt => confirm('Are you sure you want to use a freeleech token here?');
			span.prepend(button_fl, ' ');
		}
		break;
}