防止 divx Web 插件替换 html5 视频元素?

发布于 2024-10-12 19:34:26 字数 122 浏览 2 评论 0原文

出于某种原因,我确信 DivX 的人们认为这一点很重要,没有直接的方法可以阻止他们的插件用他们喜欢的徽标替换页面上的所有视频元素。

我需要的是解决这个问题的方法,告诉插件跳过一些视频,即不要用可播放的内容替换它们。

For some reason I'm sure the folks at DivX think is important, there is no straightforward way to prevent their plugin from replacing all video elements on your page with they fancy logo.

What I need is a workaround for this, telling the plugin to skip some videos, i.e. not replace them with their playable content.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

2024-10-19 19:34:26

我通过放置一个空的 HTML 5 视频标签,然后将视频源标签放入正文 onload 事件中的 JavaScript 函数来解决这个问题。然后视频会出现在普通的 HTML 5 播放器中,而不是 DivX Web 播放器中。

例如
这会给 DivX 播放器:

<video width="320" height="240" controls="controls">
  <source src="movie.mp4" type="video/mp4" />
</video>

但这会给普通的 html 5 播放器:

    <head>
    <script type="text/javascript">
    function changevid() {
       document.getElementById('vid').innerHTML = '<source src="inc/videos/sample1.mp4" type="video/mp4" />';
       document.getElementById('vid').load();
    }
    </script>
    </head>
    <body onload="changevid()">

       <video id="vid" width="800" height="450" controls="controls">    
       </video>

    </body>

I got around this by putting an empty HTML 5 video tag, then putting in the video source tags in a JavaScript function in the body onload event. The video then comes up in the normal HTML 5 player and not the DivX web player.

e.g.
This would give the DivX player:

<video width="320" height="240" controls="controls">
  <source src="movie.mp4" type="video/mp4" />
</video>

But this would give the normal html 5 player:

    <head>
    <script type="text/javascript">
    function changevid() {
       document.getElementById('vid').innerHTML = '<source src="inc/videos/sample1.mp4" type="video/mp4" />';
       document.getElementById('vid').load();
    }
    </script>
    </head>
    <body onload="changevid()">

       <video id="vid" width="800" height="450" controls="controls">    
       </video>

    </body>
鸵鸟症 2024-10-19 19:34:26

目前,没有 API 或方法可以阻止 divx 插件用占位符替换视频元素。 :-(

At this time, there is no API or means to block the divx plugin from replacing video elements with their placeholder. :-(

〗斷ホ乔殘χμё〖 2024-10-19 19:34:26

我开始对 divx 插件进行逆向工程,以找出可以采取哪些措施来禁用它。可以在此处找到一个示例,包括 divx-plugin 的完整源代码: http://jsfiddle.net/ z4JPB/1/

目前在我看来,一个可能的解决方案可以像这样工作:

  • 创建方法 appendChildreplaceChild 和 < code>insertBefore - 这必须在执行 chrome 扩展的内容脚本之前发生。
  • 内容脚本将执行,覆盖上面提到的方法,并将事件侦听器添加到 DOMNodeInsertedIntoDocument 和 DOMNodeInserted 事件
  • 之后,可以删除事件侦听器并保留原始内容DOM 方法已恢复。您现在应该能够用视频元素替换插件创建的嵌入元素

i started reverse-engineering the divx-plugin to find out what can be done to hack a way into disabling it. An example, including the complete sourcecode of the divx-plugin, can be found here: http://jsfiddle.net/z4JPB/1/

It currently appears to me that a possible solution could work like this:

  • create a "clean" backup of the methods appendChild, replaceChild and insertBefore - this has to happen before the content-script from the chrome-extension is executed.
  • the content-script will execute, overrides the methods mentioned above and adds event-listeners to the DOMNodeInsertedIntoDocument and DOMNodeInserted events
  • after that, the event-listeners can be removed and the original DOM-Methods restored. You should now be able to replace the embed-elements created by the plugin with the video-elements
凑诗 2024-10-19 19:34:26

看来,该插件仅在 video 标记中存在 src 元素时才替换视频。对我来说,它的工作原理是首先添加 video 标签,然后在第二个线程中添加 src 标签。然而,这在 IE 中不起作用,但 IE 一次插入完整的视频标签没有问题。

因此,以下代码在所有浏览器中都适用于我(当然,需要 jQuery):

var $container = $('video_container');
var video = 'my-movie';
var videoSrc = '<source src="video/'+video+'.mp4" type="video/mp4"></source>' +
    '<source src="video/'+video+'.webm" type="video/webm"></source>' +
    '<source src="video/'+video+'.ogv" type="video/ogg"></source>';

if(!$.browser.msie) {
    $container.html('<video autoplay loop></video>');
    // this timeout avoids divx player to be triggered
    setTimeout(function() {
        $container.find('video').html(videoSrc);
    }, 50);
}
else {
    // IE has no problem with divx player, so we add the src in the same thread
    $container.html('<video autoplay loop>' + videoSrc + '</video>');
}

It seems, that the plugin is only replacing the video when there are src elements within the video tag. For me it worked by first adding the video tag, and then - in a second thread - add the src tags. However, this doesn´t work in IE but IE had no problem with an insertion of the complete video tag at once.

So following code worked for me in all browsers (of course, jQuery required):

var $container = $('video_container');
var video = 'my-movie';
var videoSrc = '<source src="video/'+video+'.mp4" type="video/mp4"></source>' +
    '<source src="video/'+video+'.webm" type="video/webm"></source>' +
    '<source src="video/'+video+'.ogv" type="video/ogg"></source>';

if(!$.browser.msie) {
    $container.html('<video autoplay loop></video>');
    // this timeout avoids divx player to be triggered
    setTimeout(function() {
        $container.find('video').html(videoSrc);
    }, 50);
}
else {
    // IE has no problem with divx player, so we add the src in the same thread
    $container.html('<video autoplay loop>' + videoSrc + '</video>');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文