Removed invidious cookies as it's not working

This commit is contained in:
ManeraKai 2022-03-01 20:53:45 +03:00
parent c8fe9e2838
commit 082016dcde
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
7 changed files with 70 additions and 44 deletions

View File

@ -0,0 +1,51 @@
window.browser = window.browser || window.chrome;
function getCookie() {
for (const c of document.cookie.split(";")) {
while (c.charAt(0) == " ") c = c.substring(1, c.length);
if (c.indexOf("PREFS=") == 0)
return JSON.parse(
decodeURIComponent(c.substring("PREFS=".length, c.length))
);
}
return {};
}
browser.storage.local.get(
[
"invidiousAlwaysProxy",
"invidiousSubtitles",
"invidiousPlayerStyle",
"youtubeVolume",
"youtubeAutoplay",
"OnlyEmbeddedVideo",
"youtubeTheme",
"invidiousVideoQuality",
], (result) => {
let prefs = getCookie();
let oldPrefs = { ...prefs };
if (result.invidiousAlwaysProxy !== undefined && prefs.local !== result.invidiousAlwaysProxy)
prefs.local = result.invidiousAlwaysProxy;
if (result.invidiousVideoQuality !== undefined && prefs.quality !== result.invidiousVideoQuality)
prefs.quality = result.invidiousVideoQuality;
if (result.youtubeTheme !== undefined && prefs.dark_mode !== result.youtubeTheme)
prefs.dark_mode = result.youtubeTheme;
if (result.youtubeVolume !== undefined && prefs.volume !== result.youtubeVolume)
prefs.volume = result.youtubeVolume;
if (result.invidiousPlayerStyle !== undefined && prefs.player_style !== result.invidiousPlayerStyle)
prefs.player_style = result.invidiousPlayerStyle;
if (result.invidiousSubtitles !== undefined && prefs.subtitles === result.invidiousSubtitles)
prefs.subtitles = result.invidiousSubtitles;
if (result.youtubeAutoplay !== undefined && prefs.autoplay !== result.youtubeAutoplay)
prefs.autoplay = result.youtubeAutoplay;
if (prefs != oldPrefs) document.cookie = `PREFS=${encodeURIComponent(JSON.stringify(prefs))}`;
}
)

View File

