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:
anonion
2024-01-01 13:56:55 -07:00
committed by GitHub
parent 5dde4528d5
commit 4511ad314f
7 changed files with 65 additions and 19 deletions

View File

@@ -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();
setDefaultConfig();
});
setInterval(updateRedirects, 1 * 60 * 60 * 1000);
chrome.runtime.onInstalled.addListener(() => {
setDefaultConfig();
updateRedirects();
setAlarm();
});
//Ensure alarm is created
chrome.runtime.onStartup.addListener(() => {
setAlarm();
});

View File

@@ -20,7 +20,7 @@ function stripRedirect(URL, redirectRegex) {
function stripRedirects() {
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) {
var ReferralURL = Link.href;
Link.href = stripRedirect(ReferralURL, result["redirects"]);

View File

@@ -1,3 +1,5 @@
import { updateRedirects, setDefaultConfig } from "../js/utils.js"
const inputField = document.getElementById("input-field");
const saveButton = document.getElementById("save-button");
const resetButton = document.getElementById("reset-button");
@@ -5,7 +7,7 @@ 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) => {
chrome.storage.local.get("config").then((result) => {
const value = result.config;
if (value) {
inputField.value = value;
@@ -14,7 +16,7 @@ browser.storage.local.get("config").then((result) => {
saveButton.addEventListener("click", () => {
const value = inputField.value;
browser.storage.local.set({ config: value });
chrome.storage.local.set({ config: value });
updateRedirects();
});

View File

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