Last active
August 29, 2015 14:06
-
-
Save mayurah/1988d5893ae45e0feb02 to your computer and use it in GitHub Desktop.
jQuery to fetch images from current page
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
/* | |
* curator: Mayur Pipaliya [ mayur {at} pipaliya {dot} com ] | |
* copyleft (ɔ) distribute, alter and use at your own risk. | |
* apply necessary alternation accordingly. | |
*/ | |
// Dynamically loading jQuery if it doesn't already. | |
if (typeof jQuery == 'undefined') { | |
document.write('<scr'+'ipt type="text/javascript" src="http://ajax.googleapis.com /ajax/libs/jquery/1.7.1/jquery.min.js">'+'</scr'+'ipt>'); | |
} | |
// Parsing images and adding their links in DIV | |
function listImages(){ | |
var listofImages = ''; | |
var tmpImgURL = 'null'; | |
$('*').each(function(){ | |
var backImg; | |
if ($(this).is('img')) { | |
tmpImgURL = $(this).attr('src'); | |
if (!tmpImgURL.toLowerCase().indexOf("rgb") >= 0) | |
listofImages = listofImages + "<li><a download style='margin-bottom:4px;' href='" + tmpImgURL + "'>" + tmpImgURL + "</a></li>"; | |
console.log(tmpImgURL); | |
} else { | |
backImg = $(this).css('background-image'); | |
if (backImg != 'none') | |
{ | |
tmpImgURL = backImg.substring(4, backImg.length-1); | |
if (!tmpImgURL.toLowerCase().indexOf("rgb") >= 0) | |
listofImages = listofImages + "<li><a download style='margin-bottom:4px;' href='" + tmpImgURL + "'>" + tmpImgURL + "</a></li>"; | |
console.log(tmpImgURL); | |
} | |
} | |
}); | |
$("#objSurmi").append("<br><b>List of images </b><br><br><ol>" + listofImages + "</ol>"); | |
$('ol > li').css({'display': 'list-item', 'list-style-position':'inside'}); | |
} | |
// function for centering DIV element | |
jQuery.fn.center = function () { | |
this.css("position","absolute"); | |
this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + | |
$(window).scrollTop()) + "px"); | |
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + | |
$(window).scrollLeft()) + "px"); | |
return this; | |
} | |
// adding empty DIV element. | |
jQuery('body').prepend( | |
"<br><hr><div id='objSurmi'><br><a hred='javascript:void(0)' onClick='listImages();return false;'>Click to parse Images</a><br>" //create this html | |
+ "</div><hr><br><br>"); | |
// Beautifying DIV | |
$('#objSurmi').css({"background": "url(http://subtlepatterns.com/patterns/mooning.png)", | |
"color":"green","line-height":"18px","font-family":"'Open Sans', sans-serif", | |
"width":"500px","min-height": "400px", | |
"z-index": "2147483647", "position":"absolute", | |
"border-radius": "15px", | |
"margin": "3px 3px 3px 3px", | |
"padding": "5px 5px 5px 5px"}); | |
// Doesn't seem to be in effect due to some reasons. | |
$('ol > li').css({'display': 'list-item', 'list-style-position':'inside'}); | |
// Applying center fn on DIV | |
$("#objSurmi").center(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment