Persistent Invidious Settings

Makes Invidious settings persist across instances and in private browsing.

目前为 2023-04-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Persistent Invidious Settings
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.06
  5. // @description Makes Invidious settings persist across instances and in private browsing.
  6. // @author Veeno
  7. // @license GPLv3
  8. // @match yewtu.be/*
  9. // @match vid.puffyan.us/*
  10. // @match inv.riverside.rocks/*
  11. // @match invidious.kavin.rocks/*
  12. // @match watch.thekitty.zone/*
  13. // @match y.com.sb/*
  14. // @match invidious.nerdvpn.de/*
  15. // @match invidious.tiekoetter.com/*
  16. // @match yt.artemislena.eu/*
  17. // @match invidious.flokinet.to/*
  18. // @match inv.bp.projectsegfau.lt/*
  19. // @match inv.odyssey346.dev/*
  20. // @match invidious.sethforprivacy.com/*
  21. // @match invidious.projectsegfau.lt/*
  22. // @match invidious.baczek.me/*
  23. // @match yt.funami.tech/*
  24. // @match iv.ggtyler.dev/*
  25. // @match invidious.lunar.icu/*
  26. // @match invidious.privacydev.net/*
  27. // @match vid.priv.au/*
  28. // @match invidious.0011.lt/*
  29. // @match iv.melmac.space/*
  30. // @match invidious.esmailelbob.xyz/*
  31. // @match inv.zzls.xyz/*
  32. // @match invidious.vpsburti.com/*
  33. // @match invidious.snopyta.org/*
  34. // @icon https://invidious.io/invidious-colored-vector.svg
  35. // @run-at document-start
  36. // @grant GM_getValue
  37. // @grant GM_setValue
  38. // ==/UserScript==
  39.  
  40. /* jshint esversion: 11 */
  41.  
  42. (function() {
  43. 'use strict';
  44.  
  45. if(window.self !== window.top) return;
  46.  
  47. const domain = location.hostname;
  48.  
  49. const storedDomainUpToDate = GM_getValue("Invidious_DomainUpToDate", {});
  50.  
  51. const domainUpToDate = Object.fromEntries(
  52. GM_info.script.matches.map(
  53. match => {
  54. const key = match.slice(0, -2);
  55. return [key, storedDomainUpToDate[key] || false];
  56. }
  57. )
  58. );
  59.  
  60. function validateCurrentDomain(){
  61. domainUpToDate[domain] = true;
  62. GM_setValue("Invidious_DomainUpToDate", domainUpToDate);
  63. }
  64.  
  65. function invalidateOtherDomains(){
  66. Object.keys(domainUpToDate).forEach(key => { domainUpToDate[key] = false; });
  67. validateCurrentDomain();
  68. }
  69.  
  70. const defaultSettings = encodeURIComponent(JSON.stringify({
  71. annotations: false,
  72. annotations_subscribed: false,
  73. autoplay: true,
  74. automatic_instance_redirect: false,
  75. captions: ["", "", ""],
  76. comments: ["youtube", ""],
  77. continue: false,
  78. continue_autoplay: true,
  79. dark_mode: "",
  80. latest_only: false,
  81. listen: false,
  82. local: false,
  83. watch_history: false,
  84. vr_mode: true,
  85. show_nick: false,
  86. locale: "en-US",
  87. region: "US",
  88. max_results: 40,
  89. notifications_only: false,
  90. player_style: "invidious",
  91. quality: "hd720",
  92. quality_dash: "auto",
  93. default_home: "Popular",
  94. feed_menu: ["Popular", "Trending"],
  95. related_videos: true,
  96. sort: "published",
  97. speed: 1,
  98. thin_mode: false,
  99. unseen_only: false,
  100. video_loop: false,
  101. extend_desc: false,
  102. volume: 100,
  103. save_player_pos: false
  104. }));
  105.  
  106. const storedSettings = GM_getValue("Invidious_Settings", defaultSettings);
  107.  
  108. const cookieSettings = document.cookie
  109. .split("; ")
  110. .find((entry) => entry.startsWith("PREFS="))
  111. ?.slice(6);
  112.  
  113. if(cookieSettings && domainUpToDate[domain]){
  114. if(cookieSettings !== storedSettings){
  115. GM_setValue("Invidious_Settings", cookieSettings);
  116. invalidateOtherDomains();
  117. }
  118. } else{
  119. const date = new Date();
  120. date.setFullYear(date.getFullYear() + 2);
  121. document.cookie = "PREFS=" + storedSettings + "; domain=" + domain + "; path=/; expires=" + date.toGMTString() + "; Secure; SameSite=Lax";
  122. validateCurrentDomain();
  123. location.reload();
  124. }
  125. })();