Skip to content

Instantly share code, notes, and snippets.

@sethladd
Created June 6, 2011 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethladd/1009733 to your computer and use it in GitHub Desktop.
Save sethladd/1009733 to your computer and use it in GitHub Desktop.
Tweets +1 Chrome Extension for Google +1 Button and twitter.com
var plusOneScript = document.createElement('script');
plusOneScript.setAttribute("src", "https://apis.google.com/js/plusone.js");
plusOneScript.textContent = '{"parsetags": "explicit"}';
plusOneScript.addEventListener("load", function() {
var script = document.createElement("script");
script.textContent = "var addPlusOne = function(){gapi.plusone.go();setTimeout(addPlusOne, 1000);};setTimeout(addPlusOne, 1000);";
document.body.appendChild(script);
}, false);
document.body.appendChild(plusOneScript);
var findTweets = function(event) {
var node = event.target;
if (node.webkitMatchesSelector && node.webkitMatchesSelector('div[data-item-type=tweet]')) {
addPlusOne(node);
} else if (node.querySelectorAll) {
var tweets = node.querySelectorAll('div[data-item-type=tweet]');
for (var i = 0; i < tweets.length; i++) {
addPlusOne(tweets[i]);
}
}
}
document.body.addEventListener("DOMNodeInserted", findTweets, false);
{
"name" : "Tweets +1",
"version" : "1.0",
"description" : "Adds a +1 button to tweets on twitter.com",
"content_scripts" : [
{
"matches" : [
"http://twitter.com/*",
"https://twitter.com/*"
],
"js" : ["contentscript.js"],
"run_at" : "document_idle",
"all_frames" : false
}
],
"icons" : {
"128" : "tweets+1.png"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment