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

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

当前为 2022-11-24 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         [RED/OPS] FL link in notifications/better.php
// @namespace    https://greasyfork.org/users/321857-anakunda
// @version      1.02
// @description  Adds direct [FL] button to all notifications and better pages listings
// @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':
		document.body.querySelectorAll('span.torrent_action_buttons > a.button_dl').forEach(function(a) {
			if (a.parentNode.parentNode.querySelector('strong.tl_free') != null) return;
			let ref = a.parentNode.parentNode.parentNode.parentNode.querySelector(':scope > td:nth-of-type(6)');
			if (ref != null && /^(\d+(?:\.\d+))\s*(\w?B)\b/.test(ref.textContent.trim())) {
				let size = Math.round(RegExp.$1 * (2**10)**['B', 'KB', 'MB', 'GB', 'TB', 'PB'].indexOf(RegExp.$2.toUpperCase()));
				if (size > 2 * 2**20) return; // tokens apply only on torrents up to 2GB
			}
			ref = a.nextElementSibling;
			const button_fl = a.cloneNode(true);
			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?');
			a.parentNode.insertBefore(button_fl, ref);
			a.parentNode.insertBefore(document.createTextNode(' | '), ref);
		});
		break;
	case '/better.php':
		document.body.querySelectorAll('table.torrent_table > tbody > tr span.torrent_links_block').forEach(function(span) {
			if (span.querySelector('a.tl_free') != null) return;
			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 return;
			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;
}