URL-Modifier-for-Search-Engine-Results
Introduction
This Tampermonkey script enhances your search engine usage by modifying URLs in the search result of search engines, redirecting to alternative sites. Allows a more customized and efficient browsing experience.
URL modification uses Regular Expression.
Search result without URL modification:
Search result after URL modification:
Search Engine Support
You can manually add DOM selector in the code to support other search engines.
Can't support Bing, because it only provide intermediate links.
4get won't change displayed URLs correspondingly when links are changed. This issue exists because I aim to make my code as generalized as possible, but these search engines have unusual DOM structure for displaying URLs, which makes it tedious to support these engines considering their relatively small user base.
Just a side note, Kagi is a search engine with built-in URL redirection functionality, worth trying out. I am a user of Kagi, and I am very satisfied with this product, so I'm giving them a shout-out here.
Find more search engines:
Built-in Redirection
You can add custom redirection rules into the script yourself.
Other alternatives privacy friendly frontends, see:
Service providers:
For easy usage, we could use Farside that automatically redirect to working instances of privacy-oriented alternative frontends instead of writing regular expression rules on our own. However, this method does not support finer-grained control over matched URLs.
FYI, wiki for setting up farside in Redirector: https://github.com/einaregilsson/Redirector
const urlModificationRules = [
{
matchRegex: new RegExp(/^(?:https?:\/\/)(?:[\w-]+\.|)((?:imdb|imgur|instagram|medium|odysee|quora|reddit|tiktok|twitter|wikipedia|youtube)\.(?:[a-z]+).*)/),
replaceWith: 'https://farside.link/$1'
},
// ...
];
TODO
- Add supports for more search engines.
- Refactor the code to make it easier to read and modify.
Wiki
urlModificationRules
URL modification rules in regular expression
Variable |
Description |
matchRegex |
regular expression for matching original URLs |
replaceWith |
regular expression for replacement |
selectorRules
Selector rules for the DOM elements needs updating for search engine results
Variable |
Description |
selector |
selector for DOM element |
updateTextWithoutOverwrite |
flag for update the textnode without overwriting other nodes under the DOM element |
updateTextByOverwrite |
flag for update the content by overwriting everything under the DOM element |
updateChildText |
flag for whether to update the inner text of the child element |
childSelector |
selector for child DOM element under parent element |
containProtocol |
flag for whether to contain protocol (e.g. https://) in the domain |
useTopLevelDomain |
flag for whether to use the top-level domain when displaying URLs |
urlDisplayMethod |
required, URL display method method 1: breadcrumb format method 2: full URL method 3: full URL without protocol |
multiElementsForUrlDisplay |
flag for whether the displayed URL is separated into multiple DOM elements |
searchEngines
User-defined list of search engine domains
Variable |
Description |
hosts |
search engine's domain |
resultContainerSelectors |
optional, set search result container DOM, to narrow down the range of dynamic observation |
attribute |
specify additional URL link attribute in <a> other than 'href' (e.g. 'data-target') no need to specify this if all the link attributes are 'href' |