您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
Redirect external links to the original version if lang is not "en" and modify artist links based on the lang attribute
当前为
// ==UserScript== // @name Fix Discogs Links // @version 1.0 // @description Redirect external links to the original version if lang is not "en" and modify artist links based on the lang attribute // @author You // @match *://www.discogs.com/* // @grant none // @namespace http://greasyfork.icu/users/1215012 // ==/UserScript== (function() { 'use strict'; // Function to modify links function modifyLinks() { // Check the lang attribute in the <html> tag var langAttribute = document.documentElement.getAttribute('lang'); // Check if lang is not "en" if (langAttribute !== 'en') { // Find all links that contain the "/x/" fragment and have the hrefLang="x" attribute var links = document.querySelectorAll('a[href*="/' + langAttribute + '"][hrefLang="' + langAttribute + '"]:not([href*="discogs.com/"])'); // Iterate over all found links links.forEach(function(link) { // Replace the link with the version without "/x/" link.href = link.href.replace('/' + langAttribute, ''); }); } // Read the 'lang' attribute from the HTML document var langAttributeForArtist = document.documentElement.lang; // Select all links on the page var artistLinks = document.querySelectorAll('a'); // Iterate through the links and make modifications artistLinks.forEach(function(link) { var originalUrl = link.href; // Check if it is an artist link if (originalUrl.includes('/artist/')) { // Replace 'artist' with 'lang/artist' var newUrl = originalUrl.replace('/artist/', '/' + langAttributeForArtist + '/artist/'); // Set the modified link link.href = newUrl; // Optional: Log the modified link console.log('Original URL:', originalUrl); console.log('Modified URL:', newUrl); } }); } // Execute the script when the page is loaded window.addEventListener('load', modifyLinks); })();