Compare commits

...

3 commits

Author SHA1 Message Date
Juhani Krekelä
c59a28c126 Log errors 2024-07-25 17:15:54 +03:00
Juhani Krekelä
b2390e5b54 Don't add redirects if instance domain is unset 2024-07-24 22:30:52 +03:00
Juhani Krekelä
d486e5a637 Add .gitignore 2024-07-24 22:27:32 +03:00
2 changed files with 17 additions and 5 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.zip
*.xpi

View file

@ -3,6 +3,13 @@ if (window.browser === undefined) {
window.browser = window.chrome;
}
function errorLogger(action) {
function log(error) {
console.log(`Error: ${action}:`, error);
}
return log;
}
function createRedirect(id, from, transform) {
return {
id: id,
@ -28,11 +35,11 @@ function updateRedirects(settings) {
transform.password = settings.password;
}
const redirects = [];
if (settings.enabled) {
if (settings.enabled && settings.instance !== '') {
redirects.push(createRedirect(1, '||twitter.com', transform));
redirects.push(createRedirect(2, '||x.com', transform));
}
browser.declarativeNetRequest.updateDynamicRules({
return browser.declarativeNetRequest.updateDynamicRules({
addRules: redirects,
removeRuleIds: [1, 2],
});
@ -55,8 +62,11 @@ function setupSettingsForm(settings) {
settings.instance = instance.value;
settings.username = username.value;
settings.password = password.value;
browser.storage.local.set(settings);
updateRedirects(settings);
browser.storage.local.set(settings)
.then(
() => updateRedirects(settings),
errorLogger('browser.storage.local.set')
).catch(errorLogger('updateRedirects'));
});
}
}
@ -66,4 +76,4 @@ browser.storage.local.get({
instance: '',
username: '',
password: '',
}).then(setupSettingsForm);
}).then(setupSettingsForm, errorLogger('browser.storage.local.get'));