Greasy Fork 还支持 简体中文。

Persistent Invidious Settings

Makes Invidious settings persist across instances and in private browsing.

目前為 2023-03-02 提交的版本,檢視 最新版本

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