您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
To search scripts using Google Search
当前为
- // ==UserScript==
- // @name GreasyFork Search
- // @namespace http://tampermonkey.net/
- // @version 0.4.4
- // @description To search scripts using Google Search
- // @author CY Fung
- // @match https://gf.qytechs.cn/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=gf.qytechs.cn
- // @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;
- let locales = [...document.querySelectorAll('select#language-selector-locale > option')].map(x => x.value)
- document.head.appendChild(document.createElement('style')).textContent = `
- @keyframes rs1tmAnimation {
- 0% {
- background-position-x: 3px;
- }
- 100% {
- background-position-x: 4px;
- }
- }
- form.rs1tm{
- position: fixed;
- top:-300px;
- left:-300px;
- width: 1px;
- height: 1px;
- contain: strict;
- display: flex;
- overflow: hidden;
- animation: rs1tmAnimation 1ms linear 1ms 1 normal forwards;
- }
- `
- document.addEventListener('animationstart', (evt) => {
- if (evt.animationName === 'rs1tmAnimation') {
- const target = evt.target;
- target && target.parentNode && target.remove();
- }
- }, true);
- 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;
- if (form.classList.contains('rs1tm')) return;
- let value = input.value;
- const lang = document.documentElement.lang || '';
- let useLang = false;
- let u = 0;
- let isGoogleSearch = false;
- let sites = [];
- const split = value.split(/\s+/);
- let forceLang = 'all';
- let reformedSplit = [];
- for (const s of split) {
- if (!isGoogleSearch && /^[a-z][a-z0-9_-]{2,}(\.[a-z][a-z0-9_-]{2,})*(\.[a-z-]{2,4})+$/.test(s)) {
- sites.push(s);
- } else if (s === 'js') {
- forceLang = 'js'; reformedSplit.push(s);
- } else if (s === 'css') {
- forceLang = 'css'; reformedSplit.push(s);
- } else if (s === 'user.js') {
- forceLang = 'js';
- } else if (s === 'user.css') {
- forceLang = 'css';
- } else if (s === '"js"') {
- reformedSplit.push('js');
- } else if (s === '"css"') {
- reformedSplit.push('css');
- } else if (u === 0 && s === 'g') {
- isGoogleSearch = true;
- } else if (locales.indexOf(s) >= 0 || s === lang) {
- useLang = s;
- } else {
- reformedSplit.push(s);
- }
- u++;
- }
- value = reformedSplit.join(' ')
- let onlySite = '';
- if (sites.length === 1 && sites[0]) {
- onlySite = sites[0];
- }
- if (isGoogleSearch && value) {
- let q = value.replace('g ', '');
- 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%3Agf.qytechs.cn";
- let lr = useLang ? `&lr=lang_${useLang}` : '';
- evt.preventDefault();
- evt.stopImmediatePropagation();
- evt.stopPropagation();
- location.href = `https://www.google.com/search?q=${encodeURIComponent(q)}+${m}${lr}`
- } else if (value || onlySite) {
- let newForm = document.createElement('form');
- newForm.className = 'rs1tm';
- const copyAttr = (x) => {
- let t = form.getAttribute(x);
- if (typeof t === 'string') newForm.setAttribute(x, t);
- }
- copyAttr('action');
- copyAttr('accept-charset');
- copyAttr('method');
- newForm.innerHTML = `<input name="q" type="hidden" value="" /><input name="site" type="hidden" /><input name="language" type="hidden" value="all" />`
- const nq = newForm.querySelector('input[name="q"]');
- const language = newForm.querySelector('input[name="language"]');
- const site = newForm.querySelector('input[name="site"]');
- value = value.replace(/\s+/g, ' ');
- site.value = onlySite;
- if (form.getAttribute('action') === `/${lang}/scripts` && useLang && useLang !== lang) {
- form.setAttribute('action', `/${useLang}/scripts`)
- }
- if (site.value === '') site.remove();
- nq.value = value;
- language.value = forceLang;
- if (language.value === '') language.remove();
- evt.preventDefault();
- evt.stopImmediatePropagation();
- evt.stopPropagation();
- form.parentNode.insertBefore(newForm, form);
- newForm.submit();
- } else {
- evt.preventDefault();
- evt.stopImmediatePropagation();
- evt.stopPropagation();
- }
- })
- // Your code here...
- })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址