您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Redirect specific sites by replacing part of the URL.
当前为
- // ==UserScript==
- // @name URL Replacer/Redirector
- // @namespace https://github.com/theborg3of5/Userscripts/
- // @version 1.0
- // @description Redirect specific sites by replacing part of the URL.
- // @author Gavin Borg
- // @match https://greasyfork.org/en/scripts/403100-url-replacer-redirector
- // @grant GM_getValue
- // @grant GM_setValue
- // ==/UserScript==
- (function() {
- 'use strict';
- // Initial creation of settings structure if it doesn't exist
- if(!GM_getValue("replaceTheseStrings")) {
- GM_setValue("replacePrefix", "");
- GM_setValue("replaceSuffix", "");
- GM_setValue("replaceTheseStrings", {"toReplace": "replaceWith"});
- console.log("Created settings structure");
- }
- // Prefix/suffix apply to both sides
- var replacePrefix = GM_getValue("replacePrefix");
- var replaceSuffix = GM_getValue("replaceSuffix");
- var replaceAry = GM_getValue("replaceTheseStrings");
- // console.log(replacePrefix, replaceSuffix, replaceAry);
- var newURL = window.location.href;
- for(var key in replaceAry) {
- var toReplace = replacePrefix + key + replaceSuffix;
- var replaceWith = replacePrefix + replaceAry[key] + replaceSuffix;
- newURL = newURL.replace(toReplace, replaceWith);
- }
- // console.table({"Original URL":window.location.href, "New URL":newURL});
- if(window.location.href !== newURL) {
- window.location.replace(newURL);
- }
- })();