c-plusplus.net Alternating Post Backgrounds

try to take over the world!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         c-plusplus.net Alternating Post Backgrounds
// @namespace    http://tampermonkey.net/
// @version      0.9
// @description  try to take over the world!
// @author       Swordfishx86
// @include      https://www.c-plusplus.net/*
// @include      http://www.c-plusplus.net/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant        GM_addStyle
// @run-at       document-start
// ==/UserScript==

var background_colors = [ "#f2f2f2", "#f9f9f9" ];
var blockquote_line_color = "#c9c9c9";

GM_addStyle( "div.post-bar > hr { display: none; }" );
GM_addStyle( "#content > div.row > div.topic.col-lg-12 > ul > li > div.content > blockquote { border-left: 5px solid " + blockquote_line_color + "; margin: 0 0 10px; padding: 10px 10px; }" );
GM_addStyle( "#content > div.row > div.topic.col-lg-12 > ul > li > hr:last-of-type { display: none; }" );
GM_addStyle( "#content > div.row > div.topic.col-lg-12 > ul > li, #content > div.row > div.category.col-lg-12 > ul > li, #content > div.row > div.col-lg-12 > ul > li, #content > div.row > div.category.col-lg-12 > div.subcategory > ul > li, #content > div.recent > div.category > ul > li, #content > div.popular > div.category > ul > li, #content > div.unread > div.category > ul > li { padding: 15px 10px 15px 10px; margin: 18px 0px 18px 0px; }");

function beautifier(selector, jNode) {
    var x = document.querySelectorAll(selector);
    for (i = 0; i < x.length; ++i) {
        x[i].style.backgroundColor = background_colors[i % 2];
        var bq = x[i].querySelectorAll("blockquote");
        for(var n = 0; n < bq.length; ++n ) {
            bq[n].style.backgroundColor = background_colors[(i + 1) % 2];
        }
    }
}

function waitForKeyElements(selectorTxt, actionFunction)
{
    var targetNodes = $(selectorTxt), btargetsFound;

    if (targetNodes && targetNodes.length > 0) {
        btargetsFound = true;
        targetNodes.each ( function () {
            var jThis = $(this);
            var alreadyFound = jThis.data ('alreadyFound') || false;

            if (!alreadyFound) {
                var cancelFound = actionFunction (jThis);
                if (cancelFound) {
                    btargetsFound = false;
                } else {
                    jThis.data ('alreadyFound', true);
                }
            }
        } );
    }
    else {
        btargetsFound = false;
    }

    var controlObj = waitForKeyElements.controlObj || {};
    var controlKey = selectorTxt.replace (/[^\w]/g, "_");
    var timeControl = controlObj [controlKey];

    if ( ! timeControl) {
        timeControl = setInterval(function(){waitForKeyElements(selectorTxt, actionFunction, false, false);}, 500);
        controlObj [controlKey] = timeControl;
    }
    waitForKeyElements.controlObj = controlObj;
}

var selectors = [
    "#content > div.row > div.topic.col-lg-12 > ul > li",
    "#content > div.row > div.category.col-lg-12 > ul > li",
    "#content > div.row > div.col-lg-12 > ul > li",
    "#content > div.row > div.category.col-lg-12 > div.subcategory > ul > li",
    "#content > div.recent > div.category > ul > li",
    "#content > div.popular > div.category > ul > li",
    "#content > div.unread > div.category > ul > li"
];

for(var i = 0; i < selectors.length; ++i) {
    waitForKeyElements(selectors[i], beautifier.bind(null, selectors[i]));
}