Last active
April 12, 2017 12:46
-
-
Save Gaspadlo/0cef5f48b3a44d8a2422353ef6545ae8 to your computer and use it in GitHub Desktop.
JS bookmarklet
This file contains hidden or 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
javascript:(function () { | |
if (typeof ZHJ10W1lcg === 'undefined') {/*Append jQuery into Documents Head*/ | |
var jQuery = document.createElement('script'); | |
jQuery.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js'); | |
var head = document.getElementsByTagName('head'); | |
head[0].appendChild(jQuery); | |
ZHJ10W1lcg = true; | |
} | |
setTimeout(function () { | |
$(document).ready(function () { | |
/*Remove previous list output*/ | |
$('#IMGlist').remove(); | |
/*Prepend List output and hide it before finding Images*/ | |
$('body').prepend('<div id="IMGlist" style="display:none;position:fixed;top:0;left:0;z-index:99999;background:#fff;padding:5px;">' + | |
'<div style="position:absolute;top: 0;right:0;color:red;" onclick="$(this).parent().remove();">X</div></div>'); | |
/*Set Crosshair Cursor for all elements to indicate active Image selection*/ | |
$('body,body *').css('cursor', 'crosshair', 'important'); | |
var hoverElem = null; | |
/*Get Hovered Element (better than clicking on specific element since they can be hidden or "pointer-events:none" obfuscated*/ | |
$('*').on('mouseenter', function () { | |
hoverElem = this; | |
}); | |
/*Function Preventing from leaving page via link*/ | |
var preventer = function (e) { | |
e.preventDefault(); | |
}; | |
/*Function searching for images and outputting a list of them*/ | |
var searchIMGer = function (e) { | |
$("body,body *").unbind("click", preventer);//Restore normal funciton of links | |
$("body").unbind("click", searchIMGer);//Remove Body listener for Search Image function trigger | |
$('body,body *').css('cursor', 'auto');//Restore normal cursor | |
$('#IMGlist div').css('cursor', 'pointer');//Make list close element resemble a button for cursor | |
var found = false;//Expect no image was found yet | |
if ($(hoverElem).is('IMG')) {//Hovered element is image | |
$('#IMGlist').show() | |
.append('Found:<br />' + | |
'<div style="overflow:hidden;width:100px;height:100px;float:left;clear:both;"><img style="max-width:150%;" src="' + $(hoverElem).attr('SRC') + '"/></div>' + | |
'<div style="height:100px;float:left;">URL:<input style="max-height:32px" value="' + $(hoverElem).attr('SRC') + '" /></div><br />'); | |
found = true;//Output IMGs url | |
} else { | |
if ($(hoverElem).parent().find('IMG').length) {//Elements parent contains at least one image | |
$('#IMGlist').show().append('Found:<br />'); | |
$(hoverElem).parent().find('IMG').each(function () { | |
$('#IMGlist').append('<div style="overflow:hidden;width:32px;height:32px;float:left;clear:both;"><img style="max-width:200%;" src="' + $(this).attr('SRC') + '"/></div>' + | |
'<div style="height:15x;float:left;">URL:<input style="max-height:32px" value="' + $(this).attr('SRC') + '" /></div><br />'); | |
}); | |
found = true;//Output list of IMG URLs | |
} else {//Elements parent does not contain any images, try looking for image backgrounds | |
$(hoverElem).parent().parent().find('*').each(function () {//Looking at all elements backgrounds two levels up | |
if ($(this).css('background-image') != 'none') {//has Image background | |
bgIMG = $(this).css('background-image'); | |
$('#IMGlist').show() | |
.append('<div style="overflow:hidden;width:32px;height:32px;float:left;clear:both;"><img style="max-width:200%;" src="' + bgIMG.substring(5, bgIMG.length - 2) + '"/></div>' + | |
'<div style="height:32px;float:left;">URL:<input style="max-height:32px" value="' + bgIMG.substring(5, bgIMG.length - 2) + '" /></div><br />'); | |
found = true;//Output list of IMG URLs | |
} | |
}); | |
if (found)$('#IMGlist').prepend('Found:<br />');//Insert an Informative string | |
} | |
if (found == false)alert('Image was not found. sorry :(');//popUp information, that no image was found. | |
} | |
}; | |
$("body,body *").bind("click", preventer);//Prevent all elements from their natural actions from mouse click (following links) | |
$("body").bind("click", searchIMGer);//Add listener to body element that will trigger Search for images on click function | |
}); | |
}, 250);//Wait a bit to let everything settle and load | |
})(); |
This file contains hidden or 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
javascript:(function(){if(typeof ZHJ10W1lcg==="undefined"){var b=document.createElement("script");b.setAttribute("src","//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js");var a=document.getElementsByTagName("head");a[0].appendChild(b);ZHJ10W1lcg=true}setTimeout(function(){$(document).ready(function(){$("#IMGlist").remove();$("body").prepend('<div id="IMGlist" style="display:none;position:fixed;top:0;left:0;z-index:99999;background:#fff;padding:5px;"><div style="position:absolute;top: 0;right:0;color:red;" onclick="$(this).parent().remove();">X</div></div>');$("body,body *").css("cursor","crosshair","important");var e=null;$("*").on("mouseenter",function(){e=this});var d=function(f){f.preventDefault()};var c=function(g){$("body,body *").unbind("click",d);$("body").unbind("click",c);$("body,body *").css("cursor","auto");$("#IMGlist div").css("cursor","pointer");var f=false;if($(e).is("IMG")){$("#IMGlist").show().append('Found:<br /><div style="overflow:hidden;width:100px;height:100px;float:left;clear:both;"><img style="max-width:150%;" src="'+$(e).attr("SRC")+'"/></div><div style="height:100px;float:left;">URL:<input style="max-height:32px" value="'+$(e).attr("SRC")+'" /></div><br />');f=true}else{if($(e).parent().find("IMG").length){$("#IMGlist").show().append("Found:<br />");$(e).parent().find("IMG").each(function(){$("#IMGlist").append('<div style="overflow:hidden;width:32px;height:32px;float:left;clear:both;"><img style="max-width:200%;" src="'+$(this).attr("SRC")+'"/></div><div style="height:15x;float:left;">URL:<input style="max-height:32px" value="'+$(this).attr("SRC")+'" /></div><br />')});f=true}else{$(e).parent().parent().find("*").each(function(){if($(this).css("background-image")!="none"){bgIMG=$(this).css("background-image");$("#IMGlist").show().append('<div style="overflow:hidden;width:32px;height:32px;float:left;clear:both;"><img style="max-width:200%;" src="'+bgIMG.substring(5,bgIMG.length-2)+'"/></div><div style="height:32px;float:left;">URL:<input style="max-height:32px" value="'+bgIMG.substring(5,bgIMG.length-2)+'" /></div><br />');f=true}});if(f){$("#IMGlist").prepend("Found:<br />")}}if(f==false){alert("Image was not found. sorry :(")}}};$("body,body *").bind("click",d);$("body").bind("click",c)})},250)})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment