Last active
October 2, 2015 02:08
-
-
Save nblenke/2150175 to your computer and use it in GitHub Desktop.
A jQuery plugin to scrape your Google +1s page with YQL,jQuery
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
(function($) { | |
'use strict'; | |
$.fn.PlusEmbed = function(stg) { | |
var $this = this, | |
cfg = { | |
count: 10 | |
}; | |
if (stg) { | |
$.extend(cfg, stg); | |
} | |
this.each(function() { | |
var query = 'SELECT * FROM html WHERE url="https://plus.google.com/u/0/' + cfg.id + '/plusones" AND xpath="//div[@id=\'' + cfg.id + '-plusones-page\']"', | |
arr = [], | |
get = function () { | |
var timer; | |
$.getJSON('http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + '&callback=?', function (response) { | |
$.each($(response.results[0]).find('table:gt(0) td:first-child'), function (i) { | |
if (i < cfg.count) { | |
arr[i] = { | |
link: $(this).find('a').prop('href'), | |
img: $(this).find('img').prop('src').replace('file://', 'http://') | |
}; | |
} | |
}); | |
$.each($(response.results[0]).find('table:gt(0) td:last-child'), function (i) { | |
if (i < cfg.count) { | |
arr[i] = $.extend({ | |
title: $(this).find('a').html(), | |
descr: $(this).find('p').html() | |
}, arr[i]); | |
} | |
}); | |
timer = window.setTimeout(function () { | |
if (!arr.length) { | |
get(); | |
} else { | |
clearTimeout(timer); | |
$this.empty(); | |
$.each(arr, function (i, item) { | |
$this.append('<div><a href="' + item.link + '" class="thumb"><img src="' + item.img + '" alt=""></a>' + | |
'<h3><a href="' + item.link + '">' + item.title + '</a></h3>' + '<p>' + item.descr + '</p></div>'); | |
}); | |
} | |
}, 1000); | |
}); | |
}; | |
get(); | |
}); | |
return this; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment