Last active
February 7, 2022 01:16
-
-
Save DeeNewcum/ce6c18eb4ec55bcb470c8711b935f5a1 to your computer and use it in GitHub Desktop.
Hilight newest stories on Reddit
This file contains hidden or 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 Hilight newest stories on Reddit | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author Dee Newcum | |
// @match https://old.reddit.com/ | |
// @match https://old.reddit.com/?* | |
// @description Highlights text within HTML | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js | |
// ==/UserScript== | |
// TODO: Get this working on mobile Firefox. | |
function background_colors_by_time() { | |
// uses jQuery | |
//$('time:contains("an hour ago")').css("background-color", "lightgreen"); | |
//$("time:contains('an hour ago')").css("background-color", "lightgreen"); | |
$("time.live-timestamp").each(function() { | |
//var txt = $( this ).text().replace(/^\d+ (?=minutes? ago)$/, "# "); | |
var txt = $( this ).text().replace(/^\d+ minutes? ago$/, "# minutes ago"); | |
switch (txt) { | |
case "just now": | |
case "# minutes ago": | |
case "1 hour ago": | |
$( this ).css("background-color", "lightgreen"); | |
break; | |
case "2 hours ago": | |
case "3 hours ago": | |
$( this ).css("background-color", "yellow"); | |
break; | |
case "4 hours ago": | |
$( this ).css("background-color", "#ff9999"); | |
break; | |
default: | |
//$( this ).css("background-color", "lightred"); | |
break; | |
} | |
}); | |
// Remove color backgrounds from flair, so the time-backgrounds stand out. (this is primarily for old.reddit.com, which has a much more overall-white look) | |
$("span.flairrichtext").css("background-color", "transparent").css("color", "black"); | |
} | |
(function() { | |
//'use strict'; | |
background_colors_by_time(); | |
// Giant hack to support https://github.com/honestbleeps/Reddit-Enhancement-Suite/blob/master/lib/modules/neverEndingReddit.js | |
// This is somewhat efficient, but it works with minimal effort on my part. | |
$( window ).scroll(function() { | |
background_colors_by_time(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment