mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-02 10:52:20 +01:00
refactor: extract hardcoded values to const
This commit is contained in:
1 parent
c1a12b0bf7
commit
599f35a185
3 files changed
+33
-21
No files matched your search
@@ -19,6 +19,10 @@
|
|||||||
// @grant GM_addStyle
|
// @grant GM_addStyle
|
||||||
// @run-at document-end
|
// @run-at document-end
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
const LIKED_STATE = "LIKED_STATE";
|
||||||
|
const DISLIKED_STATE = "DISLIKED_STATE";
|
||||||
|
const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||||
|
|
||||||
function cLog(text, subtext = '') {
|
function cLog(text, subtext = '') {
|
||||||
subtext = subtext.trim() === '' ? '' : `(${subtext})`;
|
subtext = subtext.trim() === '' ? '' : `(${subtext})`;
|
||||||
console.log(`[Return YouTube Dislikes] ${text} ${subtext}`);
|
console.log(`[Return YouTube Dislikes] ${text} ${subtext}`);
|
||||||
@@ -60,12 +64,12 @@ function isVideoNotDisliked() {
|
|||||||
|
|
||||||
function getState() {
|
function getState() {
|
||||||
if (isVideoLiked()) {
|
if (isVideoLiked()) {
|
||||||
return "liked";
|
return LIKED_STATE;
|
||||||
}
|
}
|
||||||
if (isVideoDisliked()) {
|
if (isVideoDisliked()) {
|
||||||
return "disliked";
|
return DISLIKED_STATE;
|
||||||
}
|
}
|
||||||
return "neutral";
|
return NEUTRAL_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLikes(likesCount) {
|
function setLikes(likesCount) {
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
const LIKED_STATE = "LIKED_STATE";
|
||||||
|
const DISLIKED_STATE = "DISLIKED_STATE";
|
||||||
|
const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||||
|
|
||||||
(function (extensionId) {
|
(function (extensionId) {
|
||||||
let storedData = {
|
let storedData = {
|
||||||
dislikes: 0,
|
dislikes: 0,
|
||||||
previousState: 'neutral'
|
previousState: NEUTRAL_STATE
|
||||||
};
|
};
|
||||||
|
|
||||||
function cLog(message, writer) {
|
function cLog(message, writer) {
|
||||||
@@ -54,12 +58,12 @@
|
|||||||
|
|
||||||
function getState() {
|
function getState() {
|
||||||
if (isVideoLiked()) {
|
if (isVideoLiked()) {
|
||||||
return {current: "liked", previous: storedData.previousState};
|
return {current: LIKED_STATE, previous: storedData.previousState};
|
||||||
}
|
}
|
||||||
if (isVideoDisliked()) {
|
if (isVideoDisliked()) {
|
||||||
return {current: "disliked", previous: storedData.previousState};
|
return {current: DISLIKED_STATE, previous: storedData.previousState};
|
||||||
}
|
}
|
||||||
return {current: "neutral", previous: storedData.previousState};
|
return {current: NEUTRAL_STATE, previous: storedData.previousState};
|
||||||
}
|
}
|
||||||
|
|
||||||
//--- Sets The Likes And Dislikes Values ---//
|
//--- Sets The Likes And Dislikes Values ---//
|
||||||
@@ -122,10 +126,10 @@
|
|||||||
|
|
||||||
function likeClicked() {
|
function likeClicked() {
|
||||||
console.log(storedData.previousState)
|
console.log(storedData.previousState)
|
||||||
if (storedData.previousState == 'disliked') {
|
if (storedData.previousState == DISLIKED_STATE) {
|
||||||
storedData.dislikes--;
|
storedData.dislikes--;
|
||||||
setDislikes(numberFormat(storedData.dislikes));
|
setDislikes(numberFormat(storedData.dislikes));
|
||||||
storedData.previousState = 'liked';
|
storedData.previousState = LIKED_STATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,14 +138,14 @@
|
|||||||
|
|
||||||
console.log("Dislike State:",getState());
|
console.log("Dislike State:",getState());
|
||||||
|
|
||||||
if (state == 'disliked') {
|
if (state == DISLIKED_STATE) {
|
||||||
storedData.dislikes++;
|
storedData.dislikes++;
|
||||||
setDislikes(numberFormat(storedData.dislikes));
|
setDislikes(numberFormat(storedData.dislikes));
|
||||||
storedData.previousState = 'disliked';
|
storedData.previousState = DISLIKED_STATE;
|
||||||
} else if (state == 'neutral') {
|
} else if (state == NEUTRAL_STATE) {
|
||||||
storedData.dislikes--;
|
storedData.dislikes--;
|
||||||
setDislikes(numberFormat(storedData.dislikes));
|
setDislikes(numberFormat(storedData.dislikes));
|
||||||
storedData.previousState = 'neutral';
|
storedData.previousState = NEUTRAL_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setState();
|
// setState();
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
const LIKED_STATE = "LIKED_STATE";
|
||||||
|
const DISLIKED_STATE = "DISLIKED_STATE";
|
||||||
|
const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||||
|
|
||||||
if (!storedData) {
|
if (!storedData) {
|
||||||
var storedData = {
|
var storedData = {
|
||||||
dislikes: 0,
|
dislikes: 0,
|
||||||
previousState: 'neutral'
|
previousState: NEUTRAL_STATE
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,12 +56,12 @@ function isVideoNotDisliked() {
|
|||||||
|
|
||||||
function getState() {
|
function getState() {
|
||||||
if (isVideoLiked()) {
|
if (isVideoLiked()) {
|
||||||
return {current: "liked", previous: storedData.previousState};
|
return {current: LIKED_STATE, previous: storedData.previousState};
|
||||||
}
|
}
|
||||||
if (isVideoDisliked()) {
|
if (isVideoDisliked()) {
|
||||||
return {current: "disliked", previous: storedData.previousState};
|
return {current: DISLIKED_STATE, previous: storedData.previousState};
|
||||||
}
|
}
|
||||||
return {current: "neutral", previous: storedData.previousState};
|
return {current: NEUTRAL_STATE, previous: storedData.previousState};
|
||||||
}
|
}
|
||||||
|
|
||||||
//--- Sets The Likes And Dislikes Values ---//
|
//--- Sets The Likes And Dislikes Values ---//
|
||||||
@@ -120,14 +124,14 @@ function likeClicked() {}
|
|||||||
|
|
||||||
function dislikeClicked() {
|
function dislikeClicked() {
|
||||||
let state = getState().current;
|
let state = getState().current;
|
||||||
if (state == "disliked") {
|
if (state == DISLIKED_STATE) {
|
||||||
storedData.dislikes++;
|
storedData.dislikes++;
|
||||||
setDislikes(numberFormat(storedData.dislikes));
|
setDislikes(numberFormat(storedData.dislikes));
|
||||||
storedData.previousState = 'disliked';
|
storedData.previousState = DISLIKED_STATE;
|
||||||
} else if (state == "neutral") {
|
} else if (state == NEUTRAL_STATE) {
|
||||||
storedData.dislikes--;
|
storedData.dislikes--;
|
||||||
setDislikes(numberFormat(storedData.dislikes));
|
setDislikes(numberFormat(storedData.dislikes));
|
||||||
storedData.previousState = 'neutral';
|
storedData.previousState = NEUTRAL_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setState();
|
// setState();
|
||||||
|
|||||||
Reference in new issue
Block a user