mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-25 07:43:01 +01:00
Merge branch 'main' into extOptionFormatLikes
This commit is contained in:
24 files changed
+352
-52
No files matched your search
@@ -97,6 +97,36 @@ function getDislikeButton() {
|
||||
return getButtons().children[1];
|
||||
}
|
||||
|
||||
let mutationObserver = new Object();
|
||||
|
||||
if (isShorts() && mutationObserver.exists !== true) {
|
||||
cLog('initializing mutation observer')
|
||||
mutationObserver.options = {
|
||||
childList: false,
|
||||
attributes: true,
|
||||
subtree: false
|
||||
};
|
||||
mutationObserver.exists = true;
|
||||
mutationObserver.observer = new MutationObserver( function(mutationList, observer) {
|
||||
mutationList.forEach( (mutation) => {
|
||||
if (mutation.type === 'attributes' &&
|
||||
mutation.target.nodeName === 'TP-YT-PAPER-BUTTON' &&
|
||||
mutation.target.id === 'button') {
|
||||
cLog('Short thumb button status changed');
|
||||
if (mutation.target.getAttribute('aria-pressed') === 'true') {
|
||||
mutation.target.style.color =
|
||||
(mutation.target.parentElement.parentElement.id === 'like-button') ?
|
||||
getColorFromTheme(true) : getColorFromTheme(false);
|
||||
} else {
|
||||
mutation.target.style.color = 'unset';
|
||||
}
|
||||
return;
|
||||
}
|
||||
cLog('unexpected mutation observer event: ' + mutation.target + mutation.type);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function isVideoLiked() {
|
||||
if (isMobile) {
|
||||
return (
|
||||
@@ -303,8 +333,21 @@ function setState() {
|
||||
}
|
||||
createRateBar(likes, dislikes);
|
||||
if (extConfig.coloredThumbs === true) {
|
||||
getLikeButton().style.color = getColorFromTheme(true);
|
||||
getDislikeButton().style.color = getColorFromTheme(false);
|
||||
if (isShorts()) { // for shorts, leave deactived buttons in default color
|
||||
let shortLikeButton = getLikeButton().querySelector('tp-yt-paper-button#button');
|
||||
let shortDislikeButton = getDislikeButton().querySelector('tp-yt-paper-button#button');
|
||||
if (shortLikeButton.getAttribute('aria-pressed') === 'true') {
|
||||
shortLikeButton.style.color = getColorFromTheme(true);
|
||||
}
|
||||
if (shortDislikeButton.getAttribute('aria-pressed') === 'true') {
|
||||
shortDislikeButton.style.color = getColorFromTheme(false);
|
||||
}
|
||||
mutationObserver.observer.observe(shortLikeButton, mutationObserver.options);
|
||||
mutationObserver.observer.observe(shortDislikeButton, mutationObserver.options);
|
||||
} else {
|
||||
getLikeButton().style.color = getColorFromTheme(true);
|
||||
getDislikeButton().style.color = getColorFromTheme(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"extensionName": {
|
||||
"message": "Return YouTube Dislike"
|
||||
},
|
||||
"extensionDesc": {
|
||||
"message": "Macht Dislikes wieder sichtbar"
|
||||
},
|
||||
"textDeveloper": {
|
||||
"message": "von Dmitry Selivanov & Community"
|
||||
},
|
||||
"linkWebsite": {
|
||||
"message": "Website"
|
||||
},
|
||||
"linkFAQ": {
|
||||
"message": "FAQ"
|
||||
},
|
||||
"linkDonate": {
|
||||
"message": "Spenden"
|
||||
},
|
||||
"linkHelp": {
|
||||
"message": "Hilfe"
|
||||
},
|
||||
"legendSettings": {
|
||||
"message": "Einstellungen"
|
||||
},
|
||||
"textSettings": {
|
||||
"message": "Deaktiviere Like/Dislike-Übermittlung"
|
||||
},
|
||||
"textSettingsHover": {
|
||||
"message": "Stoppt deine Likes und Dislikes zu zählen."
|
||||
},
|
||||
"textUpdate": {
|
||||
"message": "aktualisieren auf"
|
||||
},
|
||||
"version30installed": {
|
||||
"message": "Version 4.0.0.0 installiert"
|
||||
},
|
||||
"whatsnew": {
|
||||
"message": "Was ist neu"
|
||||
},
|
||||
"shortsSupport": {
|
||||
"message": "YouTube Shorts Unterstützung"
|
||||
},
|
||||
"customColors": {
|
||||
"message": "Benutzerdefinierte Farben für Dislike-Leiste und Buttons"
|
||||
},
|
||||
"customNumberFormats": {
|
||||
"message": "Benutzerdefinierte Zahlenformate"
|
||||
}
|
||||
}
|
||||
@@ -26,9 +26,15 @@
|
||||
"textSettings": {
|
||||
"message": "Disable like/dislike submission"
|
||||
},
|
||||
"textLikesDisabled": {
|
||||
"message": "disabled by owner"
|
||||
},
|
||||
"textSettingsHover": {
|
||||
"message": "Stops counting your likes and dislikes."
|
||||
},
|
||||
"textTempUnavailable": {
|
||||
"message": "temporarily unavailable"
|
||||
},
|
||||
"textUpdate": {
|
||||
"message": "update to"
|
||||
},
|
||||
|
||||
@@ -23,12 +23,18 @@
|
||||
"legendSettings": {
|
||||
"message": "Paramètres"
|
||||
},
|
||||
"textLikesDisabled": {
|
||||
"message": "Désactivé par le créateur"
|
||||
},
|
||||
"textSettings": {
|
||||
"message": "Désactiver l'envoi des likes/dislikes"
|
||||
},
|
||||
"textSettingsHover": {
|
||||
"message": "Arrête de compter les likes et les dislikes mis sur les vidéos."
|
||||
},
|
||||
"textTempUnavailable": {
|
||||
"message": "temporairement indisponible"
|
||||
},
|
||||
"textUpdate": {
|
||||
"message": "mettre à jour vers"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"extensionName": {
|
||||
"message": "Επιστροφή του YouTube Dislike"
|
||||
},
|
||||
"extensionDesc": {
|
||||
"message": "Επιστρέφει τα dislikes"
|
||||
},
|
||||
"textDeveloper": {
|
||||
"message": "από τον Dmitry Selivanov & την κοινότητα"
|
||||
},
|
||||
"linkWebsite": {
|
||||
"message": "Ιστοσελίδα"
|
||||
},
|
||||
"linkFAQ": {
|
||||
"message": "Γρήγορες Ερωτήσιες & Απαντήσεις"
|
||||
},
|
||||
"linkDonate": {
|
||||
"message": "Στηρίξτε"
|
||||
},
|
||||
"linkHelp": {
|
||||
"message": "Βοήθεια"
|
||||
},
|
||||
"legendSettings": {
|
||||
"message": "Ρυθμίσεις"
|
||||
},
|
||||
"textSettings": {
|
||||
"message": "Διακοπή υποβολής like/dislike"
|
||||
},
|
||||
"textSettingsHover": {
|
||||
"message": "Σταματάει να μετράει τα likes & dislikes που κάνεις."
|
||||
},
|
||||
"textUpdate": {
|
||||
"message": "ενημέρωση σε"
|
||||
},
|
||||
"version30installed": {
|
||||
"message": "Εκδοση 4.0.0.0 εγκαταστάθηκε"
|
||||
},
|
||||
"whatsnew": {
|
||||
"message": "Τι είναι νέο;"
|
||||
},
|
||||
"shortsSupport": {
|
||||
"message": "Υποστήριξη για YouTube Shorts"
|
||||
},
|
||||
"customColors": {
|
||||
"message": "Προσαρμοζόμενα χρώματα για τα κουμπιά και την μπάρα dislike"
|
||||
},
|
||||
"customNumberFormats": {
|
||||
"message": "Προσαρμοζόμενη μορφή αριθμών."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"extensionName": {
|
||||
"message": "Return YouTube Dislike"
|
||||
},
|
||||
"extensionDesc": {
|
||||
"message": "Ripristina la possibilità di vedere i dislikes"
|
||||
},
|
||||
"textDeveloper": {
|
||||
"message": "di Dmitry Selivanov e la Community"
|
||||
},
|
||||
"linkWebsite": {
|
||||
"message": "Sito web"
|
||||
},
|
||||
"linkFAQ": {
|
||||
"message": "Domande frequenti"
|
||||
},
|
||||
"linkDonate": {
|
||||
"message": "Fai una donazione"
|
||||
},
|
||||
"linkHelp": {
|
||||
"message": "Aiuto"
|
||||
},
|
||||
"legendSettings": {
|
||||
"message": "Impostazioni"
|
||||
},
|
||||
"textSettings": {
|
||||
"message": "Disabilita l'invio di like/dislike"
|
||||
},
|
||||
"textSettingsHover": {
|
||||
"message": "Interrompe il conteggio dei tuoi likes e dislikes."
|
||||
},
|
||||
"textUpdate": {
|
||||
"message": "aggiorna a"
|
||||
},
|
||||
"version30installed": {
|
||||
"message": "Versione 4.0.0.0 installata"
|
||||
},
|
||||
"whatsnew": {
|
||||
"message": "Cosa c'è di nuovo"
|
||||
},
|
||||
"shortsSupport": {
|
||||
"message": "Supporto per YouTube Shorts"
|
||||
},
|
||||
"customColors": {
|
||||
"message": "Colori personalizzati per la barra dei dislike e i bottoni"
|
||||
},
|
||||
"customNumberFormats": {
|
||||
"message": "Formati numerici personalizzati"
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@
|
||||
"message": "Поддержка YouTube Shorts"
|
||||
},
|
||||
"customColors": {
|
||||
"message": "Выбор цветов дизлайк бара и кнопок"
|
||||
"message": "Выбор цветов панели дизлайков и кнопок"
|
||||
},
|
||||
"customNumberFormats": {
|
||||
"message": "Выбор формата чисел"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "__MSG_extensionName__",
|
||||
"description": "__MSG_extensionDesc__",
|
||||
"default_locale": "en",
|
||||
"version": "2.1.0.3",
|
||||
"version": "3.0.0.0",
|
||||
"manifest_version": 3,
|
||||
"background": {
|
||||
"service_worker": "ryd.background.js"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "__MSG_extensionName__",
|
||||
"description": "__MSG_extensionDesc__",
|
||||
"default_locale": "en",
|
||||
"version": "2.1.0.3",
|
||||
"version": "3.0.0.0",
|
||||
"manifest_version": 2,
|
||||
"background": {
|
||||
"scripts": ["ryd.background.js"]
|
||||
|
||||
@@ -73,12 +73,16 @@ api.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
}
|
||||
});
|
||||
|
||||
api.storage.sync.get(['newInstallation'], (result) => {
|
||||
if (result.newInstallation !== false) {
|
||||
api.tabs.create({url: api.runtime.getURL("/changelog/3/changelog_3.0.html")});
|
||||
api.storage.sync.get(['lastShowChangelogVersion'], (details) => {
|
||||
if (extConfig.showUpdatePopup === true &&
|
||||
details.lastShowChangelogVersion !== chrome.runtime.getManifest().version
|
||||
) {
|
||||
// keep it inside get to avoid race condition
|
||||
api.storage.sync.set({'lastShowChangelogVersion ': chrome.runtime.getManifest().version});
|
||||
// wait until async get runs & don't steal tab focus
|
||||
api.tabs.create({url: api.runtime.getURL("/changelog/3/changelog_3.0.html"), active: false});
|
||||
}
|
||||
});
|
||||
api.storage.sync.set({'newInstallation': false});
|
||||
|
||||
async function sendVote(videoId, vote) {
|
||||
api.storage.sync.get(null, async (storageResult) => {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { getButtons } from "./buttons";
|
||||
import { likesDisabledState, extConfig, isMobile } from "./state";
|
||||
import { extConfig, isMobile, isLikesDisabled } from "./state";
|
||||
import { cLog, getColorFromTheme } from "./utils";
|
||||
|
||||
function createRateBar(likes, dislikes) {
|
||||
if (!likesDisabledState) {
|
||||
if (!isLikesDisabled()) {
|
||||
let rateBar = document.getElementById("ryd-bar-container");
|
||||
|
||||
const widthPx =
|
||||
@@ -61,7 +62,9 @@ function createRateBar(likes, dislikes) {
|
||||
} else {
|
||||
cLog("removing bar");
|
||||
let ratebar = document.getElementById("ryd-bar-container");
|
||||
ratebar.parentNode.removeChild(ratebar);
|
||||
if(ratebar) {
|
||||
ratebar.parentNode.removeChild(ratebar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
getColorFromTheme,
|
||||
} from "./utils";
|
||||
import { sendVideoIds } from "./events";
|
||||
import { localize } from "./utils";
|
||||
|
||||
//TODO: Do not duplicate here and in ryd.background.js
|
||||
const apiUrl = "https://returnyoutubedislikeapi.com";
|
||||
@@ -15,8 +16,6 @@ const LIKED_STATE = "LIKED_STATE";
|
||||
const DISLIKED_STATE = "DISLIKED_STATE";
|
||||
const NEUTRAL_STATE = "NEUTRAL_STATE";
|
||||
|
||||
const DISLIKES_DISABLED_TEXT = "DISLIKES DISABLED";
|
||||
|
||||
let extConfig = {
|
||||
disableVoteSubmission: false,
|
||||
coloredThumbs: false,
|
||||
@@ -33,8 +32,6 @@ let storedData = {
|
||||
previousState: NEUTRAL_STATE,
|
||||
};
|
||||
|
||||
let likesDisabledState = true;
|
||||
|
||||
function isMobile() {
|
||||
return location.hostname == "m.youtube.com";
|
||||
}
|
||||
@@ -43,6 +40,46 @@ function isShorts() {
|
||||
return location.pathname.startsWith("/shorts");
|
||||
}
|
||||
|
||||
|
||||
let mutationObserver = new Object();
|
||||
|
||||
if (isShorts() && mutationObserver.exists !== true) {
|
||||
cLog('initializing mutation observer')
|
||||
mutationObserver.options = {
|
||||
childList: false,
|
||||
attributes: true,
|
||||
subtree: false
|
||||
};
|
||||
mutationObserver.exists = true;
|
||||
mutationObserver.observer = new MutationObserver( function(mutationList, observer) {
|
||||
mutationList.forEach( (mutation) => {
|
||||
if (mutation.type === 'attributes' &&
|
||||
mutation.target.nodeName === 'TP-YT-PAPER-BUTTON' &&
|
||||
mutation.target.id === 'button') {
|
||||
// cLog('Short thumb button status changed');
|
||||
if (mutation.target.getAttribute('aria-pressed') === 'true') {
|
||||
mutation.target.style.color =
|
||||
(mutation.target.parentElement.parentElement.id === 'like-button') ?
|
||||
getColorFromTheme(true) : getColorFromTheme(false);
|
||||
} else {
|
||||
mutation.target.style.color = 'unset';
|
||||
}
|
||||
return;
|
||||
}
|
||||
cLog('unexpected mutation observer event: ' + mutation.target + mutation.type);
|
||||
});
|
||||
});
|
||||
|
||||
function isLikesDisabled() {
|
||||
// return true if the like button's text doesn't contain any number
|
||||
if (isMobile()) {
|
||||
return /^\D*$/.test(
|
||||
getButtons().children[0].querySelector(".button-renderer-text").innerText
|
||||
);
|
||||
}
|
||||
return /^\D*$/.test(getButtons().children[0].querySelector("#text").innerText);
|
||||
}
|
||||
|
||||
function isVideoLiked() {
|
||||
if (isMobile()) {
|
||||
return (
|
||||
@@ -79,7 +116,7 @@ function setLikes(likesCount) {
|
||||
}
|
||||
|
||||
function setDislikes(dislikesCount) {
|
||||
if (!likesDisabledState) {
|
||||
if (!isLikesDisabled()) {
|
||||
if (isMobile()) {
|
||||
getButtons().children[1].querySelector(
|
||||
".button-renderer-text"
|
||||
@@ -92,11 +129,12 @@ function setDislikes(dislikesCount) {
|
||||
if (isMobile()) {
|
||||
getButtons().children[1].querySelector(
|
||||
".button-renderer-text"
|
||||
).innerText = DISLIKES_DISABLED_TEXT;
|
||||
).innerText = localize("TextLikesDisabled");
|
||||
return;
|
||||
}
|
||||
getButtons().children[1].querySelector("#text").innerText =
|
||||
DISLIKES_DISABLED_TEXT;
|
||||
getButtons().children[1].querySelector("#text").innerText = localize(
|
||||
"TextLikesDisabled"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,11 +164,31 @@ function processResponse(response, storedData) {
|
||||
storedData.likes = getLikeCountFromButton() || parseInt(response.likes);
|
||||
createRateBar(storedData.likes, storedData.dislikes);
|
||||
if (extConfig.coloredThumbs === true) {
|
||||
getLikeButton().style.color = getColorFromTheme(true);
|
||||
getDislikeButton().style.color = getColorFromTheme(false);
|
||||
if (isShorts()) { // for shorts, leave deactived buttons in default color
|
||||
let shortLikeButton = getLikeButton().querySelector('tp-yt-paper-button#button');
|
||||
let shortDislikeButton = getDislikeButton().querySelector('tp-yt-paper-button#button');
|
||||
if (shortLikeButton.getAttribute('aria-pressed') === 'true') {
|
||||
shortLikeButton.style.color = getColorFromTheme(true);
|
||||
}
|
||||
if (shortDislikeButton.getAttribute('aria-pressed') === 'true') {
|
||||
shortDislikeButton.style.color = getColorFromTheme(false);
|
||||
}
|
||||
mutationObserver.observer.observe(shortLikeButton, mutationObserver.options);
|
||||
mutationObserver.observer.observe(shortDislikeButton, mutationObserver.options);
|
||||
} else {
|
||||
getLikeButton().style.color = getColorFromTheme(true);
|
||||
getDislikeButton().style.color = getColorFromTheme(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tells the user if the API is down
|
||||
function displayError(error) {
|
||||
getButtons().children[1].querySelector("#text").innerText = localize(
|
||||
"textTempUnavailable"
|
||||
);
|
||||
}
|
||||
|
||||
async function setState(storedData) {
|
||||
storedData.previousState = isVideoDisliked()
|
||||
? DISLIKED_STATE
|
||||
@@ -151,14 +209,14 @@ async function setState(storedData) {
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
if (!response.ok) displayError(response.error);
|
||||
return response;
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.catch();
|
||||
.catch(displayError);
|
||||
cLog("response from api:");
|
||||
cLog(JSON.stringify(response));
|
||||
likesDisabledState =
|
||||
numberFormat(response.dislikes) == 0 &&
|
||||
numberFormat(response.likes) == 0 &&
|
||||
numberFormat(response.viewCount) == 0;
|
||||
if (response !== undefined && !("traceId" in response) && !statsSet) {
|
||||
processResponse(response, storedData);
|
||||
}
|
||||
@@ -268,5 +326,5 @@ export {
|
||||
extConfig,
|
||||
initExtConfig,
|
||||
storedData,
|
||||
likesDisabledState,
|
||||
isLikesDisabled
|
||||
};
|
||||
@@ -29,6 +29,10 @@ function numberFormat(numberState) {
|
||||
);
|
||||
}
|
||||
|
||||
function localize(localeString) {
|
||||
return chrome.i18n.getMessage(localeString);
|
||||
}
|
||||
|
||||
function getNumberFormatter(optionSelect) {
|
||||
let formatterNotation;
|
||||
let formatterCompactDisplay;
|
||||
@@ -151,4 +155,5 @@ export {
|
||||
isVideoLoaded,
|
||||
cLog,
|
||||
getColorFromTheme,
|
||||
localize,
|
||||
};
|
||||
Reference in new issue
Block a user