// ==UserScript== // @name greasyfork脚本页面适用于网址增强 // @namespace https://greasyfork.org/zh-CN/users/1169082-%E4%BA%BA%E6%B0%91%E7%9A%84%E5%8B%A4%E5%8A%A1%E5%91%98 // @version 0.6 // @description 脚本详情页适用于网址不默认跳转搜索 转为可点击的文本链接并提示 // @author 人民的勤务员 // @match https://*.greasyfork.org/zh-CN/scripts/* // @license MIT // @grant GM_getValue // @grant GM_setValue // @downloadURL none // ==/UserScript== //脚本由ChatGpt生成,本人未做变动 (function() { 'use strict'; // 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); alert(`点击"适用于"网址已设置为: ${options.find(option => option.value === linkBehavior).text}`); }); appliesToSection.parentElement.appendChild(changeConfigText); appliesToSection.parentElement.appendChild(selectList); } })();