appleMusicLargeThumbRedirect

apple music large thumb link redirect

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         appleMusicLargeThumbRedirect
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  apple music large thumb link redirect
// @author       lamhing
// @match        *.mzstatic.com/image/thumb/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const appleMusicLargeThumbRedirect = () => {
        let targetThumbWidth = 4000;

        const sizeReg = new RegExp(/.jpg\/(\S*)bb/);
        const pathname = location.pathname;
        let arr = pathname.match(sizeReg);
        let sizeStr = arr?.[1];

        if (!sizeStr) {
            console.error('match err');

            return;
        }

        const toTargetLink = () => {
            let newPathname = pathname;
            newPathname = newPathname.replace(
                sizeStr,
                `${targetThumbWidth}x${targetThumbWidth}`
            );

            location.pathname = newPathname;
            // location.href = `${location.origin}${newPathname}`;
        };

        let curWidth = Number(sizeStr.split('x')?.[0]);

        if (!curWidth) {
            console.error('get curWidth error');
            toTargetLink();
            return;
        }

        if (curWidth === targetThumbWidth) {
            // target width
            return;
        }

        toTargetLink();
    };

    appleMusicLargeThumbRedirect();
})();