mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-02 02:41:22 +01:00
Prepare 4.0.5 Firefox update and Shorts fixes
Add Firefox data consent, repair contributor sign-in, and introduce optional Hide clutter buttons. Harden video navigation, voting, and action layouts with shared browser regression coverage and reproducible release packaging.
This commit is contained in:
1 parent
3657de9b2c
commit
e500088e65
196 files changed
+39706
-2694
No files matched your search
+135
-99
@@ -1,4 +1,11 @@
|
||||
import { config as appConfig, getApiUrl, getApiEndpoint } from "./src/config.js";
|
||||
import { getGitHubLoginErrorMessage } from "./src/github-login-error";
|
||||
import {
|
||||
hasAuthenticationDataPermission,
|
||||
onAuthenticationDataPermissionRemoved,
|
||||
requestAuthenticationDataPermission,
|
||||
usesFirefoxDataCollectionConsent,
|
||||
} from "./src/data-collection-permissions.js";
|
||||
|
||||
/* Config */
|
||||
const config = {
|
||||
@@ -13,6 +20,7 @@ const config = {
|
||||
tooltipPercentageMode: "dash_like",
|
||||
numberDisplayReformatLikes: false,
|
||||
hidePremiumTeaser: false,
|
||||
hideClutterButtons: false,
|
||||
showAdvancedMessage:
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor"><rect fill="none" height="24" width="24"/><path d="M19.5,12c0-0.23-0.01-0.45-0.03-0.68l1.86-1.41c0.4-0.3,0.51-0.86,0.26-1.3l-1.87-3.23c-0.25-0.44-0.79-0.62-1.25-0.42 l-2.15,0.91c-0.37-0.26-0.76-0.49-1.17-0.68l-0.29-2.31C14.8,2.38,14.37,2,13.87,2h-3.73C9.63,2,9.2,2.38,9.14,2.88L8.85,5.19 c-0.41,0.19-0.8,0.42-1.17,0.68L5.53,4.96c-0.46-0.2-1-0.02-1.25,0.42L2.41,8.62c-0.25,0.44-0.14,0.99,0.26,1.3l1.86,1.41 C4.51,11.55,4.5,11.77,4.5,12s0.01,0.45,0.03,0.68l-1.86,1.41c-0.4,0.3-0.51,0.86-0.26,1.3l1.87,3.23c0.25,0.44,0.79,0.62,1.25,0.42 l2.15-0.91c0.37,0.26,0.76,0.49,1.17,0.68l0.29,2.31C9.2,21.62,9.63,22,10.13,22h3.73c0.5,0,0.93-0.38,0.99-0.88l0.29-2.31 c0.41-0.19,0.8-0.42,1.17-0.68l2.15,0.91c0.46,0.2,1,0.02,1.25-0.42l1.87-3.23c0.25-0.44,0.14-0.99-0.26-1.3l-1.86-1.41 C19.49,12.45,19.5,12.23,19.5,12z M12.04,15.5c-1.93,0-3.5-1.57-3.5-3.5s1.57-3.5,3.5-3.5s3.5,1.57,3.5,3.5S13.97,15.5,12.04,15.5z"/></svg>',
|
||||
hideAdvancedMessage:
|
||||
@@ -95,6 +103,10 @@ document.getElementById("hide_premium_teaser").addEventListener("click", (ev) =>
|
||||
chrome.storage.sync.set({ hidePremiumTeaser: ev.target.checked });
|
||||
});
|
||||
|
||||
document.getElementById("hide_clutter_buttons").addEventListener("click", (ev) => {
|
||||
chrome.storage.sync.set({ hideClutterButtons: ev.target.checked });
|
||||
});
|
||||
|
||||
function initPatreonAuth() {
|
||||
const loggedOutView = document.getElementById("patreon-logged-out");
|
||||
const loggedInView = document.getElementById("patreon-logged-in");
|
||||
@@ -104,16 +116,30 @@ function initPatreonAuth() {
|
||||
const userAvatar = document.getElementById("patreon-user-avatar");
|
||||
const userName = document.getElementById("patreon-user-name");
|
||||
const userTier = document.getElementById("patreon-tier");
|
||||
let authenticationGeneration = 0;
|
||||
const initialGeneration = authenticationGeneration;
|
||||
|
||||
chrome.storage.sync.get(["patreonUser", "patreonSessionToken"], (data) => {
|
||||
chrome.storage.sync.get(["patreonUser", "patreonSessionToken"], async (data) => {
|
||||
if (initialGeneration !== authenticationGeneration) return;
|
||||
const cachedUser = data.patreonUser;
|
||||
const sessionToken = data.patreonSessionToken;
|
||||
|
||||
if (sessionToken && cachedUser) {
|
||||
const granted = await hasAuthenticationDataPermission();
|
||||
if (initialGeneration !== authenticationGeneration) return;
|
||||
if (!granted) {
|
||||
chrome.storage.sync.remove(["patreonAuthenticated", "patreonUser", "patreonSessionToken"]);
|
||||
showLoggedOutView();
|
||||
return;
|
||||
}
|
||||
|
||||
// Show cached state immediately to avoid flicker on popup reopen.
|
||||
showLoggedInView(cachedUser);
|
||||
|
||||
verifySession(sessionToken).then((result) => {
|
||||
verifySession(sessionToken, initialGeneration).then(async (result) => {
|
||||
if (initialGeneration !== authenticationGeneration) return;
|
||||
const stillGranted = await hasAuthenticationDataPermission();
|
||||
if (initialGeneration !== authenticationGeneration || !stillGranted) return;
|
||||
if (result.status === "valid") {
|
||||
if (result.membershipTier && result.membershipTier !== cachedUser.membershipTier) {
|
||||
const updatedUser = { ...cachedUser, membershipTier: result.membershipTier, hasActiveMembership: true };
|
||||
@@ -147,6 +173,10 @@ function initPatreonAuth() {
|
||||
function showLoggedOutView() {
|
||||
loggedOutView.style.display = "block";
|
||||
loggedInView.style.display = "none";
|
||||
userAvatar.removeAttribute("src");
|
||||
userAvatar.style.display = "none";
|
||||
userName.textContent = "";
|
||||
userTier.textContent = "";
|
||||
}
|
||||
|
||||
function showLoggedInView(user) {
|
||||
@@ -179,8 +209,12 @@ function initPatreonAuth() {
|
||||
}
|
||||
}
|
||||
|
||||
async function verifySession(token) {
|
||||
async function verifySession(token, generation) {
|
||||
try {
|
||||
if (!(await hasAuthenticationDataPermission()) || generation !== authenticationGeneration) {
|
||||
return { status: "consent_required" };
|
||||
}
|
||||
|
||||
const response = await fetch(getApiEndpoint("/api/auth/verify"), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -311,63 +345,108 @@ function initPatreonAuth() {
|
||||
}
|
||||
|
||||
loginBtn.addEventListener("click", () => {
|
||||
// Request permission immediately within this user gesture
|
||||
ensureIdentityPermission(async (granted) => {
|
||||
const identityNow = getIdentityApi();
|
||||
if (!granted || !identityNow || typeof identityNow.getRedirectURL !== "function") {
|
||||
const generation = ++authenticationGeneration;
|
||||
const continueLogin = (consentGranted) => {
|
||||
if (generation !== authenticationGeneration) return;
|
||||
if (!consentGranted) {
|
||||
alert(chrome.i18n.getMessage("patreonPermissionRequired"));
|
||||
return;
|
||||
}
|
||||
// Delegate OAuth to background so it persists if the popup closes
|
||||
chrome.runtime.sendMessage({ message: "patreon_oauth_login" }, (resp) => {
|
||||
if (chrome.runtime && chrome.runtime.lastError) {
|
||||
console.error("Login failed:", chrome.runtime.lastError.message);
|
||||
alert(chrome.i18n.getMessage("patreonLoginStartFailed"));
|
||||
return;
|
||||
}
|
||||
if (resp && resp.success) {
|
||||
const user = resp.user;
|
||||
showLoggedInView(user);
|
||||
} else {
|
||||
console.error("Login failed:", resp && resp.error);
|
||||
alert(chrome.i18n.getMessage("patreonLoginCompleteFailed"));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (githubLoginBtn) {
|
||||
githubLoginBtn.addEventListener("click", () => {
|
||||
ensureIdentityPermission(async (granted) => {
|
||||
ensureIdentityPermission((granted) => {
|
||||
if (generation !== authenticationGeneration) return;
|
||||
const identityNow = getIdentityApi();
|
||||
if (!granted || !identityNow || typeof identityNow.getRedirectURL !== "function") {
|
||||
alert(chrome.i18n.getMessage("patreonPermissionRequired"));
|
||||
return;
|
||||
}
|
||||
|
||||
chrome.runtime.sendMessage({ message: "github_oauth_login" }, (resp) => {
|
||||
// Delegate OAuth to background so it persists if the popup closes
|
||||
chrome.runtime.sendMessage({ message: "patreon_oauth_login" }, async (resp) => {
|
||||
if (generation !== authenticationGeneration) return;
|
||||
if (chrome.runtime && chrome.runtime.lastError) {
|
||||
console.error("GitHub login failed:", chrome.runtime.lastError.message);
|
||||
alert(chrome.i18n.getMessage("githubLoginStartFailed"));
|
||||
console.error("Login failed:", chrome.runtime.lastError.message);
|
||||
alert(chrome.i18n.getMessage("patreonLoginStartFailed"));
|
||||
return;
|
||||
}
|
||||
if (resp && resp.success) {
|
||||
const stillGranted = await hasAuthenticationDataPermission();
|
||||
if (generation !== authenticationGeneration || !stillGranted) return;
|
||||
const user = resp.user;
|
||||
showLoggedInView(user);
|
||||
} else {
|
||||
console.error("GitHub login failed:", resp && resp.error);
|
||||
alert(chrome.i18n.getMessage("githubLoginCompleteFailed"));
|
||||
console.error("Login failed:", resp && resp.error);
|
||||
alert(chrome.i18n.getMessage("patreonLoginCompleteFailed"));
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (!usesFirefoxDataCollectionConsent()) {
|
||||
continueLogin(true);
|
||||
return;
|
||||
}
|
||||
|
||||
requestAuthenticationDataPermission().then(continueLogin);
|
||||
});
|
||||
|
||||
if (githubLoginBtn) {
|
||||
githubLoginBtn.addEventListener("click", () => {
|
||||
const generation = ++authenticationGeneration;
|
||||
const continueLogin = (consentGranted) => {
|
||||
if (generation !== authenticationGeneration) return;
|
||||
if (!consentGranted) {
|
||||
alert(chrome.i18n.getMessage("patreonPermissionRequired"));
|
||||
return;
|
||||
}
|
||||
|
||||
ensureIdentityPermission((granted) => {
|
||||
if (generation !== authenticationGeneration) return;
|
||||
const identityNow = getIdentityApi();
|
||||
if (!granted || !identityNow || typeof identityNow.getRedirectURL !== "function") {
|
||||
alert(chrome.i18n.getMessage("patreonPermissionRequired"));
|
||||
return;
|
||||
}
|
||||
|
||||
chrome.runtime.sendMessage({ message: "github_oauth_login" }, async (resp) => {
|
||||
if (generation !== authenticationGeneration) return;
|
||||
if (chrome.runtime && chrome.runtime.lastError) {
|
||||
console.error("GitHub login failed:", chrome.runtime.lastError.message);
|
||||
alert(chrome.i18n.getMessage("githubLoginStartFailed"));
|
||||
return;
|
||||
}
|
||||
if (resp && resp.success) {
|
||||
const stillGranted = await hasAuthenticationDataPermission();
|
||||
if (generation !== authenticationGeneration || !stillGranted) return;
|
||||
const user = resp.user;
|
||||
showLoggedInView(user);
|
||||
} else {
|
||||
console.error("GitHub login failed:", resp && resp.error);
|
||||
alert(getGitHubLoginErrorMessage(resp?.error, (key) => chrome.i18n.getMessage(key)));
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (!usesFirefoxDataCollectionConsent()) {
|
||||
continueLogin(true);
|
||||
return;
|
||||
}
|
||||
|
||||
requestAuthenticationDataPermission().then(continueLogin);
|
||||
});
|
||||
}
|
||||
|
||||
onAuthenticationDataPermissionRemoved(() => {
|
||||
authenticationGeneration++;
|
||||
chrome.storage.sync.remove(["patreonAuthenticated", "patreonUser", "patreonSessionToken"]);
|
||||
showLoggedOutView();
|
||||
});
|
||||
|
||||
logoutBtn.addEventListener("click", () => {
|
||||
chrome.storage.sync.remove(["patreonUser", "patreonSessionToken"], () => {
|
||||
showLoggedOutView();
|
||||
chrome.runtime.sendMessage({ message: "patreon_logout" });
|
||||
});
|
||||
authenticationGeneration++;
|
||||
showLoggedOutView();
|
||||
chrome.storage.sync.remove(["patreonAuthenticated", "patreonUser", "patreonSessionToken"]);
|
||||
chrome.runtime.sendMessage({ message: "patreon_logout" });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -405,43 +484,12 @@ function initConfig() {
|
||||
initializeTooltipPercentageMode();
|
||||
initializeNumberDisplayReformatLikes();
|
||||
initializeHidePremiumTeaser();
|
||||
initializeHideClutterButtons();
|
||||
}
|
||||
|
||||
function initializeVersionNumber() {
|
||||
const version = chrome.runtime.getManifest().version;
|
||||
document.getElementById("ext-version").innerHTML = "v" + version;
|
||||
|
||||
fetch(
|
||||
"https://raw.githubusercontent.com/Anarios/return-youtube-dislike/main/Extensions/combined/manifest-chrome.json",
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
if (compareVersions(json.version, version)) {
|
||||
document.getElementById("ext-update").innerHTML = chrome.i18n.getMessage("textUpdate") + " v" + json.version;
|
||||
document.getElementById("ext-update").style.padding = ".25rem .5rem";
|
||||
}
|
||||
});
|
||||
// .catch(console.error);
|
||||
}
|
||||
|
||||
// returns whether current < latest
|
||||
function compareVersions(latestStr, currentStr) {
|
||||
let latestarr = latestStr.split(".");
|
||||
let currentarr = currentStr.split(".");
|
||||
let outdated = false;
|
||||
// goes through version numbers from left to right from greatest to least significant
|
||||
for (let i = 0; i < Math.max(latestarr.length, currentarr.length); i++) {
|
||||
let latest = i < latestarr.length ? parseInt(latestarr[i]) : 0;
|
||||
let current = i < currentarr.length ? parseInt(currentarr[i]) : 0;
|
||||
if (latest > current) {
|
||||
outdated = true;
|
||||
break;
|
||||
} else if (latest < current) {
|
||||
outdated = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return outdated;
|
||||
}
|
||||
|
||||
function initializeDisableVoteSubmission() {
|
||||
@@ -513,6 +561,15 @@ function initializeHidePremiumTeaser() {
|
||||
});
|
||||
}
|
||||
|
||||
function initializeHideClutterButtons() {
|
||||
chrome.storage.sync.get(["hideClutterButtons"], (res) => {
|
||||
if (res.hideClutterButtons === undefined) {
|
||||
chrome.storage.sync.set({ hideClutterButtons: false });
|
||||
}
|
||||
handleHideClutterButtonsChangeEvent(res.hideClutterButtons);
|
||||
});
|
||||
}
|
||||
|
||||
chrome.storage.onChanged.addListener(storageChangeHandler);
|
||||
|
||||
function storageChangeHandler(changes, area) {
|
||||
@@ -543,6 +600,9 @@ function storageChangeHandler(changes, area) {
|
||||
if (changes.hidePremiumTeaser !== undefined) {
|
||||
handleHidePremiumTeaserChangeEvent(changes.hidePremiumTeaser.newValue);
|
||||
}
|
||||
if (changes.hideClutterButtons !== undefined) {
|
||||
handleHideClutterButtonsChangeEvent(changes.hideClutterButtons.newValue);
|
||||
}
|
||||
}
|
||||
|
||||
function handleDisableVoteSubmissionChangeEvent(value) {
|
||||
@@ -609,6 +669,12 @@ function handleHidePremiumTeaserChangeEvent(value) {
|
||||
document.getElementById("hide_premium_teaser").checked = normalized;
|
||||
}
|
||||
|
||||
function handleHideClutterButtonsChangeEvent(value) {
|
||||
const normalized = value === true;
|
||||
config.hideClutterButtons = normalized;
|
||||
document.getElementById("hide_clutter_buttons").checked = normalized;
|
||||
}
|
||||
|
||||
function getNumberFormatter(optionSelect) {
|
||||
let formatterNotation;
|
||||
let formatterCompactDisplay;
|
||||
@@ -642,24 +708,6 @@ function getNumberFormatter(optionSelect) {
|
||||
return formatter;
|
||||
}
|
||||
|
||||
(async function getStatus() {
|
||||
let status = document.getElementById("status");
|
||||
let serverStatus = document.getElementById("server-status");
|
||||
let resp = await fetch("https://returnyoutubedislikeapi.com/votes?videoId=YbJOTdZBX1g");
|
||||
let result = await resp.status;
|
||||
if (result === 200) {
|
||||
status.innerText = chrome.i18n.getMessage("apiStatusOnline");
|
||||
status.style.color = "green";
|
||||
serverStatus.style.filter =
|
||||
"invert(58%) sepia(81%) saturate(2618%) hue-rotate(81deg) brightness(119%) contrast(129%)";
|
||||
} else {
|
||||
status.innerText = chrome.i18n.getMessage("apiStatusOffline");
|
||||
status.style.color = "red";
|
||||
serverStatus.style.filter =
|
||||
"invert(11%) sepia(100%) saturate(6449%) hue-rotate(3deg) brightness(116%) contrast(115%)";
|
||||
}
|
||||
})();
|
||||
|
||||
function getColorFromTheme(colorTheme, voteIsLike) {
|
||||
let colorString;
|
||||
switch (colorTheme) {
|
||||
@@ -687,15 +735,3 @@ function getColorFromTheme(colorTheme, voteIsLike) {
|
||||
}
|
||||
return colorString;
|
||||
}
|
||||
|
||||
/* popup-script.js
|
||||
document.querySelector('#login')
|
||||
.addEventListener('click', function () {
|
||||
chrome.runtime.sendMessage({ message: 'get_auth_token' });
|
||||
});
|
||||
|
||||
|
||||
document.querySelector("#log_off").addEventListener("click", function () {
|
||||
chrome.runtime.sendMessage({ message: "log_off" });
|
||||
});
|
||||
*/
|
||||
Reference in new issue
Block a user