Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hrai committed Oct 15, 2024
1 parent f1bcf50 commit 433149e
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ console.log(errorMsg);

browser.storage.local
.get([constantsKeyVal, namesKeyVal, acronymsKeyVal, locationsKeyVal])
.then(() => {
.then((localDict) => {
browser.storage.sync
.get([
sitesToIgnore,
Expand All @@ -34,9 +34,47 @@ browser.storage.local
wordsToExclude,
wordsToInclude,
])
.then(processResponse, utils.onError);
.then((remoteDict) => {
processResponse({ ...localDict, ...remoteDict });
}, utils.onError);
}, utils.onError);

function processResponse(item) {
if (item.sitesToIgnore) {
sitesToExclude = sitesToExclude.concat(item.sitesToIgnore);
}

setOptions(item);
setKeyValues(item);

if (item && sitesToExclude) {
//https://stackoverflow.com/questions/406192/get-current-url-with-jquery
var currentUrlDomain = window.location.origin;

try {
var shouldEnableCapitalisingOnCurrentSite = true;

$.each(sitesToExclude, function (_i, siteToExclude) {
if (currentUrlDomain.includes(siteToExclude)) {
shouldEnableCapitalisingOnCurrentSite = false;
}
});

if (shouldEnableCapitalisingOnCurrentSite) {
hookupEventHandlers();

throw new Error(errorMsg);
}
} catch (e) {
if (e.message !== errorMsg) {
throw e;
}
}
} else {
hookupEventHandlers();
}
}

/* Updating the value of this sync storage variable in settings.js happens AFTER content.js.
* The browser doesn't register the change and doesn't capitalise I by default after installing the extension.
* This block will capture the event and update the value of 'shouldCapitaliseI'.
Expand Down Expand Up @@ -119,42 +157,6 @@ function setKeyValues(item) {
utils.setWordsToExclude(item.wordsToExclude);
}

function processResponse(item) {
if (item.sitesToIgnore) {
sitesToExclude = sitesToExclude.concat(item.sitesToIgnore);
}

setOptions(item);
setKeyValues(item);

if (item && sitesToExclude) {
//https://stackoverflow.com/questions/406192/get-current-url-with-jquery
var currentUrlDomain = window.location.origin;

try {
var shouldEnableCapitalisingOnCurrentSite = true;

$.each(sitesToExclude, function (_i, siteToExclude) {
if (currentUrlDomain.includes(siteToExclude)) {
shouldEnableCapitalisingOnCurrentSite = false;
}
});

if (shouldEnableCapitalisingOnCurrentSite) {
hookupEventHandlers();

throw new Error(errorMsg);
}
} catch (e) {
if (e.message !== errorMsg) {
throw e;
}
}
} else {
hookupEventHandlers();
}
}

/*eslint no-debugger: "error"*/
function observeHtmlBody() {
var target = document.querySelector('body');
Expand Down

0 comments on commit 433149e

Please sign in to comment.