Last active
February 13, 2024 13:14
-
-
Save nonusx/829ee5ac57b9e9cfd71cca53f769cbaf to your computer and use it in GitHub Desktop.
Google certain sites
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Google certain sites | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-02-13 | |
// @description Google certain sites | |
// @author Nonus | |
// @match https://www.google.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const eleSearch = document.querySelector("textarea"); | |
const replaceList = { | |
"/v": " site:v2ex.com", | |
"/z": " site:zhihu.com", | |
"/p": " site:program-think.blogspot.com", | |
}; | |
function replaceText() { | |
Object.keys(replaceList).forEach(key => { | |
const regex = new RegExp(key, 'g'); | |
eleSearch.value = eleSearch.value.replace(regex, replaceList[key]); | |
}); | |
} | |
eleSearch.addEventListener('input', replaceText); | |
eleSearch.addEventListener('focus', replaceText); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment