// ==UserScript== // @name Media Player Enhancer // @description Enhances the HTML5 video player with keyboard shortcuts and other features, and provides feedback on key presses. // @match *://*/* // @icon https://raw.githubusercontent.com/WhyWhatHow/powertoys4browser/master/icons/media_enhancer.ico // @grant none // @run-at window-load // @namespace https://whywhathow.github.io/ // @homepage https://github.com/WhyWhatHow/powertoys4browser // @supportURL https://github.com/WhyWhatHow/powertoys4browser/issues // @version 1.9 // @author whywhathow // @updateURL https://raw.githubusercontent.com/WhyWhatHow/powertoys4browser/master/js/media_enhancer.js // @license MIT // ==/UserScript== // 快捷键消息提示框 元素ID. const MSG_BOX_ID = 'reference'; // 避免 body.offsetHeight = 0 的情况. let body_size; // 初始化 function init() { // 初始化消息提示框 initShortCutsBox(); // 初始化 body_size initBodySize(); } // 初始化 body_size function initBodySize() { body_size = { width: document.body.offsetWidth, height: document.body.offsetHeight }; console.log("----------body_size----------") console.log(body_size) } var container_default_size; // 即videoPlayer的 width, height // 初始化快捷键信息提示框 function initShortCutsBox() { const reference = document.createElement('div'); reference.id = MSG_BOX_ID; reference.style.top = '35%'; reference.style.left = '15%'; reference.style.width = 'auto'; reference.style.height = 'auto'; reference.style.fontSize = 'large'; reference.style.margin = '10px'; reference.style.transform = 'translate(-50%, -50%)'; reference.style.background = 'rgba(33,33,33,.9)' reference.style.color = '#fff'; reference.style.padding = '10px'; reference.style.zIndex = '9999'; reference.style.position = 'fixed'; reference.style.display = 'none'; reference.innerHTML = `

Video Player Shortcuts

`; document.body.appendChild(reference); } // 显示快捷键提示框 function showReference() { let ele = document.getElementById(MSG_BOX_ID); if (ele.style.display === 'none') { ele.style.display = 'block'; } else { ele.style.display = 'none'; } } /** * 生成video标签的父标签 * @param videoElement video player tag * @param feedbackElement some Information * @returns videoContainer */ function createVideoParentElement(videoElement, feedbackElement) { var videoContainer; /////// videoContainer = document.createElement('div'); videoContainer.id = 'fun-video-container'; // videoContainer 样式设置 videoContainer.style.position = 'relative'; // 设置父节点 div 的定位方式 // videoContainer.style.position ='inherit'; videoContainer.style.width = videoElement.offsetWidth + 'px'; // 设置父节点 div 的宽度 videoContainer.style.height = videoElement.offsetHeight + 'px'; // 设置父节点 div 的高度 container_default_size = { width: videoElement.offsetWidth, height: videoElement.offsetHeight }; // console.log("----------------------container_default_size--------------------") // console.log(container_default_size) // console.log(videoContainer) if (videoElement.parentElement === document.body) { document.body.appendChild(videoContainer); } else { // hint: 这个函数已经将videoContainer 加入到document 中, 不需要二次加入 videoElement.parentNode.insertBefore(videoContainer, videoElement); // 将父节点 div 插入到 video 的前面 } // console.log(videoContainer) videoContainer.appendChild(videoElement); videoContainer.appendChild(feedbackElement); // videoContainer.appendChild(document.getElementById(MSG_BOX_ID)); // 添加 快捷键消息提示框. // console.log(videoElement.parentElement) return videoContainer; } // 获取