-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js.tmpl
42 lines (36 loc) · 1.29 KB
/
script.js.tmpl
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
40
41
42
// ==UserScript==
// @name RedFlagDeals Affiliate Stripper
// @author Dave Gallant
// @description Strip redirect links on forums.redflagdeals.com
// @downloadURL https://raw.githubusercontent.com/davegallant/rfd-affiliate-stripper/main/script.js
// @grant none
// @match *://forums.redflagdeals.com/*
// @namespace http://tampermonkey.net/
// @updateURL https://raw.githubusercontent.com/davegallant/rfd-affiliate-stripper/main/script.js
// @version {{ (time.Now).Format "2006-01-02" }}
// ==/UserScript==
(function() {
'use strict';
var Links = document.querySelectorAll('a.postlink, a.autolinker_link');
const REDIRECT_REGEX = {{ file.Read "redirects.json" }};
var StripRedirect = function(URL) {
for (var i = 0; i < REDIRECT_REGEX.length; i++) {
var rule = REDIRECT_REGEX[i];
var result = new RegExp(rule.pattern).exec(URL);
if (result) {
var newURL = result.groups.baseUrl;
try {
return decodeURIComponent(newURL);
} catch (e) {
console.log(e);
return URL;
}
}
}
return URL;
};
Links.forEach(function(Link) {
var ReferralURL = Link.href;
Link.href = StripRedirect(ReferralURL);
});
})();