Last.fm: Always Use +noredirect (except images)

Ändrar alla länkar till /music/<band> till /music/+noredirect/<band>, men undviker länkar som innehåller /+images/

当前为 2025-04-30 提交的版本,查看 最新版本

// ==UserScript==
// @name         Last.fm: Always Use +noredirect (except images)
// @namespace    https://last.fm/
// @version      1.2
// @description  Ändrar alla länkar till /music/<band> till /music/+noredirect/<band>, men undviker länkar som innehåller /+images/
// @author       DiCK
// @match        https://*.last.fm/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function fixLinks() {
        const links = document.querySelectorAll('a[href*="/music/"]');

        links.forEach(link => {
            let href = link.getAttribute('href');

            // Hoppa över om redan innehåller /+noredirect/ eller om den innehåller /+images/
            if (href.includes('/+noredirect/') || href.includes('/+images/')) return;

            // Mönster: matchar både interna (/music/BandName) och externa (https://www.last.fm/music/BandName)
            const regex = /^(https?:\/\/(www\.)?last\.fm)?\/music\/([^\/?#]+)/;

            const match = href.match(regex);
            if (match) {
                const bandName = match[3]; // Bandnamnet
                const newHref = href.replace(`/music/${bandName}`, `/music/+noredirect/${bandName}`);
                link.setAttribute('href', newHref);
            }
        });
    }

    // Runs immediately
    fixLinks();

    // Runs despite changes in DOM (Including AJAX)
    const observer = new MutationObserver(fixLinks);
    observer.observe(document.body, { childList: true, subtree: true });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址