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:
18
extensions/chrome/background.js
Normal file
18
extensions/chrome/background.js
Normal file
@@ -0,0 +1,18 @@
|
||||
function updateRedirects() {
|
||||
var URL =
|
||||
"https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/redirects.json";
|
||||
|
||||
fetch(URL)
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
chrome.storage.local.set({
|
||||
"rfd-redirects": res,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
chrome.runtime.onInstalled.addListener(() => {
|
||||
updateRedirects();
|
||||
});
|
||||
|
||||
setInterval(updateRedirects, 1 * 60 * 60 * 1000);
|
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();
|
BIN
extensions/chrome/icon.png
Normal file
BIN
extensions/chrome/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
21
extensions/chrome/manifest.json
Normal file
21
extensions/chrome/manifest.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"name": "rfd-redirect-stripper",
|
||||
"description": "Strip tracking redirects on rfd",
|
||||
"version": "0.1",
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["*://forums.redflagdeals.com/*"],
|
||||
"js": ["content.js"],
|
||||
"run_at": "document_end"
|
||||
}
|
||||
],
|
||||
"action": {
|
||||
"default_icon": "icon.png"
|
||||
},
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
"permissions": ["scripting", "storage"],
|
||||
"host_permissions": ["*://forums.redflagdeals.com/*"]
|
||||
}
|
Reference in New Issue
Block a user