-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.scrape.js
More file actions
44 lines (33 loc) · 1.23 KB
/
jquery.scrape.js
File metadata and controls
44 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(function( $ ){
$.jqueryScrape = {
result : '',
proxyUrl : 'jquery.scrape.proxy.php',
getResult : function(url, event) {
var finishedEvent = (typeof(event) == 'string') ? event : false;
var self = this;
if (typeof(url) != 'string') return false;
$.post(this.proxyUrl, {jqueryScrapeUrl : url}, function(response) {
self.result = $(response);
if (finishedEvent) $.event.trigger(finishedEvent, $(response));
});
},
span2img : function(result, options, callback) {
var settings = $.extend({
filter : '',
prepend : '',
imgClass : ''
}, options);
var self = this;
if (typeof(callback) != 'undefined') $(result).find(' span[src]').each(callback); else
$(result).find('span[src]'+settings.filter).each(function() {
var imgSrc = $(this).attr('src');
$('<img class="'+settings.imgClass+'" src="'+settings.prepend+imgSrc+'" />').insertAfter($(this));
})
return $(result);
},
setProxyUrl : function(url) {
if (typeof(url) != 'string') return false;
this.proxyUrl = url;
}
}
})( jQuery );