Created
November 5, 2017 22:19
-
-
Save jscher2000/586009d1d5078f4e72abe2be466d9144 to your computer and use it in GitHub Desktop.
Hide the play command for video elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Hide Media Play Command | |
// @namespace Violentmonkey Scripts | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== | |
/* Supplements but does not replace media.autoplay.enabled = false | |
* PROBLEM: in testing on YouTube, userStart() reports "pending" and the video doesn't play, when it's the initial page load. | |
* Videos you load from thumbnails work as expected. */ | |
// Kill play() and create userStart() | |
function noplay(){ | |
HTMLMediaElement.prototype.userStart = HTMLMediaElement.prototype.play; | |
HTMLMediaElement.prototype.play = function(){if(this.nodeName == "VIDEO") console.log("play canceled!"); else this.userStart();}; | |
} | |
var s = document.createElement('script'); | |
s.appendChild(document.createTextNode('('+ noplay +')();')); | |
document.body.appendChild(s); | |
// Add button to find and start videos | |
function startVid(e){ | |
var vids = document.querySelectorAll('video'); | |
console.log('vids.length='+vids.length); | |
for (var i=0; i<vids.length; i++){ | |
vids[i].scrollIntoView(); | |
if(confirm("Play this one?")){ | |
vids[i].userStart(); | |
break; | |
} | |
} | |
} | |
var btn = document.createElement('button'); | |
btn.setAttribute('style','width:25px;height:25px;color:#ccc;background-color:#333;position:fixed;bottom:0;right:0;border:none;z-index:5000;'); | |
btn.innerHTML = '▶'; | |
document.body.appendChild(btn); | |
btn.addEventListener('click', startVid, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment