Last active
December 1, 2017 13:07
-
-
Save gregsonar/0198daa7a7c516660e6dfaff5479c325 to your computer and use it in GitHub Desktop.
I perfectly know that the best way to protect image download is not putting it on internet in the first place. But sometimes there are bad days...
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
//Development version: | |
function prtctImg() { | |
var protected_images = document.getElementsByTagName("img"); | |
for (index = 0; index < protected_images.length; ++index) { | |
protected_images[index].oncopy = function() {return false;}; | |
protected_images[index].oncut = function() {return false;}; | |
protected_images[index].onpaste = function() {return false;}; | |
protected_images[index].ondrag = function() {return false;}; | |
protected_images[index].ondragstart = function() {return false;}; | |
protected_images[index].oncontextmenu = function() {return false;}; | |
}; | |
}; | |
prtctImg(); | |
var target = document.querySelector('body'); | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
prtctImg(); | |
}); | |
}); | |
var config = {subtree: true, childList: true } | |
observer.observe(target, config); |
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
//Minified version: | |
function prtctImg(){var n=document.getElementsByTagName("img");for(index=0;index<n.length;++index)n[index].oncopy=function(){return!1},n[index].oncut=function(){return!1},n[index].onpaste=function(){return!1},n[index].ondrag=function(){return!1},n[index].ondragstart=function(){return!1},n[index].oncontextmenu=function(){return!1}}prtctImg();var target=document.querySelector("body"),observer=new MutationObserver(function(n){n.forEach(function(n){prtctImg()})}),config={subtree:!0,childList:!0};observer.observe(target,config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment