mirror of
https://github.com/davegallant/rfd-redirect-stripper.git
synced 2025-08-06 00:33:39 +00:00
Use named capture groups
This commit is contained in:
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# rfd-redirect-stripper
|
||||
|
||||
This is a [Tampermonkey](https://www.tampermonkey.net/) userscript that strips affiliate redirects from deal links posted on https://forums.redflagdeals.com.
|
||||
|
||||
## Why?
|
||||
|
||||
This can help prevent broken links from collisions with adblockers. I wouldn't suggest using this unless you are experiencing difficulties opening links. Affiliate links and referrals help support RedFlagDeals.com.
|
51
script.js
Normal file
51
script.js
Normal file
@@ -0,0 +1,51 @@
|
||||
// ==UserScript==
|
||||
// @author Dave Gallant
|
||||
// @description Strip redirect links on forums.redflagdeals.com
|
||||
// @downloadURL https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/script.js
|
||||
// @grant none
|
||||
// @match *://forums.redflagdeals.com/*
|
||||
// @name RedFlagDeals Redirect Stripper
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @updateURL https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/script.js
|
||||
// @version 0.0.1
|
||||
// ==/UserScript==
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var Links = document.querySelectorAll('a.postlink, a.autolinker_link');
|
||||
|
||||
const REDIRECT_REGEX = [
|
||||
{
|
||||
name: 'Amazon',
|
||||
pattern: 'www.amazon.ca/gp/redirect.html\\?ie=UTF8&location=(?<baseUrl>.*?)(&|ref%3D|%3F)',
|
||||
},
|
||||
{
|
||||
name: 'Best Buy',
|
||||
pattern: 'bestbuyca.(.*).net(.*)\\?u=(?<baseUrl>.*)',
|
||||
},
|
||||
];
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
})();
|
Reference in New Issue
Block a user