Last active
June 10, 2017 11:08
-
-
Save 1lastBr3ath/7ce310200472b8cd3729e4bffc63c527 to your computer and use it in GitHub Desktop.
Auto navigate to New posts when requested reddit.com/r
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 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