返回首頁 

Greasy Fork is available in English.

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.

/*MIT LicenseCopyright 2022 CY FungPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.*/// ==UserScript==// @name         Reset YouTube Settings// @namespace    http://tampermonkey.net/// @version      1.1// @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.// @author       CY Fung// @supportURL   https://github.com/cyfung1031/userscript-supports// @match        https://www.youtube.com/*// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com// @grant        GM_registerMenuCommand// @grant        GM_addValueChangeListener// @grant        unsafeWindow// @grant        GM.setValue// @grant        GM.deleteValue// @license      MIT// @require      https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.1/js.cookie.min.js#sha512=wT7uPE7tOP6w4o28u1DN775jYjHQApdBnib5Pho4RB0Pgd9y7eSkAV1BTqQydupYDB9GBhTcQQzyNMPMV3cAew==// ==/UserScript==/* global Cookies, GM_addValueChangeListener, GM_registerMenuCommand */(function () {'use strict';let cb1 = nullGM_registerMenuCommand('Reset YouTube Settings', function () {if (cb1) returncb1 = trueconst whitelist = [// cookies'PREF', 'SID', 'APISID', 'SAPISID', /^__Secure-\w+$/, 'SIDCC',// localstorage'yt-remote-device-id', 'yt-player-headers-readable','ytidb::LAST_R###LT_ENTRY_KEY','yt-remote-connected-devices', 'yt-player-bandwidth','userscript-tabview-settings', // Tabview Youtube/^[\-\w]*h264ify[\-\w]+$/ // h264ify or enhanced-h264ify];const cookiesObject = Cookies.get();let keysCookies = Object.keys(cookiesObject)for (const key of keysCookies) {let value = cookiesObject[key];if (typeof value !== 'string') continue;if (whitelist.includes(key)) continue;let isSkip = false;for (const s of whitelist) {if (isSkip) break;if (typeof s === 'object' && s.constructor.name === 'RegExp') {if (s.test(key)) isSkip = true;}}if (isSkip) continue;Cookies.remove(key);Cookies.remove(key, { domain: 'youtube.com' }); // most youtube cookies use youtube.comCookies.remove(key, { domain: 'www.youtube.com' }); // some cookies such as 'WEVNSM' and 'WNMCID' use www.youtube.comCookies.remove(key, { secure: true });Cookies.remove(key, { domain: 'youtube.com',  secure: true  }); // most youtube cookies use youtube.comCookies.remove(key, { domain: 'www.youtube.com',  secure: true }); // some cookies such as 'WEVNSM' and 'WNMCID' use www.youtube.com}const lsObject = localStorage;let keysLS = Object.keys(lsObject)for (const key of keysLS) {let value = lsObject[key];if (typeof value !== 'string') continue;if (whitelist.includes(key)) continue;let isSkip = false;for (const s of whitelist) {if (isSkip) break;if (typeof s === 'object' && s.constructor.name === 'RegExp') {if (s.test(key)) isSkip = true;}}if (isSkip) continue;localStorage.removeItem(key);}function getReduceds() {const cookiesObject = Cookies.get();let keysCookiesNew = Object.keys(cookiesObject)const lsObject = localStorage;let keysLSNew = Object.keys(lsObject)let reduceds = [keysCookies.length - keysCookiesNew.length, keysLS.length - keysLSNew.length]keysCookies = nullkeysCookiesNew = nullkeysLS = nullkeysLSNew = nullreturn reduceds}setTimeout(() => {let reduceds = getReduceds()if (reduceds[0] || reduceds[1]) {cb1 = () => {alert(`${reduceds[0]} cookies and ${reduceds[1]} localstorages are deleted.The settings have been reset.Click OK to refresh the browser page.`.trim())reduceds = nullunsafeWindow.location.reload()}GM.setValue('reset-youtube-settings-flag', Date.now())} else {alert('No settings to be required for reset.')cb1 = null}}, 300)})let triggerOnce = 0GM_addValueChangeListener('reset-youtube-settings-flag', function (name, old_value, new_value, remote) {if (!(new_value > 0)) returnlet mTriggered = !remote && typeof cb1 === 'function'const tdt = Date.now();triggerOnce = tdtif (mTriggered) {setTimeout(() => {if (tdt !== triggerOnce) returnGM.deleteValue('reset-youtube-settings-flag').then(() => {if (tdt !== triggerOnce) returnsetTimeout(() => {if (tdt !== triggerOnce) returnlet pt = Date.now();window.requestAnimationFrame(() => {if (tdt !== triggerOnce) returnlet ct = Date.now();if (mTriggered && ct - pt < 800) {cb1();cb1 = null} else {cb1 = nullunsafeWindow.location.reload()}})}, 30)})}, 180)} else {if (tdt !== triggerOnce) returnwindow.requestAnimationFrame(() => {if (tdt !== triggerOnce) returncb1 = nullunsafeWindow.location.reload()})}})})();