To search scripts using Google Search
目前為
// ==UserScript==
// @name GreasyFork Search
// @namespace http://tampermonkey.net/
// @version 0.3.0
// @description To search scripts using Google Search
// @author CY Fung
// @match https://greasyfork.org/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
// @grant none
// @license MIT
// ==/UserScript==
(function () {
'use strict';
let input = document.querySelector('form input[name="q"]');
if (!(input instanceof HTMLInputElement)) return;
let form = input.closest('form');
if (!(form instanceof HTMLFormElement)) return;
form.addEventListener('submit', function (evt) {
let form = evt.target;
if (!(form instanceof HTMLFormElement)) return;
let input = form.querySelector('input[name="q"]');
if (!(input instanceof HTMLInputElement)) return;
let value = input.value;
const lang = document.documentElement.lang || '';
if (value && value.startsWith('g ')) {
let q = value.replace('g ', '');
evt.preventDefault();
let m = "-inurl%3A%22%2Fusers%2F%22+-inurl%3A%22%2Fdiscussions%22-inurl%3A%22%2Fstats%22+-inurl%3A%22%2Ffeedback%22+-inurl%3A%22%2Fcode%22+-inurl%3A%22q%3D%22+-inurl%3A%22%2Fby-site%2F%22+inurl%3A%22%2Fscripts%2F%22+site%3Agreasyfork.org";
let lr = lang ? `&lr=lang_${lang}` : '';
location.href = `https://www.google.com/search?q=${encodeURIComponent(q)}+${m}${lr}`
} else if (value) {
let urlObject = null;
try {
urlObject = new URL(value)
} catch (e) { }
if (urlObject && urlObject.hostname === value) {
let gl = lang ? `/${lang}` : '';
location.href = `https://greasyfork.org${gl}/scripts/by-site/` + value;
}
}
})
// Your code here...
})();