// ==UserScript== // @name youtube auto-hide header // @namespace http://tampermonkey.net/ // @version 2.2 // @description youtubeのヘッダーを自動で隠します(スクロールか画面上部ホバーで表示) // @author y_kahou // @match https://www.youtube.com/* // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @license MIT // @require https://greasyfork.org/scripts/419955-y-method/code/y_method.js?version=1051149 // @noframes // @downloadURL https://update.greasyfork.icu/scripts/414234/youtube%20auto-hide%20header.user.js // @updateURL https://update.greasyfork.icu/scripts/414234/youtube%20auto-hide%20header.meta.js // ==/UserScript== /** スクロール後ヘッダーが表示されている時間 */ const SHOW_INTERVAL_SCROLL = 3000; /** topにマウスを載せてからヘッダーが出るまでの時間 */ const SHOW_INTERVAL_HOVER = 300; /** topからマウスをどけてヘッダーが消えるまでの時間 */ const HIDE_INTERVAL_HOVER = 1000; let mouseX = -1, mouseY = -1; (function() { // innerHTML を使うためのおまじない if (window.trustedTypes && trustedTypes.createPolicy) { if (!trustedTypes.defaultPolicy) { const passThroughFn = (x) => x; trustedTypes.createPolicy('default', { createHTML: passThroughFn, createScriptURL: passThroughFn, createScript: passThroughFn, }); } } // ページ遷移を検知できるようにする y_method.DetectPagetransition(); y_method.PageLauncher([ { match: 'https://www.youtube.com/watch', css: `html:not([fullscreen]) ytd-app { margin-top: -56px; }`, run: hide } ]); // 最初の一回 y_method.TriggerPagetransition(); y_method.addStyle('auto-hide-header', ` #masthead #background { opacity: 1!important; } #yah-setting { position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; background: #888b; z-index: 10000; user-select: none; } #yah-setting .modal-back { position: absolute; width: 100%; height: 100%; z-index: -1; } #yah-setting .modal { display: grid; justify-items: center; margin: 100px auto; padding: 50px; width: fit-content; background: white; } #yah-setting label { font-size: large; } `); const defaultValue = (key, val) => (typeof GM_getValue(key) == "undefined") ? GM_setValue(key, val) : ''; defaultValue('yah-1', true); defaultValue('yah-2', false); // setting GM_registerMenuCommand('Setting', () => { let modal = document.createElement('div') modal.id = 'yah-setting' modal.innerHTML = trustedTypes.defaultPolicy.createHTML(`