mirror of
https://github.com/davegallant/rfd-redirect-stripper.git
synced 2025-08-07 09:02:30 +00:00
Add chrome extension source
This commit is contained in:
30
extensions/chrome/content.js
Normal file
30
extensions/chrome/content.js
Normal file
@@ -0,0 +1,30 @@
|
||||
function stripRedirect(URL, redirectRegex) {
|
||||
for (var i = 0; i < redirectRegex.length; i++) {
|
||||
var rule = redirectRegex[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;
|
||||
}
|
||||
|
||||
function stripRedirects() {
|
||||
var Links = document.querySelectorAll("a.postlink, a.autolinker_link");
|
||||
|
||||
chrome.storage.local.get("rfd-redirects", function (redirectRegex) {
|
||||
Links.forEach(function (Link) {
|
||||
var ReferralURL = Link.href;
|
||||
|
||||
Link.href = stripRedirect(ReferralURL, redirectRegex["rfd-redirects"]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
stripRedirects();
|
Reference in New Issue
Block a user