-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedditFixHTTPAndNPLinks.user.js
More file actions
39 lines (35 loc) · 994 Bytes
/
RedditFixHTTPAndNPLinks.user.js
File metadata and controls
39 lines (35 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// ==UserScript==
// @name Reddit: Fix http and np Links
// @namespace http://github.com/alienacorn
// @description Rewrite links
// @include http://www.reddit.com/*
// @include https://www.reddit.com/*
// @version 1
// @grant none
// ==/UserScript==
function GM_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(GM_wait,100);
} else {
GM_use_JQuery();
}
}
GM_wait();
function GM_use_JQuery() {
var nplinks = /^https?:\/\/np\.reddit\.com\/(.*)/;
var nonhttps = /^http:\/\/www\.reddit\.com\/(.*)/;
var $ = unsafeWindow.jQuery;
$('a[href]').each(
function(i){
var href = $(this).attr('href');
if (href.match(nplinks)) {
var fixed = href.replace(nplinks, 'https://www.reddit.com/$1');
$(this).attr('href', fixed);
}
if (href.match(nonhttps)) {
var fixed = href.replace(nonhttps, 'https://www.reddit.com/$1');
$(this).attr('href', fixed);
}
}
)
}