Skip to content

Instantly share code, notes, and snippets.

@1lastBr3ath
Last active June 10, 2017 11:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1lastBr3ath/7ce310200472b8cd3729e4bffc63c527 to your computer and use it in GitHub Desktop.
Save 1lastBr3ath/7ce310200472b8cd3729e4bffc63c527 to your computer and use it in GitHub Desktop.
Auto navigate to New posts when requested reddit.com/r
// ==UserScript==
// @name reddit | NEW Posts
// @namespace @1lastBr3ath
// @description Auto navigate to new posts when requested reddit.com/r
// @include /https?:\/\/[a-z0-9._-]+\.reddit\.com\/r\/[a-z0-9._-]+\/?/
// @version 1.0
// @grant none
// @runat document-start
// ==/UserScript==
(function(){
var current_url = document.URL;
var pattern = /^https?:\/\/[a-z0-9._-]+\.reddit\.com\/r\/([a-z0-9._-]+)\/?/i;
var matches = current_url.match(pattern);
var expected_url = matches[0];
var subreddit = matches[1];
if(document.referrer.match(/\/r\/([a-z0-9._-]+)\/?/i)[1] === subreddit){
return;
}
if((current_url === expected_url) && !current_url.endsWith('/new')){
if(current_url.endsWith('/')){
location.href += 'new';
}
else{
location.href += '/new';
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment