// ==UserScript==
// @name Persistent Invidious Settings
// @namespace http://tampermonkey.net/
// @version 1.03
// @description Makes Invidious settings persist across instances and in private browsing.
// @author Veeno
// @license GPLv3
// @match invidious.snopyta.org/*
// @match yewtu.be/*
// @match vid.puffyan.us/*
// @match inv.riverside.rocks/*
// @match invidious.kavin.rocks/*
// @match watch.thekitty.zone/*
// @match y.com.sb/*
// @match invidious.nerdvpn.de/*
// @match invidious.tiekoetter.com/*
// @match yt.artemislena.eu/*
// @match invidious.flokinet.to/*
// @match inv.bp.projectsegfau.lt/*
// @match inv.odyssey346.dev/*
// @match invidious.sethforprivacy.com/*
// @match invidious.baczek.me/*
// @match inv.vern.cc/*
// @match invidious.snopyta.org/*
// @match yt.funami.tech/*
// @match invidious.epicsite.xyz/*
// @match iv.ggtyler.dev/*
// @match yt.oelrichsgarcia.de/*
// @match invidious.lunar.icu/*
// @match invidious.privacydev.net/*
// @match invidious.slipfox.xyz/*
// @match iv.melmac.space/*
// @match invidious.weblibre.org/*
// @match invidious.esmailelbob.xyz/*
// @match invidious.lidarshield.cloud/*
// @icon https://invidious.io/invidious-colored-vector.svg
// @run-at document-start
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
/* jshint esversion: 11 */
(function() {
'use strict';
if(window.self !== window.top) return;
const domain = location.hostname;
const defaultDomainUpToDate = Object.fromEntries(
GM_info.script.matches.map(
match => [match.slice(0, -2), false]
)
);
const storedDomainUpToDate = GM_getValue("Invidious_DomainUpToDate", defaultDomainUpToDate);
const domainUpToDate = Object.fromEntries(
Object.entries(defaultDomainUpToDate).map(
([key, value]) => [key, storedDomainUpToDate[key] || value]
)
);
function validateCurrentDomain(){
domainUpToDate[domain] = true;
GM_setValue("Invidious_DomainUpToDate", domainUpToDate);
}
function invalidateOtherDomains(){
Object.keys(domainUpToDate).forEach(key => { domainUpToDate[key] = false; });
validateCurrentDomain();
}
const defaultSettings = encodeURIComponent(JSON.stringify({
annotations: false,
annotations_subscribed: false,
autoplay: true,
automatic_instance_redirect: false,
captions: ["", "", ""],
comments: ["youtube", ""],
continue: false,
continue_autoplay: true,
dark_mode: "",
latest_only: false,
listen: false,
local: false,
watch_history: false,
vr_mode: true,
show_nick: false,
locale: "en-US",
region: "US",
max_results: 40,
notifications_only: false,
player_style: "invidious",
quality: "hd720",
quality_dash: "auto",
default_home: "Popular",
feed_menu: ["Popular", "Trending"],
related_videos: true,
sort: "published",
speed: 1,
thin_mode: false,
unseen_only: false,
video_loop: false,
extend_desc: false,
volume: 100,
save_player_pos: false
}));
const storedSettings = GM_getValue("Invidious_Settings", defaultSettings);
const cookieSettings = document.cookie
.split("; ")
.find((entry) => entry.startsWith("PREFS="))
?.slice(6);
if(cookieSettings && domainUpToDate[domain]){
if(cookieSettings !== storedSettings){
GM_setValue("Invidious_Settings", cookieSettings);
invalidateOtherDomains();
}
} else{
const date = new Date();
date.setFullYear(date.getFullYear() + 2);
document.cookie = "PREFS=" + storedSettings + "; domain=" + domain + "; path=/; expires=" + date.toGMTString() + "; Secure; SameSite=Lax";
validateCurrentDomain();
location.reload();
}
})();