Affiliate ID remover

Removes affiliate IDs from URL (Amazon, Rakuten, Yahoo)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name:ja      アフィリエイト除去
// @name         Affiliate ID remover
// @namespace    https://greasyfork.org/morca
// @version      0.2
// @description:ja URLからアフィリエイトIDを除去する(Amazon, 楽天, Yahoo)
// @description  Removes affiliate IDs from URL (Amazon, Rakuten, Yahoo)
// @author       morca
// @match        https://www.amazon.co.jp/*
// @match        https://*.rakuten.co.jp/*
// @match        https://*shopping.yahoo.co.jp/*
// @match        https://*paypaymall.yahoo.co.jp/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const sites = {
        "amazon": [/^tag=.+$/],
        "rakuten": [/^scid=.+$/, /^sc2id=.+$/],
        "yahoo": [/^sc_e=.+$/]
    };
    var href = (window.location != window.parent.location) ? document.referrer : document.location.href;
    const amazon = /^https:\/\/www\.amazon\.co\.jp\/[^?]+\?.*$/.test(href) === true;
    const rakuten = /^https:\/\/\w+\.rakuten\.co\.jp\/[^?]+\?.*$/.test(href) === true;
    const yahoo = /^https:\/\/.*shopping\.yahoo\.co\.jp\/[^?]+\?.*$/.test(href) === true || /^https:\/\/.*paypaymall\.yahoo\.co\.jp\/[^?]+\?.*$/.test(href);
    const site = sites[amazon ? "amazon" : rakuten ? "rakuten" : yahoo ? "yahoo" : null];
    if (site) {
        var base = href.replace(/^([^?]+)\?(.*)$/, "$1");
        var params = href.replace(/^([^?]+)\?(.*)$/, "$2");
        var params2 = params.split("&").filter(function(param) {
            for (var i = 0; i < site.length; i++) {
                if (site[i].test(param) === true) return false;
            }
            return true;
        }).join("&");
        if (params2 != params) {
            if (params2) base += "?"
            window.top.location.replace(base + params2);
        }
    }
})();