mirror of
https://github.com/davegallant/rfd-redirect-stripper.git
synced 2025-08-06 00:33:39 +00:00
Add Chrome support (#15)
* add chrome support * fix alarms * Add tkqlhce.com (#12) * add tkqlhce.com * add match at beginning of regex * formatting * set config needs to come first * still need background.scripts for firefox * need full path * add onStartup listener to ensure alarm is created * set time to 60 * add manifest specific to chrome and bump version
This commit is contained in:
@@ -4,13 +4,12 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>rfd-redirect-stripper</title>
|
<title>rfd-redirect-stripper</title>
|
||||||
<link rel="stylesheet" href="../css/popup.css" />
|
<link rel="stylesheet" href="../css/popup.css" />
|
||||||
<script src="../js/utils.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
Config URL:
|
Config URL:
|
||||||
<input type="text" id="input-field" />
|
<input type="text" id="input-field" />
|
||||||
<button id="save-button">Save</button>
|
<button id="save-button">Save</button>
|
||||||
<button id="reset-button">Reset</button>
|
<button id="reset-button">Reset</button>
|
||||||
<script src="../js/popup.js"></script>
|
<script type="module" src="../js/popup.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -1,6 +1,24 @@
|
|||||||
chrome.runtime.onInstalled.addListener(() => {
|
import { updateRedirects, setDefaultConfig } from "../js/utils.js"
|
||||||
|
|
||||||
|
function setAlarm() {
|
||||||
|
chrome.alarms.get('update-redirects', alarm => {
|
||||||
|
if (!alarm) {
|
||||||
|
chrome.alarms.create('update-redirects', { periodInMinutes: 60 });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
chrome.alarms.onAlarm.addListener(() => {
|
||||||
updateRedirects();
|
updateRedirects();
|
||||||
setDefaultConfig();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
setInterval(updateRedirects, 1 * 60 * 60 * 1000);
|
chrome.runtime.onInstalled.addListener(() => {
|
||||||
|
setDefaultConfig();
|
||||||
|
updateRedirects();
|
||||||
|
setAlarm();
|
||||||
|
});
|
||||||
|
|
||||||
|
//Ensure alarm is created
|
||||||
|
chrome.runtime.onStartup.addListener(() => {
|
||||||
|
setAlarm();
|
||||||
|
});
|
@@ -20,7 +20,7 @@ function stripRedirect(URL, redirectRegex) {
|
|||||||
function stripRedirects() {
|
function stripRedirects() {
|
||||||
var Links = document.querySelectorAll("a.postlink, a.autolinker_link");
|
var Links = document.querySelectorAll("a.postlink, a.autolinker_link");
|
||||||
|
|
||||||
browser.storage.local.get("redirects", function (result) {
|
chrome.storage.local.get("redirects", function (result) {
|
||||||
Links.forEach(function (Link) {
|
Links.forEach(function (Link) {
|
||||||
var ReferralURL = Link.href;
|
var ReferralURL = Link.href;
|
||||||
Link.href = stripRedirect(ReferralURL, result["redirects"]);
|
Link.href = stripRedirect(ReferralURL, result["redirects"]);
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
import { updateRedirects, setDefaultConfig } from "../js/utils.js"
|
||||||
|
|
||||||
const inputField = document.getElementById("input-field");
|
const inputField = document.getElementById("input-field");
|
||||||
const saveButton = document.getElementById("save-button");
|
const saveButton = document.getElementById("save-button");
|
||||||
const resetButton = document.getElementById("reset-button");
|
const resetButton = document.getElementById("reset-button");
|
||||||
@@ -5,7 +7,7 @@ const resetButton = document.getElementById("reset-button");
|
|||||||
const defaultConfig =
|
const defaultConfig =
|
||||||
"https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/redirects.json";
|
"https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/redirects.json";
|
||||||
|
|
||||||
browser.storage.local.get("config").then((result) => {
|
chrome.storage.local.get("config").then((result) => {
|
||||||
const value = result.config;
|
const value = result.config;
|
||||||
if (value) {
|
if (value) {
|
||||||
inputField.value = value;
|
inputField.value = value;
|
||||||
@@ -14,7 +16,7 @@ browser.storage.local.get("config").then((result) => {
|
|||||||
|
|
||||||
saveButton.addEventListener("click", () => {
|
saveButton.addEventListener("click", () => {
|
||||||
const value = inputField.value;
|
const value = inputField.value;
|
||||||
browser.storage.local.set({ config: value });
|
chrome.storage.local.set({ config: value });
|
||||||
updateRedirects();
|
updateRedirects();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
15
js/utils.js
15
js/utils.js
@@ -1,22 +1,25 @@
|
|||||||
function updateRedirects() {
|
export function updateRedirects() {
|
||||||
browser.storage.local.get("config", function (URL) {
|
chrome.storage.local.get("config", function (URL) {
|
||||||
fetch(URL.config)
|
fetch(URL.config)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
browser.storage.local
|
chrome.storage.local
|
||||||
.set({
|
.set({
|
||||||
redirects: res,
|
redirects: res,
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDefaultConfig() {
|
export function setDefaultConfig() {
|
||||||
browser.storage.local.set({
|
chrome.storage.local.set({
|
||||||
config:
|
config:
|
||||||
"https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/redirects.json",
|
"https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/redirects.json",
|
||||||
});
|
});
|
||||||
}
|
}
|
23
manifest-chrome.json
Normal file
23
manifest-chrome.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"manifest_version": 3,
|
||||||
|
"name": "rfd-redirect-stripper",
|
||||||
|
"description": "Strip tracking redirects on rfd",
|
||||||
|
"version": "0.2",
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": ["*://forums.redflagdeals.com/*"],
|
||||||
|
"js": ["js/content.js"],
|
||||||
|
"run_at": "document_end"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"action": {
|
||||||
|
"default_icon": "icon.png",
|
||||||
|
"default_popup": "html/popup.html"
|
||||||
|
},
|
||||||
|
"background": {
|
||||||
|
"service_worker": "js/background.js",
|
||||||
|
"type": "module"
|
||||||
|
},
|
||||||
|
"permissions": ["scripting", "storage", "alarms"],
|
||||||
|
"host_permissions": ["*://forums.redflagdeals.com/*"]
|
||||||
|
}
|
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "rfd-redirect-stripper",
|
"name": "rfd-redirect-stripper",
|
||||||
"description": "Strip tracking redirects on rfd",
|
"description": "Strip tracking redirects on rfd",
|
||||||
"version": "0.1",
|
"version": "0.2",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": ["*://forums.redflagdeals.com/*"],
|
"matches": ["*://forums.redflagdeals.com/*"],
|
||||||
@@ -15,14 +15,15 @@
|
|||||||
"default_popup": "html/popup.html"
|
"default_popup": "html/popup.html"
|
||||||
},
|
},
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": ["js/utils.js", "js/background.js"]
|
"scripts": [ "js/background.js" ],
|
||||||
|
"type": "module"
|
||||||
},
|
},
|
||||||
"permissions": ["scripting", "storage"],
|
"permissions": ["scripting", "storage", "alarms"],
|
||||||
"host_permissions": ["*://forums.redflagdeals.com/*"],
|
"host_permissions": ["*://forums.redflagdeals.com/*"],
|
||||||
"browser_specific_settings": {
|
"browser_specific_settings": {
|
||||||
"gecko": {
|
"gecko": {
|
||||||
"id": "davegallant@gmail.com",
|
"id": "davegallant@gmail.com",
|
||||||
"strict_min_version": "42.0"
|
"strict_min_version": "112.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user