From 1a9fbb061f3391ef1f7fc55bcc23132125d28890 Mon Sep 17 00:00:00 2001 From: Dave Gallant Date: Thu, 6 Apr 2023 21:48:53 -0400 Subject: [PATCH] Add chrome extension source --- README.md | 20 ++++++++++++++++++-- extensions/chrome/background.js | 18 ++++++++++++++++++ extensions/chrome/content.js | 30 ++++++++++++++++++++++++++++++ extensions/chrome/icon.png | Bin 0 -> 4472 bytes extensions/chrome/manifest.json | 21 +++++++++++++++++++++ 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 extensions/chrome/background.js create mode 100644 extensions/chrome/content.js create mode 100644 extensions/chrome/icon.png create mode 100644 extensions/chrome/manifest.json diff --git a/README.md b/README.md index 32917b0..58e43f7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,23 @@ # 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. +rfd-redirect-stripper 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. +This helps prevent broken links from collisions with adblockers. Only use if you are experiencing difficulties opening links. Affiliate links and referrals help support RedFlagDeals.com. + +## Tampermonkey Script + +This was originally a [Tampermonkey](https://www.tampermonkey.net/) userscript before evolving into a browser extension. + +Copy [script.js](./script.js) into Tampermonkey. + +## Chrome extension + +To load the browser extension, clone this repo and load [extensions/chrome](./extensions/chrome/). + +## Updating redirects + +The chrome extension will update itself by periodically fetching the latest [redirects.json](redirects.json). + +Open a pull request to this repo to update the redirects. diff --git a/extensions/chrome/background.js b/extensions/chrome/background.js new file mode 100644 index 0000000..58cd4de --- /dev/null +++ b/extensions/chrome/background.js @@ -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); diff --git a/extensions/chrome/content.js b/extensions/chrome/content.js new file mode 100644 index 0000000..f3a2fb2 --- /dev/null +++ b/extensions/chrome/content.js @@ -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(); diff --git a/extensions/chrome/icon.png b/extensions/chrome/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ca71db24f56d0e52a4943b1813bf9fd7ac43bb51 GIT binary patch literal 4472 zcmeHLdsGuw8V`cv1`t>)vPxwftw*ernY=RtK_dYPH8#jY=<&g1W&$JRK{A*ig4W`@ ztq81pY!zBip-Z8)LhFNqRn)p})oP`uF0v@lmbTKmTC1z8dnde4d(Ixt+5SgzX70@Q z_}%aOec!z&H`@(M7yAjP2?YXypDtFr42&3mO`HJk%f~(33Wihb5>vQkq!Y5)ttK{$ zfw){712HbvBoMf+n+=*jo`xni-rW(YStCN*6N}G&7~Z*K{*iI@&1L?_ zlO$+3fZVAgDxs+ARCaw zzWm+l*wYI`&a6&22v70$*)h>neJgG1l%A9tL!t2PdbX`F+t`r?OsuI?X_g)ZG zGf8yuIB`_Csl$6)&CZgFouv<&4_$`OzS3FHc;c6%dEOI$mRxcl3e#etNNkOD|kM$_j}pmqLc6*NK?3JUfkT%F@?$dpYaL1zANv+);9~buMi%K zOY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rome/manifest.json b/extensions/chrome/manifest.json new file mode 100644 index 0000000..e727c73 --- /dev/null +++ b/extensions/chrome/manifest.json @@ -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/*"] +}