Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript动态更改YouTube播放器大小?_Javascript_Google Chrome_Dynamic_Youtube_Userscripts - Fatal编程技术网

使用JavaScript动态更改YouTube播放器大小?

使用JavaScript动态更改YouTube播放器大小?,javascript,google-chrome,dynamic,youtube,userscripts,Javascript,Google Chrome,Dynamic,Youtube,Userscripts,我希望YouTube完全填满我的浏览器窗口,而不删除评论/播放列表/任何内容 我制作了以下脚本,无论何时调整窗口大小,它都能完美地工作(忽略一些细节,我将在稍后修复)。当页面加载或使用最大化按钮时,它(完全)无法工作。我怎样才能使它在这两种情况下也起作用 我注意到YouTube上还有其他脚本动态更改了标记的样式,我可以删除该脚本还是确保我的脚本在该脚本之后运行 (用户)脚本: 它很难看,但仅供个人使用 PS:请不要建议任何jQuery内容,它不是必需/需要的。 PPS:它只需要在Google C

我希望YouTube完全填满我的浏览器窗口,而不删除评论/播放列表/任何内容

我制作了以下脚本,无论何时调整窗口大小,它都能完美地工作(忽略一些细节,我将在稍后修复)。当页面加载或使用最大化按钮时,它(完全)无法工作。我怎样才能使它在这两种情况下也起作用

我注意到YouTube上还有其他脚本动态更改了
标记的样式,我可以删除该脚本还是确保我的脚本在该脚本之后运行

(用户)脚本:

它很难看,但仅供个人使用

PS:请不要建议任何jQuery内容,它不是必需/需要的。

PPS:它只需要在Google Chrome上运行。

在这里找到了解决方案:

通过任何类型的调整大小,它似乎都是可靠的

// ==UserScript==
// @name        My Fancy New Userscript
// @namespace   http://your.homepage/
// @version     0.1
// @description enter something useful
// @author      You
// @match       http://www.youtube.com/*
// @match       https://www.youtube.com/*
// @match       http://youtube.com/*
// @match       https://youtube.com/*
// @grant       none
// @run-at      document-start
// ==/UserScript==

var addEvent = function(elem, type, eventHandle) {
    if (elem == null || typeof(elem) == 'undefined') return;
    if ( elem.addEventListener ) {
        elem.addEventListener( type, eventHandle, false );
    } else if ( elem.attachEvent ) {
        elem.attachEvent( "on" + type, eventHandle );
    } else {
        elem["on"+type]=eventHandle;
    }
};

var resizer = function() {
    var clientWidth = document.documentElement.clientWidth || window.innerWidth || document.body.clientWidth;
    var clientHeight = document.documentElement.clientHeight || window.innerHeight || document.body.clientHeight;
    var player = document.getElementById("player");
    var playerAPI = document.getElementById("player-api-legacy") || document.getElementById("player-api");
    var videoContainer = player;

    var html5container = document.getElementsByTagName("video");
    console.log(html5container);
    html5container[0].style.width = 100 + "%";
    html5container[0].style.height = 100 + "%";

    player.removeAttribute("class");
    playerAPI.style.width = clientWidth + "px";
    playerAPI.style.height = clientHeight + "px";
}

addEvent(window, "load", resizer);
addEvent(window, "resize", resizer);