// ==UserScript== // @name greasyfork脚本页面适用于网址增强 // @namespace http://tampermonkey.net/ // @version 0.3 // @description 脚本详情页适用于网址不默认跳转搜索 转为可点击的文本链接并提示 // @author 人民的勤务员 // @match https://*.greasyfork.org/zh-CN/scripts/* // @license MIT // @grant GM_registerMenuCommand // @downloadURL none // ==/UserScript== //脚本由ChatGpt生成,本人未做变动 (function() { 'use strict'; // Define an integer variable to control link behavior let 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'); } else if (linkBehavior === 2) { // Open modified URL const newUrl = `https://${location.host}/zh-CN/scripts/by-site/${linkText}`; window.open(newUrl, '_blank'); } } // Add menu command to allow user to change link behavior GM_registerMenuCommand('设置链接行为', () => { const behaviorOptions = ['0. 弹出确认对话框', '1. 打开文本地址', '2. 打开 https://${location.host}/zh-CN/scripts/by-site/ 搜索']; const selectedBehavior = prompt('请选择链接行为:\n' + behaviorOptions.join('\n'), linkBehavior); if (selectedBehavior !== null && !isNaN(selectedBehavior) && selectedBehavior >= 0 && selectedBehavior <= 2) { linkBehavior = parseInt(selectedBehavior); alert(`链接行为已设置为 ${linkBehavior}`); } else { alert('无效的选择,请选择 0, 1 或 2.'); } }); })();