Greasy Fork

Greasy Fork is available in English.

Nga 显示VIP

在看帖界面显示VIP的ui

当前为 2024-02-13 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Nga 显示VIP
// @namespace    http://greasyfork.icu/users/325815
// @version      1.0.0
// @description  在看帖界面显示VIP的ui
// @author       monat151
// @license      MIT
// @match        http*://nga.178.com/read.php?tid=*
// @match        http*://ngabbs.com/read.php?tid=*
// @match        http*://bbs.nga.cn/read.php?tid=*
// @match        http*://bbs.nga.cn/read.php?pid=*
// @match        http*://ngabbs.com/read.php?pid=*
// @match        http*://nga.178.com/read.php?pid=*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=nga.cn
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function isNumeric(str) { return !isNaN(str) && !isNaN(parseFloat(str)); }
    function currentUnixTimeStamp() { return Math.floor(Date.now() / 1000); }

    function getPageJson(cb) {
        fetch(
            document.location.href + '&__output=8'
        ).then(
            res => res.arrayBuffer()
        ).then(res => {
            const text = new TextDecoder('gbk').decode(res)
            const json = JSON.parse(text.replaceAll('\t',''))
            cb(json)
        })
    }
    function isVip(u, ct) {
        if (!u?.buffs || !u.buffs[129]) {
            return false
        }
        let result = false
        for (var i in u.buffs[129]) {
            const buff = u.buffs[129][i]
            if (buff[5] && buff[6]) {
                if (buff[6] === 2048 && buff[5] > ct) {
                    result = true
                }
            }
        }
        return result
    }
    function generateVipUi() {
        const ui = document.createElement('a')
        ui.href = 'javascript:void(0)'
        ui.className = 'small_colored_text_btn stxt block_txt_c0 vertmod'
        ui.style = 'background: #ff5858;'
        ui.innerHTML = 'VIP'
        ui.title = '这个用户是NGA的VIP'
        return ui
    }

    setTimeout(() => {
        getPageJson(json => {
            const currentTimestamp = currentUnixTimeStamp()
            const vips = []
            const users = json.data.__U
            for (var uid in users) {
                if (isNumeric(uid)) {
                    const user = users[uid]
                    if (isVip(user, currentTimestamp)) {
                        vips.push(uid)
                    }
                }
            }
            const pageUidUIs = document.getElementsByName('uid')
            const generalVipUI = generateVipUi()
            for (let i=0; i < pageUidUIs.length; i++) {
                const uid = pageUidUIs[i].innerText
                if (vips.indexOf(uid) >= 0) {
                    document.getElementsByName('uid')[i].after(generateVipUi())
                }
            }
        })
    }, 100)
})();