Add popup that allows modifying the config url

This commit is contained in:
Dave Gallant
2023-04-08 00:04:33 -04:00
parent 5a58a92460
commit c72db40f7d
13 changed files with 262 additions and 31 deletions

View File

@@ -1,18 +1,8 @@
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,
});
});
}
importScripts('utils.js');
chrome.runtime.onInstalled.addListener(() => {
updateRedirects();
setDefaultConfig();
});
setInterval(updateRedirects, 1 * 60 * 60 * 1000);

View File

@@ -11,7 +11,8 @@
}
],
"action": {
"default_icon": "icon.png"
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"background": {
"service_worker": "background.js"

View File

@@ -0,0 +1,63 @@
body {
background-color: #282828;
color: #ebdbb2;
font-family: "Font Name", sans-serif;
font-size: 16px;
}
input[type="text"] {
background-color: #3c3836;
color: #ebdbb2;
border: none;
border-radius: 3px;
padding: 5px;
margin-bottom: 10px;
font-size: 16px;
}
button#save-button {
background-color: #1e7325;
color: #ebdbb2;
border: none;
border-radius: 3px;
padding: 5px 10px;
font-size: 16px;
}
button#save-button:hover {
background-color: #83a598;
}
button#save-button:active {
transform: translateY(1px);
box-shadow: none;
}
button#save-button:disabled {
background-color: #a89984;
color: #928374;
}
button#reset-button {
background-color: #458588;
color: #ebdbb2;
border: none;
border-radius: 3px;
padding: 5px 10px;
font-size: 16px;
}
button#reset-button:hover {
background-color: #83a598;
}
button#reset-button:active {
transform: translateY(1px);
box-shadow: none;
}
button#reset-button:disabled {
background-color: #a89984;
color: #928374;
}

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>rfd-redirect-stripper</title>
<link rel="stylesheet" href="popup.css" />
<script src="utils.js"></script>
</head>
<body>
Config URL:
<input type="text" id="input-field" />
<button id="save-button">Save</button>
<button id="reset-button">Reset</button>
<script src="popup.js"></script>
</body>
</html>

View File

@@ -0,0 +1,25 @@
const inputField = document.getElementById("input-field");
const saveButton = document.getElementById("save-button");
const resetButton = document.getElementById("reset-button");
const defaultConfig =
"https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/redirects.json";
chrome.storage.local.get("config").then((result) => {
const value = result.config;
if (value) {
inputField.value = value;
}
});
saveButton.addEventListener("click", () => {
const value = inputField.value;
chrome.storage.local.set({ config: value });
updateRedirects();
});
resetButton.addEventListener("click", () => {
setDefaultConfig();
inputField.value = defaultConfig;
updateRedirects();
});

View File

@@ -0,0 +1,22 @@
function updateRedirects() {
chrome.storage.local.get("config", function (URL) {
fetch(URL.config)
.then((res) => res.json())
.then((res) => {
chrome.storage.local
.set({
redirects: res,
})
.catch((error) => {
console.log(error);
});
});
});
}
function setDefaultConfig() {
chrome.storage.local.set({
config:
"https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/redirects.json",
});
}

View File

@@ -1,18 +1,6 @@
function updateRedirects() {
var URL =
"https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/redirects.json";
fetch(URL)
.then((res) => res.json())
.then((res) => {
browser.storage.local.set({
"rfd-redirects": res,
});
});
}
chrome.runtime.onInstalled.addListener(() => {
updateRedirects();
setDefaultConfig();
});
setInterval(updateRedirects, 1 * 60 * 60 * 1000);

View File

@@ -20,11 +20,10 @@ function stripRedirect(URL, redirectRegex) {
function stripRedirects() {
var Links = document.querySelectorAll("a.postlink, a.autolinker_link");
browser.storage.local.get("rfd-redirects", function (redirectRegex) {
browser.storage.local.get("redirects", function (result) {
Links.forEach(function (Link) {
var ReferralURL = Link.href;
Link.href = stripRedirect(ReferralURL, redirectRegex["rfd-redirects"]);
Link.href = stripRedirect(ReferralURL, result["redirects"]);
});
});
}

View File

@@ -11,10 +11,11 @@
}
],
"action": {
"default_icon": "icon.png"
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"]
"scripts": ["utils.js", "background.js"]
},
"permissions": ["scripting", "storage"],
"host_permissions": ["*://forums.redflagdeals.com/*"]

View File

@@ -0,0 +1,63 @@
body {
background-color: #282828;
color: #ebdbb2;
font-family: "Font Name", sans-serif;
font-size: 16px;
}
input[type="text"] {
background-color: #3c3836;
color: #ebdbb2;
border: none;
border-radius: 3px;
padding: 5px;
margin-bottom: 10px;
font-size: 16px;
}
button#save-button {
background-color: #1e7325;
color: #ebdbb2;
border: none;
border-radius: 3px;
padding: 5px 10px;
font-size: 16px;
}
button#save-button:hover {
background-color: #83a598;
}
button#save-button:active {
transform: translateY(1px);
box-shadow: none;
}
button#save-button:disabled {
background-color: #a89984;
color: #928374;
}
button#reset-button {
background-color: #458588;
color: #ebdbb2;
border: none;
border-radius: 3px;
padding: 5px 10px;
font-size: 16px;
}
button#reset-button:hover {
background-color: #83a598;
}
button#reset-button:active {
transform: translateY(1px);
box-shadow: none;
}
button#reset-button:disabled {
background-color: #a89984;
color: #928374;
}

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>rfd-redirect-stripper</title>
<link rel="stylesheet" href="popup.css" />
<script src="utils.js"></script>
</head>
<body>
Config URL:
<input type="text" id="input-field" />
<button id="save-button">Save</button>
<button id="reset-button">Reset</button>
<script src="popup.js"></script>
</body>
</html>

View File

@@ -0,0 +1,25 @@
const inputField = document.getElementById("input-field");
const saveButton = document.getElementById("save-button");
const resetButton = document.getElementById("reset-button");
const defaultConfig =
"https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/redirects.json";
browser.storage.local.get("config").then((result) => {
const value = result.config;
if (value) {
inputField.value = value;
}
});
saveButton.addEventListener("click", () => {
const value = inputField.value;
browser.storage.local.set({ config: value });
updateRedirects();
});
resetButton.addEventListener("click", () => {
setDefaultConfig();
inputField.value = defaultConfig;
updateRedirects();
});

View File

@@ -0,0 +1,22 @@
function updateRedirects() {
browser.storage.local.get("config", function (URL) {
fetch(URL.config)
.then((res) => res.json())
.then((res) => {
browser.storage.local
.set({
redirects: res,
})
.catch((error) => {
console.log(error);
});
});
});
}
function setDefaultConfig() {
browser.storage.local.set({
config:
"https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/redirects.json",
});
}