privacy-redirect/src/assets/javascripts/persist-invidious-prefs.js

31 lines
831 B
JavaScript
Raw Normal View History

2021-04-16 02:45:15 +02:00
"use strict";
window.browser = window.browser || window.chrome;
function getCookie() {
2021-04-16 02:45:15 +02:00
let ca = document.cookie.split(";");
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
2021-04-16 02:45:15 +02:00
while (c.charAt(0) == " ") c = c.substring(1, c.length);
if (c.indexOf("PREFS=") == 0) {
return JSON.parse(
2021-04-16 02:45:15 +02:00
decodeURIComponent(c.substring("PREFS=".length, c.length))
);
}
}
return {};
}
browser.storage.sync.get(
2021-04-16 02:45:15 +02:00
["alwaysProxy", "videoQuality", "invidiousDarkMode", "persistInvidiousPrefs"],
(result) => {
if (result.persistInvidiousPrefs) {
const prefs = getCookie();
prefs.local = result.alwaysProxy;
prefs.quality = result.videoQuality;
prefs.dark_mode = result.invidiousDarkMode;
document.cookie = `PREFS=${encodeURIComponent(JSON.stringify(prefs))}`;
}
}
2021-04-16 02:45:15 +02:00
);