Reset YouTube Settings

Due to YouTube making changes to its layout, some obsolete settings might remain and cause some problems to you. Use this to reset them.

当前为 2022-12-28 提交的版本,查看 最新版本

  1. /*
  2.  
  3. MIT License
  4.  
  5. Copyright 2022 CY Fung
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13.  
  14. The above copyright notice and this permission notice shall be included in all
  15. copies or substantial portions of the Software.
  16.  
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. SOFTWARE.
  24.  
  25. */
  26. // ==UserScript==
  27. // @name Reset YouTube Settings
  28. // @namespace http://tampermonkey.net/
  29. // @version 0.2
  30. // @description Due to YouTube making changes to its layout, some obsolete settings might remain and cause some problems to you. Use this to reset them.
  31. // @author CY Fung
  32. // @supportURL https://github.com/cyfung1031/userscript-supports
  33. // @match https://www.youtube.com/*
  34. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  35. // @grant GM_registerMenuCommand
  36. // @grant unsafeWindow
  37. // @license MIT
  38. // @require https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.1/js.cookie.min.js#sha512=wT7uPE7tOP6w4o28u1DN775jYjHQApdBnib5Pho4RB0Pgd9y7eSkAV1BTqQydupYDB9GBhTcQQzyNMPMV3cAew==
  39. // ==/UserScript==
  40.  
  41. /* global Cookies */
  42.  
  43. (function () {
  44. 'use strict';
  45. GM_registerMenuCommand('Reset YouTube Settings', function () {
  46.  
  47. const whilelist = [
  48. // cookies
  49. 'PREF', 'SID', 'APISID', 'SAPISID', /^__Secure-\w+$/, 'SIDCC',
  50. // localstorage
  51. 'yt-remote-device-id', 'yt-player-headers-readable',
  52. 'ytidb::LAST_RESULT_ENTRY_KEY',
  53. 'yt-remote-connected-devices', 'yt-player-bandwidth',
  54. 'userscript-tabview-settings', // Tabview Youtube
  55. /^[\-\w]*h264ify[\-\w]+$/ // h264ify or enhanced-h264ify
  56. ];
  57.  
  58. const cookiesObject = Cookies.get();
  59. let keysCookies = Object.keys(cookiesObject)
  60. for (const key of keysCookies) {
  61. let value = cookiesObject[key];
  62. if (typeof value !== 'string') continue;
  63. if (whilelist.includes(key)) continue;
  64. let isSkip = false;
  65. for (const s of whilelist) {
  66. if (isSkip) break;
  67. if (typeof s === 'object' && s.constructor.name === 'RegExp') {
  68. if (s.test(key)) isSkip = true;
  69. }
  70. }
  71. if (isSkip) continue;
  72. Cookies.remove(key);
  73. Cookies.remove(key, { domain: 'youtube.com' }); // most youtube cookies use youtube.com
  74. Cookies.remove(key, { domain: 'www.youtube.com' }); // some cookies such as 'WEVNSM' and 'WNMCID' use www.youtube.com
  75. }
  76.  
  77. const lsObject = localStorage;
  78. let keysLS = Object.keys(lsObject)
  79. for (const key of keysLS) {
  80. let value = lsObject[key];
  81. if (typeof value !== 'string') continue;
  82. if (whilelist.includes(key)) continue;
  83. let isSkip = false;
  84. for (const s of whilelist) {
  85. if (isSkip) break;
  86. if (typeof s === 'object' && s.constructor.name === 'RegExp') {
  87. if (s.test(key)) isSkip = true;
  88. }
  89. }
  90. if (isSkip) continue;
  91. localStorage.removeItem(key);
  92. }
  93.  
  94. let ct = Date.now();
  95. window.requestAnimationFrame(() => {
  96. let t = Date.now();
  97. if (ct - t < 800) {
  98.  
  99. const cookiesObject = Cookies.get();
  100. let keysCookiesNew = Object.keys(cookiesObject)
  101. const lsObject = localStorage;
  102. let keysLSNew = Object.keys(lsObject)
  103.  
  104. let reduceds = [keysCookies.length - keysCookiesNew.length, keysLS.length - keysLSNew.length]
  105. if (reduceds[0] || reduceds[1]) {
  106.  
  107. alert(`
  108. ${reduceds[0]} cookies and ${reduceds[1]} localstorages are deleted.
  109. The settings have been reset.
  110. Click OK to refresh the browser page.
  111. `.trim())
  112. unsafeWindow.location.reload()
  113.  
  114. }
  115. keysCookies = null
  116. keysCookiesNew = null
  117. keysLS = null
  118. keysLSNew = null
  119.  
  120. }
  121. })
  122.  
  123. })
  124. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址