Greasyfork 脚本顯示評分

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

目前為 2024-07-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Greasyfork Script Display Rating
// @name:zh-CN         Greasyfork 脚本显示评分
// @name:zh-TW         Greasyfork 脚本顯示評分
// @name:en      Display the script rating after the script list name
// @name:fr      Afficher la note du sc\ript après le nom de la liste de scripts
// @name:ja      スクリプトリスト名の後にスクリプト評価を表示する
// @name:ko      스크립트 목록 이름 뒤에 스크립트 평가 표시
// @namespace    https://github.com/10086100886/
// @version      1.3.3
// @description     Add the script rating after the script name when browsing the script list
// @description:en  Add the script rating after the script name when browsing the script list
// @description:fr  Ajouter la note du script après le nom du script lors de la navigation dans la liste des scripts
// @description:ja  スクリプトリストを閲覧する際にスクリプト名の後にスクリプト評価を追加する
// @description:ko  스크립트 목록을 탐색할 때 스크립트 이름 뒤에 스크립트 평가 추가
// @description:zh-CN 在浏览脚本列表时在脚本名称后面添加脚本评分
// @description:zh-TW  在瀏覽腳本列表時在腳本名稱後面添加腳本評分
// @author       人民的勤务员 <[email protected]>
// @match        https://greasyfork.org/* 
// @match        https://sleazyfork.org/* 
// @license      MIT
// @grant        none
// @icon         https://www.google.com/s2/favicons?domain=greasyfork.org
// ==/UserScript==
(function () {
    'use strict'
    // 检测脚本列表的出现,并自动插入评分
    function observeScriptList() {
        const scriptList = document.querySelector('.script-list')
        if (scriptList) {
            // 插入评分
            insertRatings(scriptList)
            // 配置观察器
            const observer = new MutationObserver(function (mutationsList, observer) {
                for (let mutation of mutationsList) {
                    if (mutation.type === 'childList') {
                        for (let node of mutation.addedNodes) {
                            // 检查是否为脚本列表项
                            if (node.nodeType === Node.ELEMENT_NODE && node.matches('li[data-script-id]')) {
                                insertRating(node)
                            }
                        }
                    }
                }
            })
            // 开始观察脚本列表的变化
            observer.observe(scriptList, { childList: true, subtree: true })
        }
    }
    // 插入评分
    function insertRating(scriptBlock) {
        const ratingElement = scriptBlock.querySelector('dd.script-list-ratings')
        if (ratingElement) {
            const rating = ratingElement.getAttribute('data-rating-score')
            const ratingDisplay = document.createElement('span')
            ratingDisplay.textContent = rating.replace(/[^\d.]/g, '')
            ratingDisplay.style.marginLeft = '30px'
            ratingDisplay.style.fontSize = '1em'
            ratingDisplay.style.color = '#ff8c00'
            ratingDisplay.style.fontWeight = 'bold'
            const titleElement = scriptBlock.querySelector('.script-link')
            if (titleElement) {
                titleElement.insertAdjacentElement('afterend', ratingDisplay)
            }
        }
    }
    // 插入评分到当前页面的脚本列表中
    function insertRatings(scriptList) {
        const scriptBlocks = scriptList.querySelectorAll('li[data-script-id]')
        scriptBlocks.forEach(insertRating)
    }
    // 开始观察当前页面脚本列表的出现
    observeScriptList()
    // 观察 body 元素以检测页面加载了下一页
    const bodyObserver = new MutationObserver(function (mutationsList, observer) {
        mutationsList.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === Node.ELEMENT_NODE && node.matches('.script-list')) {
                    // 页面加载了下一页,自动插入评分
                    insertRatings(node)
                }
            })
        })
    })
    // 开始观察 body 元素的子节点变化
    bodyObserver.observe(document.body, { childList: true, subtree: true })
})()