// ==UserScript== // @name 二次元裏ちゃんジュークボックス 最適化版 // @namespace http://tampermonkey.net/ // @version 3.0 // @description ウィンドウ操作時のみ動画サイズを最適化 // @author You // @match https://nijiurachan.net/pc/jukebox-popup.php* // @grant none // ==/UserScript== (function() { 'use strict'; // 1. 文字サイズとページ全体の余白調整 const style = document.createElement('style'); style.textContent = ` body, td, th, p, div, span, a, input, button, select { font-size: 100% !important; } body, html { margin: 0 !important; padding: 2px !important; } `; document.head.appendChild(style); // 2. 動画プレイヤーのサイズをウィンドウに合わせる関数 function resizePlayer() { const players = document.querySelectorAll('iframe, video, object, embed'); players.forEach(player => { player.removeAttribute('width'); player.removeAttribute('height'); player.style.setProperty('width', '100%', 'important'); player.style.setProperty('height', 'auto', 'important'); player.style.setProperty('aspect-ratio', '16 / 9', 'important'); player.style.setProperty('display', 'block', 'important'); }); players.forEach(player => { let parent = player.parentElement; while (parent && parent !== document.body) { parent.removeAttribute('width'); parent.removeAttribute('height'); parent.style.setProperty('width', '100%', 'important'); parent.style.setProperty('max-width', '100%', 'important'); parent = parent.parentElement; } }); } // 処理をまとめて実行する関数 function updateAll() { resizePlayer(); } // 初回読み込み時に1回だけ実行 updateAll(); // ご要望通り、ウィンドウのサイズを変更した時(resize)だけ動作させる window.addEventListener('resize', updateAll); // ----------------------------------------------------------- // 【おまけ】PCに負荷をかけない、スマートなページ変更監視機能 // 次の曲へ進んだ時など、ページの中身が切り替わってサイズが // 元に戻ってしまった場合のみ、自動で1回だけ処理を走らせます。 // (1秒ごとのループ監視とは違い、必要な時以外は完全に沈黙します) // ----------------------------------------------------------- const observer = new MutationObserver(() => { clearTimeout(window.updateTimer); // 変更を検知してから0.3秒後に1度だけ整頓処理を実行 window.updateTimer = setTimeout(updateAll, 300); }); observer.observe(document.body, { childList: true, subtree: true }); })();