Jump to Another Music Service

Jump to Another Music Service.

目前為 2022-04-05 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Jump to Another Music Service
// @description  Jump to Another Music Service.
// @author       to
// @namespace    https://github.com/to
// @license      MIT
// @version      0.2
// @match        https://music.amazon.co.jp/*
// @match        https://music.apple.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=odesli.co
// @grant        GM_xmlhttpRequest
// @grant        GM_registerMenuCommand
// @connect      song.link
// ==/UserScript==

const MARKET = 'JP';
const PLATFORM = 'spotify';
const AUTO = /(amazon)/;

if(AUTO.test(location.href)){
    jump()
}else{
    GM_registerMenuCommand (`Jump to ${PLATFORM}`, () => {
        jump()
    });
}

function jump(){
    GM_xmlhttpRequest({
        url: `https://api.song.link/v1-alpha.1/links?userCountry=${MARKET}&url=${encodeURIComponent(location.href)}`,
        onload: function(r){
            r = JSON.parse(r.responseText);
            try{
                location.href = r.linksByPlatform[PLATFORM].url;
            }catch{
                alert(';;');
            }
        }});
}