以下是一个油猴脚本示例,可以加载gitee的js文件,并搜索特定值对应的值:

// ==UserScript==
// @name         Gitee JS Loader and Value Searcher
// @namespace    my-gitee-script
// @version      1
// @description  Load JS file from Gitee and search for specific value pair in the loaded object/array
// @match        https://gitee.com/*
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // Define the URL of the JS file to load
    const jsUrl = 'https://gitee.com/username/repo/raw/branch/path/to/js/file.js';

    // Define the key-value pair to search for in the loaded object/array
    const searchKey = 'name';
    const searchValue = 'John';

    // Load the JS file from Gitee
    GM_xmlhttpRequest({
        method: 'GET',
        url: jsUrl,
        onload: function(response) {
            // Parse the loaded JS file as JSON
            const loadedData = JSON.parse(response.responseText);

            // Search for the specific key-value pair in the loaded object/array
            let result;
            if (Array.isArray(loadedData)) {
                result = loadedData.find(item => item[searchKey] === searchValue);
            } else {
                result = loadedData[searchKey] === searchValue ? loadedData : null;
            }

            // Output the search result to the console
            console.log('Search Result:', result);
        }
    });
})();

在使用前,请将jsUrl替换为您要加载的Gitee JS文件的实际URL,并将searchKey和searchValue替换为您要搜索的特定键值对。

请注意,此脚本仅在Gitee网站上运行,并使用GM_xmlhttpRequest和GM_addStyle函数,这些函数是由Greasemonkey提供的,因此您需要安装Greasemonkey才能运行此脚本

油猴加载gitee的js文件并搜索特定值对应的值 示例

原文地址: https://www.cveoy.top/t/topic/heuE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录