add option to disable vote submission

also change the icon of the extension when voting is disabled
popup.js, content-script, bg-script listenes to storage change event
so that they can all stay in sync without passing messages
icon_hold is addded
advanced setting is enabled in popup.html

add fallback for changing extension icon

refactor stateData
This commit is contained in:
himanshudabas committed 2021-12-19 05:05:00 +05:30
1 parent 96f063838d
commit 819c59c5b7
7 files changed
+170 -40

No files matched your search

+29 -1
View File
@@ -7,6 +7,16 @@ const LIKED_STATE = "LIKED_STATE";
const DISLIKED_STATE = "DISLIKED_STATE";
const NEUTRAL_STATE = "NEUTRAL_STATE";
let extConfig = {
disableVoteSubmission: false,
};
let storedData = {
likes: 0,
dislikes: 0,
previousState: NEUTRAL_STATE,
};
function isMobile() {
return location.hostname == "m.youtube.com";
}
@@ -97,13 +107,28 @@ function setState(storedData) {
);
}
function setInitialState(storedData) {
function setInitialState() {
setState(storedData);
setTimeout(() => {
sendVideoIds();
}, 1500);
}
function initExtConfig() {
initializeDisableVoteSubmission();
}
function initializeDisableVoteSubmission() {
getBrowser().storage.sync.get(['disableVoteSubmission'], (res) => {
if (res.disableVoteSubmission === undefined) {
getBrowser().storage.sync.set({disableVoteSubmission: false});
}
else {
extConfig.disableVoteSubmission = res.disableVoteSubmission;
}
});
}
export {
isMobile,
isVideoDisliked,
@@ -117,4 +142,7 @@ export {
LIKED_STATE,
DISLIKED_STATE,
NEUTRAL_STATE,
extConfig,
initExtConfig,
storedData,
};