Persistent Invidious Settings

Makes Invidious settings persist across instances and in private browsing.

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

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