Greasy Fork镜像脚本页面适用于网址增强

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

目前为 2024-07-29 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Greasy Fork镜像脚本页面适用于网址增强
  3. // @namespace https://github.com/10086100886/renmindeqinwuyuan
  4. // @version 0.9.3.8
  5. // @description 脚本详情页适用于网址不默认跳转搜索 转为可点击的文本链接并弹出提示
  6. // @author 人民的勤务员 <toniaiwanowskiskr47@gmail.com>
  7. // @match https://*.gf.qytechs.cn/zh-CN/scripts/*
  8. // @match https://*.sleazyfork.org/zh-CN/scripts/*
  9. // @icon https://www.google.com/s2/favicons?domain=https://gf.qytechs.cn
  10. // @license MIT
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict'
  17. let useWindowOpen = GM_getValue('useWindowOpen', false) // 默认在当前页面跳转
  18. let linkBehavior = GM_getValue('linkBehavior', 0)
  19. let shouldMatchLink = false // 添加一个全局变量,默认为假 不显示适用于脚本的数量
  20.  
  21. function Toast(msg, duration) {
  22. duration = isNaN(duration) ? 3000 : duration
  23. var m = document.createElement('div')
  24. m.innerHTML = msg
  25. m.style.cssText = "max-width:60%;min-width: 150px;padding:0 14px;height: 40px;color: black;line-height: 40px;text-align: center;border-radius: 12px;position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);z-index: 2147483647;background: white;font-size: 16px;"
  26. document.body.appendChild(m)
  27. setTimeout(function () {
  28. var d = 0.5
  29. m.style.transition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in'
  30. m.style.opacity = '0'; setTimeout(function () { document.body.removeChild(m) }, d * 1000)
  31. }, duration)
  32. }
  33.  
  34. function navigateTo(url, useWindowOpen) {
  35. if (useWindowOpen) {
  36. window.open(url, '_blank')
  37. } else {
  38. window.location.href = url
  39. }
  40. }
  41.  
  42. const ddElements = document.querySelectorAll('dd.script-show-applies-to ul.block-list.expandable > li')
  43.  
  44. ddElements.forEach(dd => {
  45. const link = dd.querySelector('a[title^="查看其他"]')
  46. const text = dd.textContent.trim()
  47. if (shouldMatchLink && link) { // 检查 shouldMatchLink 变量的值
  48. const match = link.title.match(/查看其他 (\d+) 个适用/)
  49. if (match) {
  50. const count = match[1]
  51. const note = document.createElement('sup')
  52. note.textContent = count
  53. link.appendChild(note)
  54. link.title = link.title.replace(/ \d+ /, ' ')
  55. link.addEventListener('click', function (event) {
  56. event.preventDefault()
  57. handleLinkClick(text)
  58. })
  59. }
  60. } else {
  61. const newLink = document.createElement('a')
  62. newLink.textContent = text
  63. newLink.href = '#'
  64. newLink.addEventListener('click', function (event) {
  65. event.preventDefault()
  66. handleLinkClick(text)
  67. })
  68. dd.textContent = ''
  69. dd.appendChild(newLink)
  70. }
  71. })
  72.  
  73. function handleLinkClick(linkText) {
  74. if (linkBehavior === 0) {
  75. const bodyBackgroundColor = window.getComputedStyle(document.body).backgroundColor
  76. const dialogBox = document.createElement('div')
  77. dialogBox.style.position = 'fixed'
  78. dialogBox.style.top = '50%'
  79. dialogBox.style.left = '50%'
  80. dialogBox.style.transform = 'translate(-50%, -50%)'
  81. dialogBox.style.background = bodyBackgroundColor
  82. dialogBox.style.padding = '20px'
  83. dialogBox.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.1)'
  84. dialogBox.style.borderRadius = '8px'
  85. dialogBox.style.zIndex = '9999'
  86. dialogBox.innerHTML = `
  87. <span id="closeBtn" style="position: absolute; top: 10px; right: 10px; color: red; cursor: pointer; font-size: 30px;">&times;</span>
  88. <p style="font-weight: bold; font-size: 20px;"> <span id="linkTextSpan" style="color: red;">${linkText}</span> 操作</p>
  89. <button id="forumSearchBtn">论坛搜索</button>
  90. <button id="openUrlBtn">打开网址</button>
  91. <button id="copyLinkBtn">复制链接</button>
  92. `
  93. document.body.appendChild(dialogBox)
  94.  
  95. let dialogInitialX, dialogInitialY, initialX, initialY
  96. dialogBox.addEventListener('mousedown', onMouseDown)
  97. dialogBox.addEventListener('touchstart', onTouchStart)
  98.  
  99. function onMouseDown(event) {
  100. dialogInitialX = dialogBox.offsetLeft
  101. dialogInitialY = dialogBox.offsetTop
  102. initialX = event.clientX
  103. initialY = event.clientY
  104. document.addEventListener('mousemove', onMouseMove)
  105. document.addEventListener('mouseup', onMouseUp)
  106. }
  107.  
  108. function onTouchStart(event) {
  109. dialogInitialX = dialogBox.offsetLeft
  110. dialogInitialY = dialogBox.offsetTop
  111. initialX = event.touches[0].clientX
  112. initialY = event.touches[0].clientY
  113. document.addEventListener('touchmove', onTouchMove)
  114. document.addEventListener('touchend', onTouchEnd)
  115. }
  116.  
  117. function onMouseMove(event) {
  118. const deltaX = event.clientX - initialX
  119. const deltaY = event.clientY - initialY
  120. dialogBox.style.left = dialogInitialX + deltaX + 'px'
  121. dialogBox.style.top = dialogInitialY + deltaY + 'px'
  122. }
  123.  
  124. function onTouchMove(event) {
  125. const deltaX = event.touches[0].clientX - initialX
  126. const deltaY = event.touches[0].clientY - initialY
  127. dialogBox.style.left = dialogInitialX + deltaX + 'px'
  128. dialogBox.style.top = dialogInitialY + deltaY + 'px'
  129. }
  130.  
  131. function onMouseUp() {
  132. document.removeEventListener('mousemove', onMouseMove)
  133. document.removeEventListener('mouseup', onMouseUp)
  134. }
  135.  
  136. function onTouchEnd() {
  137. document.removeEventListener('touchmove', onTouchMove)
  138. document.removeEventListener('touchend', onTouchEnd)
  139. }
  140.  
  141. document.getElementById('linkTextSpan').style.pointerEvents = 'none'
  142. document.getElementById('closeBtn').addEventListener('click', function () {
  143. document.body.removeChild(dialogBox)
  144. })
  145.  
  146. document.getElementById('copyLinkBtn').addEventListener('click', function () {
  147. const linkText = document.getElementById('linkTextSpan').innerText
  148. const tempTextarea = document.createElement('textarea')
  149. tempTextarea.value = linkText
  150. document.body.appendChild(tempTextarea)
  151. tempTextarea.select()
  152. document.execCommand('copy')
  153. document.body.removeChild(tempTextarea)
  154. document.body.removeChild(dialogBox)
  155. Toast('文本已复制到剪贴板!', 1000)
  156. })
  157.  
  158. document.getElementById('forumSearchBtn').addEventListener('click', function () {
  159. const newUrl = `https://${location.host}/zh-CN/scripts/by-site/${linkText}`
  160. navigateTo(newUrl, useWindowOpen)
  161. document.body.removeChild(dialogBox)
  162. })
  163.  
  164. document.getElementById('openUrlBtn').addEventListener('click', function () {
  165. const originalUrl = `https://${linkText.replace(/\d+/g, '')}`
  166. navigateTo(originalUrl, useWindowOpen)
  167. document.body.removeChild(dialogBox)
  168. })
  169. } else if (linkBehavior === 1) {
  170. const originalUrl = `https://${linkText.replace(/\d+/g, '')}`
  171. navigateTo(originalUrl, useWindowOpen)
  172. } else if (linkBehavior === 2) {
  173. const newUrl = `https://${location.host}/zh-CN/scripts/by-site/${linkText}`
  174. navigateTo(newUrl, useWindowOpen)
  175. }
  176. }
  177.  
  178. const appliesToSection = document.querySelector('dt.script-show-applies-to')
  179. if (appliesToSection) {
  180. const changeConfigText = document.createElement('span')
  181. changeConfigText.textContent = '[适用于] '
  182. changeConfigText.style.fontWeight = 'bold'
  183.  
  184. const checkboxLabel = document.createElement('label')
  185. checkboxLabel.textContent = '新窗口打开'
  186. checkboxLabel.style.marginLeft = '10px'
  187.  
  188. const checkboxInput = document.createElement('input')
  189. checkboxInput.type = 'checkbox'
  190. checkboxInput.checked = useWindowOpen
  191. checkboxInput.style.marginRight = '5px'
  192.  
  193. checkboxInput.addEventListener('change', function () {
  194. useWindowOpen = checkboxInput.checked
  195. GM_setValue('useWindowOpen', useWindowOpen)
  196. })
  197.  
  198. checkboxLabel.appendChild(checkboxInput)
  199.  
  200. const selectList = document.createElement('select')
  201. selectList.style.width = '7em'
  202. const options = [
  203. { value: 0, text: '弹出提示' },
  204. { value: 1, text: '打开网址' },
  205. { value: 2, text: '论坛搜索' }
  206. ]
  207. options.forEach(option => {
  208. const optionElement = document.createElement('option')
  209. optionElement.textContent = option.text
  210. optionElement.value = option.value
  211. if (linkBehavior === option.value) {
  212. optionElement.selected = true
  213. }
  214. selectList.appendChild(optionElement)
  215. })
  216. selectList.addEventListener('change', function () {
  217. linkBehavior = parseInt(selectList.value)
  218. GM_setValue('linkBehavior', linkBehavior)
  219. Toast(`点击"适用于"网址已设置为: ${options.find(option => option.value === linkBehavior).text}`, 1000)
  220. })
  221.  
  222. appliesToSection.parentElement.appendChild(changeConfigText)
  223. appliesToSection.parentElement.appendChild(selectList)
  224. appliesToSection.parentElement.appendChild(checkboxLabel)
  225. }
  226. })();
  227.  

QingJ © 2025

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