Created
June 5, 2015 20:33
-
-
Save dnicolson/56451a826c25d9f4f6f9 to your computer and use it in GitHub Desktop.
UserScript to highlight JavaScript/Ruby articles on Hacker News
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 Hacker News Article Highlighter | |
// @version 0.1 | |
// @author You | |
// @include https://news.ycombinator.com/* | |
// @grant none | |
// @noframes | |
// ==/UserScript== | |
// Requires Hacker News Enhancement Suite | |
var jsMatches = /JavaScript|JS|Node|io.js|Front-end|Frontend|Chrome|V8|DevTools/i; | |
var rubyMatches = /Ruby|Rails|MRI|Rubinius|JRuby|Matz/i; | |
var css = ` | |
.athing.highlight td:first-child::before { | |
position: absolute; | |
left: 8px; | |
top: 8px; | |
width: 16px; | |
height: 16px; | |
content: ''; | |
} | |
.athing.ruby td:first-child::before { | |
background-color: fireBrick; | |
} | |
.athing.js td:first-child::before { | |
background-color: mediumSpringGreen; | |
} | |
`; | |
var style = document.createElement('style'); | |
document.head.appendChild(style); | |
style.innerHTML = css; | |
var items = document.querySelectorAll('.athing'); | |
for (var i = 0; i < items.length; i++) { | |
var item = items[i]; | |
var title = item.querySelector('.title > a'); | |
if (title.innerHTML.match(jsMatches)) { | |
item.className += ' highlight js'; | |
} | |
if (title.innerHTML.match(rubyMatches)) { | |
item.className += ' highlight ruby'; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment