Greasy Fork is available in English.
URLからアフィリエイトIDを除去する(Amazon, 楽天, Yahoo)
< アフィリエイト除去についてのフィードバック
// ==UserScript==// @name:ja アフィリエイト除去// @name Affiliate ID remover// @namespace https://greasyfork.org/morca// @version 0.3// @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) { var newUrl = base + (params2 ? "?" + params2 : ""); if (newUrl !== window.location.href) { history.replaceState(null, '', newUrl); } } }})();//ブラウザリロードのループが起きたので修正しました
コメントありがとうございます。 検証のため、どんなページで現象が発生するか教えていただけるでしょうか?
amazonの商品ページでURLが元々の表示>短縮>リロード>元々のURL>短縮>リロードとループしてました(どの商品ページでも一応上記スクリプトは修正してあるのでそのまま反映していただければ使えると思います
返信を投稿するにはログインしてください。
// ==UserScript==
// @name:ja アフィリエイト除去
// @name Affiliate ID remover
// @namespace https://greasyfork.org/morca
// @version 0.3
// @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) {
var newUrl = base + (params2 ? "?" + params2 : "");
if (newUrl !== window.location.href) {
history.replaceState(null, '', newUrl);
}
}
}
})();
//ブラウザリロードのループが起きたので修正しました