最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

How can I re-enable the "Save Video As" option when it is disabled on a video?

This is basically the opposite of this question.

Is there a global command I can send to the chrome command line which re-enables this option?

Or is there a simple extension I could use?

How can I re-enable the "Save Video As" option when it is disabled on a video?

This is basically the opposite of this question.

Is there a global command I can send to the chrome command line which re-enables this option?

Or is there a simple extension I could use?

Share Improve this question edited Nov 10, 2019 at 22:14 Neuron 5,8415 gold badges43 silver badges62 bronze badges asked Sep 7, 2016 at 3:55 DOMDocumentVideoSourceDOMDocumentVideoSource 6461 gold badge7 silver badges16 bronze badges 1
  • 3 re-enable disabled menu “save video as” chrome ext or chrome itself “Save Video As” – DOMDocumentVideoSource Commented Nov 27, 2016 at 20:14
Add a comment  | 

2 Answers 2

Reset to default 1

I think it is possible (at least in one way)

If we are using this method to "block" the menu context of the video

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

Then, all you need to do is to select video element (using dev-tools) and reverse the blocking command. For instance:

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

Will re-enable the "right click menu" + allows you to download video using the "save video as..." option

As noted in accepted answer this is a bad practice because experienced users that already familiar with dev-tools can by-pass this easily. If you intend to protect your videos, please consider using a cloud service that specialized in that specific task.

I don't know a definitive way, but saving the video information, deleting the tag and creating another one in its place deletes the event that prevents the context menu.

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();

However, if you only need to do this in chrome, you can cancel the event with the getEventListeners() function

// 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();

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论