Greasyfork 脚本顯示評分

在瀏覽腳本列表時在腳本名稱後面添加腳本評分

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

  1. // ==UserScript==
  2. // @name Greasyfork Script Display Rating
  3. // @name:zh-CN Greasyfork 脚本显示评分
  4. // @name:zh-TW Greasyfork 脚本顯示評分
  5. // @name:en Display the script rating after the script list name
  6. // @name:fr Afficher la note du sc\ript après le nom de la liste de scripts
  7. // @name:ja スクリプトリスト名の後にスクリプト評価を表示する
  8. // @name:ko 스크립트 목록 이름 뒤에 스크립트 평가 표시
  9. // @namespace https://github.com/10086100886/
  10. // @version 1.3.3.41
  11. // @description Add the script rating after the script name when browsing the script list
  12. // @description:en Add the script rating after the script name when browsing the script list
  13. // @description:fr Ajouter la note du script après le nom du script lors de la navigation dans la liste des scripts
  14. // @description:ja スクリプトリストを閲覧する際にスクリプト名の後にスクリプト評価を追加する
  15. // @description:ko 스크립트 목록을 탐색할 때 스크립트 이름 뒤에 스크립트 평가 추가
  16. // @description:zh-CN 在浏览脚本列表时在脚本名称后面添加脚本评分
  17. // @description:zh-TW 在瀏覽腳本列表時在腳本名稱後面添加腳本評分
  18. // @author 人民的勤务员 <toniaiwanowskiskr47@gmail.com>
  19. // @match https://greasyfork.org/*
  20. // @match https://sleazyfork.org/*
  21. // @license MIT
  22. // @grant none
  23. // @icon https://greasyfork.org/vite/assets/blacklogo96-CxYTSM_T.png
  24. // @supportURL https://github.com/ChinaGodMan/UserScripts/issues
  25. // @homepageURL https://github.com/ChinaGodMan/UserScripts
  26. // ==/UserScript==
  27. (function () {
  28. 'use strict'
  29. // 检测脚本列表的出现,并自动插入评分
  30. function observeScriptList() {
  31. const scriptList = document.querySelector('.script-list')
  32. if (scriptList) {
  33. // 插入评分
  34. insertRatings(scriptList)
  35. // 配置观察器
  36. const observer = new MutationObserver(function (mutationsList, observer) {
  37. for (let mutation of mutationsList) {
  38. if (mutation.type === 'childList') {
  39. for (let node of mutation.addedNodes) {
  40. // 检查是否为脚本列表项
  41. if (node.nodeType === Node.ELEMENT_NODE && node.matches('li[data-script-id]')) {
  42. insertRating(node)
  43. }
  44. }
  45. }
  46. }
  47. })
  48. // 开始观察脚本列表的变化
  49. observer.observe(scriptList, { childList: true, subtree: true })
  50. }
  51. }
  52. // 插入评分
  53. function insertRating(scriptBlock) {
  54. const ratingElement = scriptBlock.querySelector('dd.script-list-ratings')
  55. if (ratingElement) {
  56. const rating = ratingElement.getAttribute('data-rating-score')
  57. const ratingDisplay = document.createElement('span')
  58. ratingDisplay.textContent = rating.replace(/[^\d.]/g, '')
  59. ratingDisplay.style.marginLeft = '30px'
  60. ratingDisplay.style.fontSize = '1em'
  61. ratingDisplay.style.color = '#ff8c00'
  62. ratingDisplay.style.fontWeight = 'bold'
  63. const titleElement = scriptBlock.querySelector('.script-link')
  64. if (titleElement) {
  65. titleElement.insertAdjacentElement('afterend', ratingDisplay)
  66. }
  67. }
  68. }
  69. // 插入评分到当前页面的脚本列表中
  70. function insertRatings(scriptList) {
  71. const scriptBlocks = scriptList.querySelectorAll('li[data-script-id]')
  72. scriptBlocks.forEach(insertRating)
  73. }
  74. // 开始观察当前页面脚本列表的出现
  75. observeScriptList()
  76. // 观察 body 元素以检测页面加载了下一页
  77. const bodyObserver = new MutationObserver(function (mutationsList, observer) {
  78. mutationsList.forEach(mutation => {
  79. mutation.addedNodes.forEach(node => {
  80. if (node.nodeType === Node.ELEMENT_NODE && node.matches('.script-list')) {
  81. // 页面加载了下一页,自动插入评分
  82. insertRatings(node)
  83. }
  84. })
  85. })
  86. })
  87. // 开始观察 body 元素的子节点变化
  88. bodyObserver.observe(document.body, { childList: true, subtree: true })
  89. })()