Last active
April 5, 2018 08:57
-
-
Save nkmathew/472be27e25163391e249 to your computer and use it in GitHub Desktop.
Greasemonkey script that adds a link for viewing a reddit thread using reddit-stream
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 Add reddit-stream.com Link | |
// @namespace http://nkmathew.net | |
// @author nkmathew | |
// @description Adds links to view the posts in a subreddit's frontpage using reddit-stream | |
// @icon http://www.reddit.com/favicon.ico | |
// @icon64 http://www.reddit.com/favicon.ico | |
// @version 0.2.0 | |
// @include /^https?:\/\/(.+\.)?reddit\.com\/?.*$/ | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// ==/UserScript== | |
/* | |
* Change the color of the link through the .reddit-stream-link CSS class using | |
* Stylish | |
* | |
* The link is opened with a click handler instead of just embedding the | |
* reddit-stream url in the anchor so that you don't have the green WOT badges all | |
* over the subreddit frontpage | |
*/ | |
(function() { | |
window.addEventListener('load', function() { | |
var href, link; | |
if (/\/comments\//.test(window.location)) { | |
href = window.location; | |
link = ` | |
<li title="Open reddit-stream.com"> | |
<a href="#" class="reddit-stream" data-href="${href}"> | |
stream | |
</a> | |
</li> | |
`; | |
$(link).appendTo('#siteTable ul.flat-list.buttons'); | |
} else { | |
$('ul.flat-list.buttons').each(function() { | |
href = $('.comments', this).first().attr('href'); | |
link = ` | |
<li title="Open reddit-stream.com"> | |
<a href="#" class="reddit-stream" data-href="${href}"> | |
stream | |
</a> | |
</li> | |
`; | |
$(link).appendTo(this); | |
}); | |
} | |
$('.share').remove(); | |
$('.RES-save.noCtrlF').remove(); | |
$('.report-button').remove(); | |
$('.give-gold-button').remove(); | |
$('.res-toggleAllChildren').remove(); | |
$('.viewSource').remove(); | |
$('.hide-button').parent().remove(); | |
$('.reddit-stream').click(function(event) { | |
var href = $(this).data('href'); | |
event.preventDefault(); | |
href = href.replace('//www.reddit.com', '//www.reddit-stream.com'); | |
if (/comments/.test(window.location.href)) { | |
window.location.href = href; | |
} else { | |
window.open(href, '_blank'); | |
} | |
}); | |
}, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment