Skip to content

Instantly share code, notes, and snippets.

@nonusx
Last active February 13, 2024 13:14
Show Gist options
  • Save nonusx/829ee5ac57b9e9cfd71cca53f769cbaf to your computer and use it in GitHub Desktop.
Save nonusx/829ee5ac57b9e9cfd71cca53f769cbaf to your computer and use it in GitHub Desktop.
Google certain sites
// ==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