NGA Red List

参考V2EX的RedList做一个NGA版。在个人主页增加了一个拉红的功能,之后在帖子列表和详情页面被拉红的人的帖子或回复会标红显示。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NGA Red List
// @namespace    http://tampermonkey.net/
// @version      0.0.2
// @description  参考V2EX的RedList做一个NGA版。在个人主页增加了一个拉红的功能,之后在帖子列表和详情页面被拉红的人的帖子或回复会标红显示。
// @author       nyanpasus
// @match        *://nga.178.com/*
// @match        *://bbs.nga.cn/*
// @match        *://ngabbs.com/*
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at       document-end
// ==/UserScript==
/* jshint esversion: 6 */

(function() {
    'use strict';

    // Your code here...
    let profileUid;
    let listName = 'nga-red-list';
    let uidList = GM_getValue(listName, "");
    let redList = uidList.split(';');
    let url = document.URL;
    let path = location.pathname;
    let buttonName = 'redButton';

    setTimeout(function() {
        function redsb() {
            let uidList = GM_getValue(listName, "");
            let redList = uidList.split(';');
            if (redList.indexOf(profileUid) >= 0) {
                GM_setValue(listName, uidList.replace(';' + profileUid, ''));
            } else {
                GM_setValue(listName, uidList + ';' + profileUid);
            }
            document.getElementById(buttonName).innerText = GM_getValue(listName, '').split(';').indexOf(profileUid) >= 0 ? '[取消拉红]' : '[拉红对方]';
        }

        if (path.startsWith('/thread.php')) {
            let homeList = document.getElementsByClassName('author');
            let len = homeList.length;
            for (let index = 0; index < len; index++) {
                let uid = homeList[index].title.split(' ')[1];
                if (redList.indexOf(uid) >= 0) {
                    homeList[index].parentElement.previousElementSibling.style.cssText += "background-image:url(https://i.loli.net/2019/06/09/5cfbebdfd083a19907.png);background-size:contain;";
                    homeList[index].parentElement.style.cssText += "background-image:url(https://i.loli.net/2019/06/09/5cfbebdfd083a19907.png);background-size:contain;";
                }
            }
        } else if (path.startsWith('/read.php')) {
            let commentList = document.getElementsByName('uid');
            let len = commentList.length;
            for (let index = 0; index < len; index++) {
                let uid = commentList[index].innerText;
                if (redList.indexOf(uid) >= 0) {
                    commentList[index].parentElement.parentElement.parentElement.style.cssText += "background-image:url(https://i.loli.net/2019/06/09/5cfbebdfd083a19907.png);background-size:contain;";
                    commentList[index].parentElement.parentElement.parentElement.nextElementSibling.style.cssText += "background-image:url(https://i.loli.net/2019/06/09/5cfbebdfd083a19907.png);background-size:contain;";
                }
            }
        } else if (path.startsWith('/nuke.php')) {
            console.info("abc");
            profileUid = document.getElementsByClassName('info')[0].firstElementChild.lastElementChild.innerText.split(':')[1].trim();
            let buttonContainer = document.getElementsByClassName('actions')[0];
            let constructLi = document.createElement('li');
            constructLi.setAttribute('style','padding-right: 5px;');
            let constructSpan = document.createElement('span');
            let constructA = document.createElement('a');
            constructA.setAttribute('href','javascript:void(0)');
            constructA.setAttribute('id', buttonName);
            constructA.innerText = redList.indexOf(profileUid) >= 0 ? '[取消拉红]' : '[拉红对方]';
            let lastDiv = document.getElementsByClassName(' clear')[4];
            constructSpan.appendChild(constructA);
            constructLi.appendChild(constructSpan);
            buttonContainer.insertBefore(constructLi, lastDiv);
            document.getElementById(buttonName).onclick= redsb;
        }
    }, 1000);
})();