Skip to content

Instantly share code, notes, and snippets.

@Xiyng
Last active August 15, 2017 02:32
Show Gist options
  • Save Xiyng/5e430a5c70993603dda1d82f013873a3 to your computer and use it in GitHub Desktop.
Save Xiyng/5e430a5c70993603dda1d82f013873a3 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Manipulate threads under chosen sections on VGChartz front page
// @description Manipulates threads in the chosen sections of the forums on the VGChartz front page. To customize, edit this script (instructions in the script).
// @namespace Xiyng
// @version 1.1
// @include http://www.vgchartz.com
// @include http://www.vgchartz.com/
// @include https://www.vgchartz.com
// @include https://www.vgchartz.com/
// @grant none
// ==/UserScript==
//-----------------------//
// CONFIGURATION SECTION //
//-----------------------//
// If you want to add custom sections here, just add them between the
// brackets, comma-separated from the other sections, and surrounded
// with quotation marks. Don't put two sections between the same
// quotation marks! New sections can be either on the same line or on
// another line (as long as they're between the brackets). The worst
// that can happen if you make a mistake is that the script stops
// working.
var affectedSections = [
"Politics Discussion"
];
// You can choose what to do with affected threads. The possible
// choices are listed here, and you can make the choice later below.
var displayChoices = {
hide: 1, // Hides the posts entirely.
dim: 2, // Dims the posts according to the dim strength set below.
highlight: 3 // Highlights the section with the color set below.
};
// Choose what will be done to the affected sections.
// Possible options are listed above under 'displayChoices'.
// Just replace the word 'hide' with some other word from the
// 'displayChoices' section.
var displayChoice = displayChoices.hide;
// Choose anything from 0.0 to 1.0.
var dimStrength = 0.5;
// Most common colors should work.
var highlightColor = "red";
//------------------------------------------//
// CONFIGURATION SECTION ENDS, MAGIC STARTS //
//------------------------------------------//
document.addEventListener("DOMContentLoaded", initialize);
window.addEventListener("load", initialize);
var executed = false;
function initialize() {
if (executed) {
return;
}
hideThreads(displayChoice);
executed = true;
}
function hideThreads(displayChoice) {
var rightBar = document.getElementById("rightbar");
var threads = rightbar.getElementsByClassName("forum_post");
for (var i = 0; i < threads.length; i++) {
var thread = threads[i];
var section = thread
.getElementsByTagName("span")[0]
.getElementsByTagName("a")[0]
.textContent
.trim();
if (affectedSections.indexOf(section) >= 0) {
switch (displayChoice) {
case displayChoices.hide:
thread.parentNode.style.display = "none";
break;
case displayChoices.dim:
thread.parentNode.style.opacity = 1.0 - dimStrength;
break;
case displayChoices.highlight:
thread
.getElementsByTagName("span")[0]
.getElementsByTagName("a")[0]
.style.color = highlightColor;
break;
default:
console.log("Looks like you screwed up configuration.");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment