去除网页内磁力链的tracker链接的油猴脚本。
效果还不错:
// ==UserScript==
// @name Magnet Link Tracker Remover and File Name Extractor
// @namespace https://greasyfork.org/users/123456
// @version 1.1
// @description Remove trackers from magnet links and extract file names from h3 tags with class panel-title on web pages
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Get all the links on the page
var links = document.getElementsByTagName("a");
// Loop through the links
for (var i = 0; i < links.length; i++) {
// Get the href attribute of the link
var href = links[i].href;
// Check if the link is a magnet link
if (href.startsWith("magnet:?")) {
// Split the link by "&" to get the parameters
var params = href.split("&");
// Loop through the parameters
for (var j = 0; j < params.length; j++) {
// Check if the parameter is a tracker
if (params[j].startsWith("tr=")) {
// Remove the parameter from the array
params.splice(j, 1);
// Decrement j to avoid skipping the next parameter
j--;
}
// Join the parameters back with "&"
var newHref = params.join("&");
// Replace the link's href attribute with the new one
links[i].href = newHref;
// Get the parent element of the link
var parent = links[i].parentElement;
// Check if the parent element is a h3 tag with class panel-title
if (parent.tagName == "H3" && parent.className == "panel-title") {
// Get the text content of the h3 tag
var text = parent.textContent;
// Trim any whitespace from the text
text = text.trim();
// Replace the link's text content with the text from the h3 tag
links[i].textContent = text;
}
}
}
}
})();