Greasy Fork

Greasy Fork is available in English.

アフィリエイト除去

URLからアフィリエイトIDを除去する(Amazon, 楽天, Yahoo!ショッピング)

目前为 2020-03-10 提交的版本,查看 最新版本

// ==UserScript==
// @name         アフィリエイト除去
// @namespace    http://greasyfork.icu/morca
// @version      0.1
// @description  URLからアフィリエイトIDを除去する(Amazon, 楽天, Yahoo!ショッピング)
// @author       morca
// @match        https://www.amazon.co.jp/*
// @match        https://*.rakuten.co.jp/*
// @match        https://*shopping.yahoo.co.jp/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const sites = {
        "amazon": [/^tag=.+$/],
        "rakuten": [/^scid=.+$/, /^sc2id=.+$/],
        "yahoo": [/^sc_e=.+$/]
    };
    var href = 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;
    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 += "?"
            location.replace(base + params2);
        }
    }
})();