Created
December 18, 2012 19:01
-
-
Save Scarygami/4330879 to your computer and use it in GitHub Desktop.
Meebo Bar - Recent Posts Widget See https://plus.google.com/112336147904981294875/posts/HW3C3mvNBFk for details
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
<style> | |
.activities-widget { | |
display: inline-block !important; | |
padding: 5px !important; | |
width: 320px !important; | |
max-width: 320px !important; | |
margin: 2px !important; | |
border-radius: 5px !important; | |
overflow: hidden !important; | |
font-size: 13px !important; | |
} | |
.activities-widget img { | |
max-width: 300px !important; | |
} | |
.activities-widget p { | |
margin-bottom: 10px !important; | |
word-wrap: break-word !important; | |
} | |
.activities-widget a { | |
text-decoration: none !important; | |
color: black !important; | |
} | |
.activities-widget a:hover { | |
text-decoration: underline !important; | |
} | |
.activities-widget-activity { | |
position: relative !important; | |
display: block !important; | |
padding: 2px !important; | |
margin-bottom: 2px !important; | |
border-bottom: 1px solid black !important; | |
} | |
.activities-widget .activities-widget-activity:last-child { | |
border-bottom: 0 !important; | |
} | |
.activities-widget-date { | |
display: block !important; | |
text-align: right !important; | |
width: 100% !important; | |
color: #999 !important; | |
font-size: 11px !important; | |
} | |
.activities-widget-date a { | |
color: #999 !important; | |
} | |
.activities-widget-reshare { | |
font-size: 11px !important; | |
border-bottom: 1px dashed #CCC !important; | |
} | |
</style> | |
<script type="text/javascript"> | |
(function (global) { | |
"use strict"; | |
// You get this by creating a project at https://code.google.com/apis/console/ | |
// You also need to activate Google+ API in "Services" | |
// Key can be found API Access | |
var apikey = "<YOUR API KEY>"; | |
// That's the long number (or custom name) in the URL of your Google+ Profile | |
var userId = "<YOUR GOOGLE+ USER ID>"; | |
Date.prototype.niceDate = function () { | |
var y, m, d, h, min, sec, now; | |
now = new Date(); | |
y = this.getFullYear().toString(); | |
m = (this.getMonth() + 1).toString(); | |
d = this.getDate().toString(); | |
h = this.getHours().toString(); | |
min = this.getMinutes().toString(); | |
sec = this.getSeconds().toString(); | |
if (this.getFullYear() === now.getFullYear() && this.getMonth() === now.getMonth() && this.getDate() === now.getDate()) { | |
return (h[1] ? h : "0" + h[0]) + ":" + (min[1] ? min : "0" + min[0]); | |
} else { | |
return y + "-" + (m[1] ? m : "0" + m[0]) + "-" + (d[1] ? d : "0" + d[0]) + " " + (h[1] ? h : "0" + h[0]) + ":" + (min[1] ? min : "0" + min[0]); | |
} | |
}; | |
function renderActivity(item) { | |
var div, tmp, a, reshare, i; | |
div = global.document.createElement("div"); | |
div.className = "activities-widget-activity"; | |
tmp = global.document.createElement("div"); | |
tmp.className = "activities-widget-date"; | |
a = global.document.createElement("a"); | |
a.href = item.url; | |
a.innerHTML = (new Date(item.published)).niceDate(); | |
tmp.appendChild(a); | |
div.appendChild(tmp); | |
reshare = (item.object.actor && item.object.actor.id !== item.actor.id); | |
if (reshare) { | |
if (item.annotation) { | |
tmp = global.document.createElement("p"); | |
tmp.innerHTML = item.annotation; | |
div.appendChild(tmp); | |
} | |
tmp = global.document.createElement("p"); | |
tmp.className = "activities-widget-reshare"; | |
tmp.innerHTML = "Originally shared by "; | |
a = global.document.createElement("a"); | |
a.href = item.object.url || item.object.actor.url; | |
a.innerHTML = item.object.actor.displayName; | |
tmp.appendChild(a); | |
div.appendChild(tmp); | |
} | |
tmp = global.document.createElement("p"); | |
tmp.innerHTML = item.object.content; | |
div.appendChild(tmp); | |
if (item.object.attachments && item.object.attachments.length > 0) { | |
for (i = 0; i < item.object.attachments.length; i++) { | |
if (item.object.attachments[i].image) { | |
tmp = global.document.createElement("img"); | |
tmp.src = item.object.attachments[i].image.url; | |
div.appendChild(tmp); | |
break; | |
} | |
if (item.object.attachments[i].thumbnails && item.object.attachments[i].thumbnails.length > 0) { | |
if (item.object.attachments[i].thumbnails[0].image && item.object.attachments[i].thumbnails[0].image.url) { | |
tmp = global.document.createElement("img"); | |
tmp.src = item.object.attachments[i].thumbnails[0].image.url; | |
div.appendChild(tmp); | |
break; | |
} | |
} | |
} | |
} | |
return div; | |
} | |
function renderWidget() { | |
var request, div; | |
div = global.document.getElementById("activities_widget"); | |
div.innerHTML = ""; | |
request = global.gapi.client.plus.activities.list({"userId": userId, "collection": "public", "maxResults": 10}); | |
request.execute(function (result) { | |
var i, activity, a, l; | |
if (result.error) { | |
div.innerHTML = result.error.message || result.error.code; | |
} else { | |
if (result.items && result.items.length > 0) { | |
l = result.items.length; | |
for (i = 0; i < l; i++) { | |
div.appendChild(renderActivity(result.items[i])); | |
} | |
a = global.document.querySelectorAll("#activities_widget a"); | |
l = a.length; | |
for (i = 0; i < l; i++) { | |
a[i].target = "_blank"; | |
} | |
} else { | |
div.innerHTML = "No posts found"; | |
} | |
} | |
}); | |
} | |
global.onClientReady = function () { | |
global.gapi.client.setApiKey(apikey); | |
global.gapi.client.load('plus', 'v1', function () { | |
renderWidget(); | |
}); | |
}; | |
}(this)); | |
</script> | |
<script src="https://apis.google.com/js/client.js?onload=onClientReady"></script> | |
<div id="activities_widget" class="activities-widget"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment