Greasy Fork is available in English.

URL Replacer/Redirector

Redirect specific sites by replacing part of the URL.


安装此脚本?
  1. // ==UserScript==// @name URL Replacer/Redirector// @namespace https://github.com/theborg3of5/Userscripts/// @version 1.1// @description Redirect specific sites by replacing part of the URL.// @author Gavin Borg// @match https://gfork.dahi.icu/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 existif(!GM_getValue("replaceTheseStrings")) {GM_setValue("replacePrefix", "");GM_setValue("replac###ffix", "");GM_setValue("replaceTheseStrings", {"toReplace": "replaceWith"});console.log("Created settings structure");}// Prefix/suffix apply to both sidesvar replacePrefix = GM_getValue("replacePrefix");var replac###ffix = GM_getValue("replac###ffix");var replaceAry = GM_getValue("replaceTheseStrings");// console.log(replacePrefix, replac###ffix, replaceAry);var newURL = window.location.href;for(var key in replaceAry) {var toReplace = replacePrefix + key + replac###ffix;var replaceWith = replacePrefix + replaceAry[key] + replac###ffix;// Use a RegEx to allow case-insensitive matchingtoReplace = new RegExp(escapeRegex(toReplace), "i");newURL = newURL.replace(toReplace, replaceWith);}// console.table({"Original URL":window.location.href, "New URL":newURL});if(window.location.href !== newURL) {window.location.replace(newURL);}})();// From https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript/3561711#3561711function escapeRegex(string) {return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');}