mirror of
https://github.com/davegallant/rfd-redirect-stripper.git
synced 2025-08-06 08:43:40 +00:00
Add popup that allows modifying the config url
This commit is contained in:
@@ -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);
|
||||
|
@@ -11,7 +11,8 @@
|
||||
}
|
||||
],
|
||||
"action": {
|
||||
"default_icon": "icon.png"
|
||||
"default_icon": "icon.png",
|
||||
"default_popup": "popup.html"
|
||||
},
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
|
63
extensions/chrome/popup.css
Normal file
63
extensions/chrome/popup.css
Normal 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;
|
||||
}
|
||||
|
16
extensions/chrome/popup.html
Normal file
16
extensions/chrome/popup.html
Normal 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>
|
25
extensions/chrome/popup.js
Normal file
25
extensions/chrome/popup.js
Normal 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();
|
||||
});
|
22
extensions/chrome/utils.js
Normal file
22
extensions/chrome/utils.js
Normal 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",
|
||||
});
|
||||
}
|
@@ -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);
|
||||
|
@@ -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"]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@@ -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/*"]
|
||||
|
63
extensions/firefox/popup.css
Normal file
63
extensions/firefox/popup.css
Normal 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;
|
||||
}
|
||||
|
16
extensions/firefox/popup.html
Normal file
16
extensions/firefox/popup.html
Normal 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>
|
25
extensions/firefox/popup.js
Normal file
25
extensions/firefox/popup.js
Normal 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();
|
||||
});
|
22
extensions/firefox/utils.js
Normal file
22
extensions/firefox/utils.js
Normal 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",
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user