Greasy Fork

来自缓存

Greasy Fork is available in English.

检测网站存在脚本

检测脚本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         检测网站存在脚本
// @namespace    http://yeyu2048.xyz
// @version      1.0
// @description  检测脚本
// @author       夜雨
// @match        *://*/*
// @grant       GM_xmlhttpRequest
// @grant       GM_openInTab
// @grant       GM_registerMenuCommand
// @connect     greasyfork.org
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

   



    function getParams(name){
        let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        let r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURIComponent(r[2]);
        return '';
    }

    //封装GM_xmlhttpRequest ---start---
    async function GM_fetch(details) {
        return new Promise((resolve, reject) =>{
            switch (details.responseType){
                case "stream":
                    details.onloadstart = (res)=>{
                        resolve(res)
                    }
                    break;
                default:
                    details.onload = (res)=>{
                        resolve(res)
                    };
            }

            details.onerror = (res)=>{
                reject(res)
            };
            details.ontimeout = (res)=>{
                reject(res)
            };
            details.onabort = (res)=>{
                reject(res)
            };

            GM_xmlhttpRequest(details)

        });
    }

    function GM_httpRequest(details, callBack, errorCallback, timeoutCallback, abortCallback){
        if(callBack){
            switch (details.responseType){
                case "stream":
                    details.onloadstart = callBack;
                    break;
                default:
                    details.onload = callBack
            }
        }
        if(errorCallback){
            details.onerror = errorCallback;
        }
        if(timeoutCallback){
            details.ontimeout = timeoutCallback;
        }
        if(abortCallback){
            details.onabort = abortCallback;
        }
        console.log(details)

        GM_xmlhttpRequest(details)
    }

    //封装GM_xmlhttpRequest ---end---


    GM_fetch({
        method: "GET",
        url: `http://greasyfork.icu/zh-CN/scripts/by-site/${location.host.startsWith("www.")?location.host.slice(4):location.host}?filter_locale=0&sort=updated`,
        headers: {
            "Referer": "http://greasyfork.icu/"
        },
        responseType: "text"
    }).then((res) => {
        if (res.status === 200) {
            console.log(res)
            let rest = res.responseText
            if(!rest.includes("找不到相关脚本")){
                GM_registerMenuCommand("存在脚本", function (event) {
                    console.warn("存在脚本")
                    GM_openInTab(`http://greasyfork.icu/zh-CN/scripts/by-site/${location.host.startsWith("www.")?location.host.slice(4):location.host}?filter_locale=0&sort=updated`)
                }, "searchJS");
            }else {
               console.error("找不到相关脚本")
            }

        } else {
            console.log('访问失败了')
        }
    },function (err) {
        console.log(err)
    }).catch((ex)=>{
        console.log(ex)
    })




})();