mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-30 01:47:54 +01:00
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:
1 parent
96f063838d
commit
819c59c5b7
7 files changed
+170
-40
No files matched your search
@@ -1,14 +1,16 @@
|
||||
import { getBrowser, getVideoId, numberFormat } from "./utils"
|
||||
import { checkForSignInButton } from "./buttons"
|
||||
import { NEUTRAL_STATE, LIKED_STATE, DISLIKED_STATE, setDislikes } from "./state"
|
||||
import { getBrowser, getVideoId, numberFormat, cLog } from "./utils"
|
||||
import { checkForSignInButton, getButtons } from "./buttons"
|
||||
import { NEUTRAL_STATE, LIKED_STATE, DISLIKED_STATE, setDislikes, extConfig, storedData } from "./state"
|
||||
import { createRateBar } from "./bar"
|
||||
|
||||
function sendVote(vote) {
|
||||
getBrowser().runtime.sendMessage({
|
||||
message: "send_vote",
|
||||
vote: vote,
|
||||
videoId: getVideoId(window.location.href),
|
||||
});
|
||||
if (extConfig.disableVoteSubmission !== true) {
|
||||
getBrowser().runtime.sendMessage({
|
||||
message: "send_vote",
|
||||
vote: vote,
|
||||
videoId: getVideoId(window.location.href),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function sendVideoIds() {
|
||||
@@ -37,7 +39,7 @@ function sendVideoIds() {
|
||||
});
|
||||
}
|
||||
|
||||
function likeClicked(storedData) {
|
||||
function likeClicked() {
|
||||
if (checkForSignInButton() === false) {
|
||||
if (storedData.previousState === DISLIKED_STATE) {
|
||||
sendVote(1);
|
||||
@@ -60,7 +62,7 @@ function likeClicked(storedData) {
|
||||
}
|
||||
}
|
||||
|
||||
function dislikeClicked(storedData) {
|
||||
function dislikeClicked() {
|
||||
if (checkForSignInButton() == false) {
|
||||
if (storedData.previousState === NEUTRAL_STATE) {
|
||||
sendVote(-1);
|
||||
@@ -85,4 +87,30 @@ function dislikeClicked(storedData) {
|
||||
}
|
||||
}
|
||||
|
||||
export { sendVote, sendVideoIds, likeClicked, dislikeClicked }
|
||||
function addLikeDislikeEventListener() {
|
||||
const buttons = getButtons();
|
||||
if (!window.returnDislikeButtonlistenersSet) {
|
||||
buttons.children[0].addEventListener("click", likeClicked);
|
||||
buttons.children[1].addEventListener("click", dislikeClicked);
|
||||
window.returnDislikeButtonlistenersSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
function storageChangeHandler(changes, area) {
|
||||
if (changes.disableVoteSubmission !== undefined) {
|
||||
handleDisableVoteSubmissionChangeEvent(changes.disableVoteSubmission.newValue);
|
||||
}
|
||||
}
|
||||
|
||||
function handleDisableVoteSubmissionChangeEvent(value) {
|
||||
extConfig.disableVoteSubmission = value;
|
||||
}
|
||||
|
||||
export {
|
||||
sendVote,
|
||||
sendVideoIds,
|
||||
likeClicked,
|
||||
dislikeClicked,
|
||||
addLikeDislikeEventListener,
|
||||
storageChangeHandler,
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
Reference in new issue
Block a user