Created
June 25, 2016 12:18
-
-
Save MeLlamoPablo/b2cd9bb11d291dc87737efc1f9012d57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name TRUJ-Userscript | |
// @namespace http://reddit.com | |
// @version 0.1 | |
// @description This is a port of the chrome extension TRUJ to UserScript. | |
// The author of said extension is kmc and its download link can be found here: | |
// https://chrome.google.com/webstore/detail/true-unexpected-jihad/ihglffdfnfdifnlgjecjbnpkjffciibm | |
// I, (MeLLamoPablo a.k.a. /u/sfcpfc), am not responsible for any trouble that this UserScript may cause. | |
// Contact the original author instead. | |
// @author MeLLamoPablo a.k.a. /u/sfcpfc | |
// @match *://*.reddit.com/ | |
// @exclude *://*.reddit.com/r/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var defaultSettings = { | |
settings: { | |
postScore: { | |
min: 1700, | |
max: 3700 | |
}, | |
commentCount: { | |
min: 700, | |
max: 2500 | |
}, | |
postTime: { | |
min: 4, | |
max: 15 | |
}, | |
//These are the list of words that will randomly replace the subreddit(s) you have chosen. | |
//You don't need to add "/r/". Separate words with ";" | |
replaceList: "videos;unexpected;wtf", | |
//These are the subreddits that the extension will act upon. | |
//You don't need to add "/r/". Separate words with ";" | |
subredditList: "unexpectedjihad;unexpectedcena" | |
} | |
}; | |
function fuzzPosts(storage) { | |
var subElements = document.querySelectorAll('.link .entry .tagline .subreddit'); | |
var maxScore = storage.settings.postScore.max, | |
minScore = storage.settings.postScore.min, | |
maxCommentCount = storage.settings.commentCount.max, | |
minCommentCount = storage.settings.commentCount.min, | |
maxTime = storage.settings.postTime.max, | |
minTime = storage.settings.postTime.min, | |
//i'm trash at naming variables... | |
subsToReplace = storage.settings.subredditList, | |
replaceList = storage.settings.replaceList; | |
for (var i = 0; i < subElements.length; i++) { | |
var subHref = subElements[i].href; | |
var subsToReplaceSplit = subsToReplace.split(";"); | |
//cycle through replacement list | |
for (var j = 0; j < subsToReplaceSplit.length; j++) { | |
subHref = subElements[i].href.toLowerCase(); | |
//and then check if any posts match. also check if they aren't already fuzzed | |
if (subHref.indexOf(subsToReplaceSplit[j].toLowerCase()) > -1 && subElements[i].className.indexOf('fuzzed') == -1) { | |
subElements[i].className += " fuzzed"; | |
var randScore = randomInt(minScore, maxScore); | |
var randCommentCount = randomInt(minCommentCount, maxCommentCount); | |
var randTime = randomInt(minTime, maxTime); | |
var scoreElement = subElements[i].parentElement.parentElement.parentElement.querySelectorAll('.midcol .score'); | |
var commentElement = subElements[i].parentElement.parentElement.parentElement.querySelector('.buttons .first .comments'); | |
var timeElement = subElements[i].parentElement.parentElement.parentElement.querySelector('.entry .tagline .live-timestamp'); | |
var replaceListSplit = replaceList.split(";"); | |
var randReplace = replaceListSplit[Math.floor(Math.random() * replaceListSplit.length)]; | |
if (subElements[i].innerHTML !== null && randReplace !== null) { | |
subElements[i].innerHTML = "/r/" + randReplace; | |
} | |
//change numbers so voting shows up properly | |
for (var v = 0; v < scoreElement.length; v++) { | |
scoreElement[v].innerHTML = randScore; | |
randScore++; | |
} | |
commentElement.innerHTML = randCommentCount + " comments"; | |
timeElement.outerHTML = '<time class="live-timestamp">' + randTime + ' hours ago</time>'; | |
} | |
} | |
} | |
} | |
function randomInt(min, max){ | |
return Math.floor(Math.random() * (max - min) + min); | |
} | |
fuzzPosts(defaultSettings); | |
//called everytime the dom changes | |
var observer = new window.WebKitMutationObserver(function(mutations) { | |
for (var i = 0; i < mutations.length; i++) { | |
//this seemed to be the best way to check if RES loaded a new page | |
if (mutations[i].target.id.match(/([A-Za-z-])+/g) == "page-") { | |
fuzzPosts(defaultSettings); | |
} | |
} | |
}); | |
observer.observe(document, {subtree: true, attributes: true}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment