Fix Discogs Links

Redirect external links to the original version if lang is not "en" and modify artist links based on the lang attribute

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu betiği yüklemek için bir betik yöneticisi eklentisi yüklemeniz gerekecektir.

(Zaten bir betik yöneticim var, hadi yükleyelim!)

Advertisement:

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

Advertisement:

// ==UserScript==
// @name         Fix Discogs Links
// @version      1.1
// @description  Redirect external links to the original version if lang is not "en" and modify artist links based on the lang attribute
// @author       Kai
// @match        *://www.discogs.com/*
// @grant        none
// @namespace https://greasyfork.org/users/1215012
// ==/UserScript==
(function() {
    'use strict';
    // Check the lang attribute in the <html> tag
    var langAttribute = document.documentElement.getAttribute('lang');
    // Function to modify links
    function modifyLinks() {   
        // 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, '');
            });
                 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 without a languge attribute
            if (originalUrl.includes('com/artist/')) {
                // Replace 'com/artist' with 'com/lang/artist'
                var newUrl = originalUrl.replace('com/artist/', 'com/' + langAttribute + '/artist/');
                // Set the modified link
                link.href = newUrl;
            }
        });

    }}
    // Execute the script when the page is loaded
    window.addEventListener('load', modifyLinks);
})
();