GreasyFork Sites Show (GFSS)

Show @match and @include URLs in the GreasyFork script list with a toggle icon to expand/collapse the list

当前为 2024-08-27 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GreasyFork Sites Show (GFSS)
// @namespace    https://your-namespace-here
// @version      1.2
// @description  Show @match and @include URLs in the GreasyFork script list with a toggle icon to expand/collapse the list
// @author       Emree.el on instagrammmmmmmmmm
// @match        https://greasyfork.org/*
// @grant        GM_xmlhttpRequest
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Process each script list item
    $('li[data-script-id]').each(function() {
        let scriptElement = $(this);
        let codeUrl = scriptElement.find('a.install-link').attr('href');

        if (codeUrl) {
            // Fetch the script content
            GM_xmlhttpRequest({
                method: "GET",
                url: codeUrl,
                onload: function(response) {
                    if (response.status === 200) {
                        // Extract @match and @include lines
                        let matchUrls = response.responseText.match(/\/\/\s*@match\s+(\S+)/g) || [];
                        let includeUrls = response.responseText.match(/\/\/\s*@include\s+(\S+)/g) || [];
                        let allUrls = matchUrls.concat(includeUrls);

                        if (allUrls.length > 0) {
                            let matchList = $('<ul class="url-list" style="list-style-type: disc; margin-left: 20px;"></ul>');
                            allUrls.forEach(function(line, index) {
                                let url = line.replace(/\/\/\s*@(match|include)\s+/, '').trim();
                                let listItem = $(`<li style="display: ${index >= 3 ? 'none' : 'list-item'};">${url}</li>`);
                                matchList.append(listItem);
                            });

                            let toggleButton = null;
                            if (allUrls.length > 3) {
                                toggleButton = $('<button style="margin-left: 10px; cursor: pointer; background: #AC68FE; border: none; padding: 2px 5px;">+</button>');

                                toggleButton.click(function() {
                                    let isExpanded = $(this).text() === '-';
                                    $(this).text(isExpanded ? '+' : '-');
                                    matchList.children('li').slice(3).toggle(!isExpanded);
                                });
                            }

                            // Append the @match and @include URLs under the script description
                            scriptElement.find('h2').after(matchList);

                            // Add the toggle button next to the script title link
                            if (toggleButton) {
                                scriptElement.find('a.script-link').after(toggleButton);
                            }
                        }
                    }
                }
            });
        }
    });
})();