重新启用禁用菜单"将视频保存为"chrome ext或chrome本身"另存视频"

re-enable disabled menu "save video as" chrome ext or chrome itself "Save Video As"

本文关键字:quot 视频 chrome 保存 ext 本身 启用 菜单 新启用      更新时间:2023-09-26

如何在视频上禁用"另存视频为"选项时重新启用该选项?

这基本上是这个问题的反面。

是否有一个全局命令,我可以发送到chrome命令行重新启用此选项?

或者有一个简单的扩展我可以使用?

我不知道一个确定的方法,但是保存视频信息,删除标签并在其位置创建另一个标签会删除阻止上下文菜单的事件。

function unblockVideos(){
    document.querySelectorAll('video').forEach(function(video){
        let videoHtml = video.outerHTML;
        let container = document.createElement('div');
        let newVideo = toElement(videoHtml);
        container.append(newVideo);
        newVideo.outerHTML = videoHtml;
        video.parentElement.insertBefore(newVideo, video);
        container.remove();
        video.remove();
        // to-element.js v1.0.1
        function toElement(string) {
            let wrapper = document.createElement('div');
            wrapper.appendChild(document.createElement('div'));
            wrapper.firstChild.outerHTML = string.trim();
            return wrapper.firstChild;
        };
    });
};
unblockVideos();

然而,如果你只需要在chrome中这样做,你可以取消事件与getEventListeners()函数

// getEventListeners()
function unblockVideosChrome(){
    document.querySelectorAll('video').forEach(function(video){
        let events = getEventListeners(video);
        if(events.contextmenu){
            events.contextmenu.forEach(function(thisEvent){
                video.removeEventListener('contextmenu', thisEvent.listener);
            });
        };
    });
};
unblockVideosChrome();

我认为这是可能的(至少在一个方面)

如果我们使用这个方法来"阻止"视频的菜单上下文

<video oncontextmenu="return false;">
   <source src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_2MB.mp4"/>
</video>

然后,您所需要做的就是选择视频元素(使用dev-tools)并反转阻塞命令。例如:

document.querySelector('body > video').oncontextmenu="return true"

将重新启用"右键菜单"。+允许你下载视频使用"保存视频为…"选择

正如在公认的答案中所指出的,这是一个不好的实践,因为已经熟悉dev-tools的有经验的用户可以很容易地绕过它。如果您打算保护您的视频,请考虑使用专门针对该特定任务的云服务。