Greasyfork 脚本显示评分

在浏览脚本列表时在脚本名称后面添加脚本评分

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

  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.8
  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://www.google.com/s2/favicons?domain=greasyfork.org
  24. // ==/UserScript==
  25. (function () {
  26. 'use strict'
  27. // 检测脚本列表的出现,并自动插入评分
  28. function observeScriptList() {
  29. const scriptList = document.querySelector('.script-list')
  30. if (scriptList) {
  31. // 插入评分
  32. insertRatings(scriptList)
  33. // 配置观察器
  34. const observer = new MutationObserver(function (mutationsList, observer) {
  35. for (let mutation of mutationsList) {
  36. if (mutation.type === 'childList') {
  37. for (let node of mutation.addedNodes) {
  38. // 检查是否为脚本列表项
  39. if (node.nodeType === Node.ELEMENT_NODE && node.matches('li[data-script-id]')) {
  40. insertRating(node)
  41. }
  42. }
  43. }
  44. }
  45. })
  46. // 开始观察脚本列表的变化
  47. observer.observe(scriptList, { childList: true, subtree: true })
  48. }
  49. }
  50. // 插入评分
  51. function insertRating(scriptBlock) {
  52. const ratingElement = scriptBlock.querySelector('dd.script-list-ratings')
  53. if (ratingElement) {
  54. const rating = ratingElement.getAttribute('data-rating-score')
  55. const ratingDisplay = document.createElement('span')
  56. ratingDisplay.textContent = rating.replace(/[^\d.]/g, '')
  57. ratingDisplay.style.marginLeft = '30px'
  58. ratingDisplay.style.fontSize = '1em'
  59. ratingDisplay.style.color = '#ff8c00'
  60. ratingDisplay.style.fontWeight = 'bold'
  61. const titleElement = scriptBlock.querySelector('.script-link')
  62. if (titleElement) {
  63. titleElement.insertAdjacentElement('afterend', ratingDisplay)
  64. }
  65. }
  66. }
  67. // 插入评分到当前页面的脚本列表中
  68. function insertRatings(scriptList) {
  69. const scriptBlocks = scriptList.querySelectorAll('li[data-script-id]')
  70. scriptBlocks.forEach(insertRating)
  71. }
  72. // 开始观察当前页面脚本列表的出现
  73. observeScriptList()
  74. // 观察 body 元素以检测页面加载了下一页
  75. const bodyObserver = new MutationObserver(function (mutationsList, observer) {
  76. mutationsList.forEach(mutation => {
  77. mutation.addedNodes.forEach(node => {
  78. if (node.nodeType === Node.ELEMENT_NODE && node.matches('.script-list')) {
  79. // 页面加载了下一页,自动插入评分
  80. insertRatings(node)
  81. }
  82. })
  83. })
  84. })
  85. // 开始观察 body 元素的子节点变化
  86. bodyObserver.observe(document.body, { childList: true, subtree: true })
  87. })()