@ -564,7 +564,7 @@ function addUrlParams(url) {
else return;
}
function initPipedLocalStorage(url, tabId) {
function initPipedLocalStorage(tabId) {
browser.tabs.executeScript(
tabId,
{
@ -574,37 +574,12 @@ function initPipedLocalStorage(url, tabId) {
);
}
function invidiousInitCookies(url) {
console.log("invidiousInitCookies");
browser.cookies.get({
url: url,
name: "PREFS"
}).then(
cookie => {
let prefs = {};
if (cookie) prefs = JSON.parse(decodeURIComponent(cookie.value));
let oldPrefs = { ...prefs };
if (invidiousAlwaysProxy != "DEFAULT" && prefs.local !== invidiousAlwaysProxy) prefs.local = invidiousAlwaysProxy;
if (invidiousVideoQuality != "DEFAULT" && prefs.quality !== invidiousVideoQuality) prefs.quality = invidiousVideoQuality;
if (theme != "DEFAULT" && prefs.dark_mode !== theme) prefs.dark_mode = theme;
if (volume != "--" && prefs.volume !== volume) prefs.volume = volume;
if (invidiousPlayerStyle != "DEFAULT" && prefs.player_style !== invidiousPlayerStyle) prefs.player_style = invidiousPlayerStyle;
if (invidiousSubtitles != "DEFAULT" && prefs.subtitles === invidiousSubtitles) prefs.subtitles = invidiousSubtitles;
if (autoplay != "DEFAULT" && prefs.autoplay !== autoplay) prefs.autoplay = autoplay;
if (oldPrefs != prefs)
browser.cookies.set({
url: url,
name: "PREFS",
value: encodeURIComponent(JSON.stringify(prefs))
})
function initInvidiousCookies(tabId) {
browser.tabs.executeScript(
tabId,
{
file: "/assets/javascripts/helpers/youtube/invidious-preferences.js",
runAt: "document_start"
}
);
}
@ -695,7 +670,7 @@ async function init() {
export default {
getBypassWatchOnYoutube,
setBypassWatchOnYoutube,
invidiousInitCookies,
initInvidiousCookies,
initPipedLocalStorage,
getFrontend,

View File

@ -16,9 +16,9 @@
},
"permissions": [
"storage",
"cookies",
"webRequest",
"webRequestBlocking",
"cookies",
"<all_urls>"
],
"browser_action": {

View File

@ -50,6 +50,7 @@ browser.webRequest.onBeforeRequest.addListener(
var newUrl;
if (!newUrl) newUrl = youtubeHelper.redirect(url, details, initiator)
if (youtubeHelper.isPipedorInvidious(newUrl ?? url, details.type)) newUrl = youtubeHelper.addUrlParams(newUrl ?? url);
if (youtubeMusicHelper.isYoutubeMusic(url, initiator)) newUrl = youtubeMusicHelper.redirect(url, details.type)
if (twitterHelper.isTwitter(url, initiator)) newUrl = twitterHelper.redirect(url);
@ -106,6 +107,6 @@ browser.tabs.onRemoved.addListener((tabId) => {
browser.tabs.onUpdated.addListener(
(tabId, changeInfo, _) => {
if (changeInfo.url && youtubeHelper.isUrlPipedorInvidious(changeInfo.url, 'piped')) youtubeHelper.initPipedLocalStorage(changeInfo.url, tabId);
if (changeInfo.url && youtubeHelper.isUrlPipedorInvidious(changeInfo.url, 'invidious')) youtubeHelper.invidiousInitCookies(changeInfo.url);
if (changeInfo.url && youtubeHelper.isUrlPipedorInvidious(changeInfo.url, 'piped')) youtubeHelper.initPipedLocalStorage(tabId);
// if (changeInfo.url && youtubeHelper.isUrlPipedorInvidious(changeInfo.url, 'invidious')) youtubeHelper.initInvidiousCookies(tabId);
});

View File

@ -21,10 +21,10 @@ invidiousSubtitlesElement.addEventListener("change",
() => youtubeHelper.setInvidiousSubtitles(invidiousSubtitlesElement.value)
);
let persistInvidiousPrefsElement = document.getElementById("persist-invidious-prefs");
persistInvidiousPrefsElement.addEventListener("change",
(event) => youtubeHelper.setPersistInvidiousPrefs(event.target.checked)
);
// let persistInvidiousPrefsElement = document.getElementById("persist-invidious-prefs");
// persistInvidiousPrefsElement.addEventListener("change",
// (event) => youtubeHelper.setPersistInvidiousPrefs(event.target.checked)
// );
youtubeHelper.init().then(() => {
@ -33,7 +33,7 @@ youtubeHelper.init().then(() => {
console.log("youtubeHelper.getInvidiousAlwaysProxy()", youtubeHelper.getInvidiousAlwaysProxy())
invidiousVideoQualityElement.value = youtubeHelper.getInvidiousVideoQuality();
invidiousSubtitlesElement.value = youtubeHelper.getInvidiousSubtitles();
persistInvidiousPrefsElement.checked = youtubeHelper.getPersistInvidiousPrefs();
// persistInvidiousPrefsElement.checked = youtubeHelper.getPersistInvidiousPrefs();
commonHelper.processDefaultCustomInstances(
'invidious',

View File

@ -212,14 +212,13 @@
<input id="invidious-subtitles" placeholder="en, ar, es" type="text" />
</div>
<div class="some-block option-block">
<!-- <div class="some-block option-block">
<h4>Persist preferences (as cookie)</h4>
<input id="persist-invidious-prefs" type="checkbox" checked />
</div>
</div> -->
<hr>
<div id="invidious-normal">
<div class="some-block option-block">
<h4>Default Instances</h4>

Binary file not shown.