greasyfork脚本页面适用于网址增强

脚本详情页适用于网址不默认跳转搜索 转为可点击的文本链接并提示

目前為 2024-06-08 提交的版本,檢視 最新版本

// ==UserScript==

// @name         greasyfork脚本页面适用于网址增强

// @namespace     https://gf.qytechs.cn/zh-CN/users/1169082-%E4%BA%BA%E6%B0%91%E7%9A%84%E5%8B%A4%E5%8A%A1%E5%91%98

// @version      0.7

// @description  脚本详情页适用于网址不默认跳转搜索 转为可点击的文本链接并提示

// @author       人民的勤务员

// @match        https://*.gf.qytechs.cn/zh-CN/scripts/*

// @match        https://*.sleazyfork.org/zh-CN/scripts/*
// @icon               https://www.google.com/s2/favicons?domain=https://gf.qytechs.cn
// @license      MIT

// @grant        GM_getValue

// @grant        GM_setValue



// ==/UserScript==

//脚本由ChatGpt生成,本人未做变动

(function() {

    'use strict';
function Toast(msg, duration) {

      duration = isNaN(duration) ? 3000 : duration;

      var m = document.createElement('div');

      m.innerHTML = msg;

      m.style.cssText = "max-width:60%;min-width: 150px;padding:0 14px;height: 40px;color: rgb(255, 255, 255);line-height: 40px;text-align: center;border-radius: 12px;position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);z-index: 2147483647;background: rgba(0, 0, 0,.7);font-size: 16px;";

      document.body.appendChild(m);

      setTimeout(function () {

        var d = 0.5;

        m.style.transition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';

        m.style.opacity = '0'; setTimeout(function () { document.body.removeChild(m) }, d * 1000);

      }, duration);

    }
    // Define an integer variable to control link behavior

    let linkBehavior = GM_getValue('linkBehavior', 0); // 0: prompt, 1: open text URL, 2: open modified URL

    // Get all dd elements with class 'script-show-applies-to'

    const ddElements = document.querySelectorAll('dd.script-show-applies-to ul.block-list.expandable > li');

    // Iterate over all dd elements

    ddElements.forEach(dd => {

        const link = dd.querySelector('a[title^="查看其他"]');

        const text = dd.textContent.trim();

        // Skip elements containing '*'

        if (text.includes('*')) {

            return;

        }

        // If there is an a tag, handle its click event

        if (link) {

            link.addEventListener('click', function(event) {

                event.preventDefault(); // Prevent default behavior

                handleLinkClick(text);

            });

        } else {

            // If no a tag exists, convert text to link

            const newLink = document.createElement('a');

            newLink.textContent = text;

            newLink.href = '#';

            newLink.addEventListener('click', function(event) {

                event.preventDefault(); // Prevent default behavior

                handleLinkClick(text);

            });

            dd.textContent = ''; // Clear original text content

            dd.appendChild(newLink); // Insert new link element

        }

    });

    // Function to handle link clicks

    function handleLinkClick(linkText) {

        if (linkBehavior === 0) {

            // Show confirmation dialog

            const userConfirmed = confirm(`是否在[ ${location.host}]搜索关于 ${linkText} 的脚本?`);

            if (userConfirmed) {

                // User chose yes, open modified URL

                const newUrl = `https://${location.host}/zh-CN/scripts/by-site/${linkText}`;

                window.open(newUrl, '_blank');

            } else {

                // User chose no, open original text content

                const originalUrl = `https://${linkText}`;

                window.open(originalUrl, '_blank');

            }

        } else if (linkBehavior === 1) {

            // Open text URL

            const originalUrl = `https://${linkText}`;

            //window.open(originalUrl, '_blank');
            window.location.href=originalUrl;
        } else if (linkBehavior === 2) {

            // Open modified URL

            const newUrl = `https://${location.host}/zh-CN/scripts/by-site/${linkText}`;

           // window.open(newUrl, '_blank');
             window.location.href=newUrl;
        }

    }

    // Add "更改配置" text and select list under the specified "适用于" section

    const appliesToSection = document.querySelector('dt.script-show-applies-to');

    if (appliesToSection) {

        const changeConfigText = document.createElement('span');

        changeConfigText.textContent = '[适用于] ';
        changeConfigText.style.fontWeight= 'bold'; // Bold
        const selectList = document.createElement('select');

        const options = [

            { value: 0, text: '弹出提示' },

            { value: 1, text: '打开网址' },

            { value: 2, text: '论坛搜索' }

        ];

        options.forEach(option => {

            const optionElement = document.createElement('option');

            optionElement.textContent = option.text;

            optionElement.value = option.value;

            if (linkBehavior === option.value) {

                optionElement.selected = true;

            }

            selectList.appendChild(optionElement);

        });

        selectList.addEventListener('change', function() {

            linkBehavior = parseInt(selectList.value);

            GM_setValue('linkBehavior', linkBehavior);
                 Toast(`点击"适用于"网址已设置为: ${options.find(option => option.value === linkBehavior).text}`, 1000)
//alert(`点击"适用于"网址已设置为: ${options.find(option => option.value === linkBehavior).text}`);

        });

        appliesToSection.parentElement.appendChild(changeConfigText);

        appliesToSection.parentElement.appendChild(selectList);

    }

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址