Skip to content

Instantly share code, notes, and snippets.

@wittman
Created March 8, 2010 18:20
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 wittman/325421 to your computer and use it in GitHub Desktop.
Save wittman/325421 to your computer and use it in GitHub Desktop.
buzzSawChrome - Google Chrome content extension - Adds avatars to beginning of comments on Google Buzz.Also, Removes Buzz Count (below Inbox count), but still tooltip shows count. Also, removes Friendfeed profile image imported into Buzz.
// ==UserScript==
// @name buzzSawChrome
// @namespace http://wittman.org/projects/buzzsawchrome/
// @description Google Chrome content extension - Adds avatars to beginning of comments on Google Buzz.Also, Removes Buzz Count (below Inbox count), but still tooltip shows count. Also, removes Friendfeed profile image imported into Buzz.
// @author Micah Wittman
// @include http*://mail.google.com/mail/*#buzz*
// @include http*://www.google.com/profiles/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
// @version 0.1.0
// ==/UserScript==
/*
Author: Micah Wittman | http://wittman.org/ | http://wittman.org/projects/buzzsawchrome/ | http://wittman.org/buzz
Versions:
* 2010-03-08 - version 0.1.0 - Prepends commenter's avatar (profile image) to each Google Buzz comment on Buzz views located at www.google.com/profile/*. Also, Removes Buzz Count (below Inbox count), but still tooltip shows count. Also, removes Friendfeed profile image imported into Buzz.
*/
/*** Globals ************************************************/
var logging = false; //DEBUG - Set to true to debug logging
/*** Local Storage *******************************************/
function setItem(key, value) {
try {
log("Storing [" + key + ":" + value + "]");
window.localStorage.removeItem(key); // <-- Local storage!
window.localStorage.setItem(key, value); // <-- Local storage!
} catch(e) {
log("Error inside setItem");
log(e);
}
log("Return from setItem" + key + ":" + value);
}
// Gets item from local storage with specified key.
function getItem(key) {
var value;
log('Retrieving key [' + key + ']');
try {
value = window.localStorage.getItem(key); // <-- Local storage!
}catch(e) {
log("Error inside getItem() for key:" + key);
log(e);
value = "null";
}
log("Returning value: " + value);
return value;
}
// Clears all key/value pairs in local storage.
function clearStrg() {
log('about to clear local storage');
window.localStorage.clear(); // <-- Local storage!
log('cleared');
}
function log(txt) {
if(logging) {
console.log(txt);
}
}
function GM_setValue(name, value){
setItem(name, value);
}
function GM_getValue(name, oDefault){
var value = getItem(name);
if(value == null){
return oDefault;
}else{
return value;
}
}
function GM_listValues(){
return window.localStorage;
}
function GM_deleteValue(name){
var key = name;
try {
log("Removing [" + key + ":" + value + "]");
window.localStorage.removeItem(name);
} catch(e) {
log("Error inside removeItem");
log(e);
}
log("Return from setItem" + key + ":" + value);
}
/*** Hide Buzz Counter (anonymous function)*******************/
(function(){
/** Delay between requests to the server when polling. */
var pollDelay = 3000;
/** Start polling the server */
function start() {
pollId = setInterval(run, pollDelay);
}
/** Stop polling the server */
function stop() {
clearInterval(pollId);
}
function run(){
//d = new Date();
var contents = $("#canvas_frame").contents();
var buzzCountLink = contents.find("a:contains('Buzz'):first");
var text = buzzCountLink.text();
if( (buzzCountLink.length > 0) && (text.indexOf("(") > -1) ){
var title = buzzCountLink.attr('title');
buzzCountLink.attr('title', title).css('padding-right', '1px');
buzzCountLink.text('Buzz');
}
}
/*************************************************************
************************** RUN MODULE ************************
******************** *********************/
start();
})();
/*** Profile Page Comment Avatars (anonymous function)********/
(function(){
//Init for Global Vars
if(typeof unsafeWindow != 'undefined'){
window = unsafeWindow;
}
//Global Vars
var PROFILE_CORPUS = 'http://www.google.com/profiles/';
var PROFILE_CORPUS_SUBDIR = '/contactme';
var NO_PROFILE_URL = 'http://www.gstatic.com/s2/profiles/images/googleyeyes96.png';
var LOC_REF = window.location.href;
var NOW = new Date();
var MONTH = NOW.getMonth() + 1;
var MONTH_PREV = MONTH - 1;
var BUZZ_PROFILE_URL = 'buzz_profile_url:' + MONTH + ':';
var BUZZ_PROFILE_URL_PREV = 'buzz_profile_url:' + MONTH_PREV + ':';
var gSinglePostView = false;
var gCommCount = 0;
var gCommCountPrev = -1;
var gRefetch = false;
var commentCssPadding = '4px 0 4px 0';
//Init Main
if(LOC_REF.indexOf('www.google.com/buzz/') > -1 || LOC_REF.indexOf(PROFILE_CORPUS) > -1){
//Single Post View settings
gSinglePostView = true;
commentCssPadding = '8px 0 8px 0';
}
if(LOC_REF.indexOf('buzzCommentAvatar-refetch') > -1){
//Dump image cache on current page
gRefetch = true;
}
function removeOldCache(){
clearStrg();
}
//Functions
function getProfileUrl(url, username, node){
if(LOC_REF.indexOf('/profiles/') > -1){
//continue
}else{
return;
}
var href = '';
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var domain = '';
var r = xhr.responseText;
var h;
if(r.indexOf(NO_PROFILE_URL) > -1){
h = [NO_PROFILE_URL];
}else{
h = r.match(/\/s2\/photos\/public\/[^"]*"/);
domain = 'http://www.google.com';
}
if(h != null){
href = domain + h[0].replace('"', '');
}
try{GM_deleteValue(BUZZ_PROFILE_URL_PREV + username);}catch(e){}
try{GM_deleteValue(BUZZ_PROFILE_URL + username);}catch(e){}
GM_setValue(BUZZ_PROFILE_URL + username, href);
render_miniavatar(node, username, href);
}
}
xhr.send();
}
function add_miniavatars(){
if(LOC_REF.indexOf('/profiles/') > -1){ //|| LOC_REF.indexOf('/mail/') > -1 || LOC_REF.indexOf('/buzz/') > -1
//continue
}else{
setTimeout(add_miniavatars, 4000);
return;
}
var contents = jQuery("#canvas_frame").contents();
if(contents.length == 0){
contents = jQuery("#buzz-root").contents();
}
var comments = contents.find(".Ix, .CSS_UPDATES_UCW_COMMENT_ROW").css('padding', commentCssPadding);
gCommCount = comments.length; // CSS_PROFILES_COMMENTS ... CSS_UPDATES_UCW_COMMENT_ROW
if(gCommCount == gCommCountPrev){
//No new comments, so call with timeout and return to skip unneccesary processing
setTimeout(add_miniavatars, 2000);
return false;
}else{
//New comments founds, continue balance of function...
//sync counters
gCommCountPrev = gCommCount;
}
var prolinks = comments.find("a.proflink");
if(gSinglePostView){
prolinks = prolinks.filter("a.CSS_UPDATES_UCW_AUTHOR");
}
prolinks.each(function(){
var node = jQuery(this);
var path = node.attr('href');
var hashPos = path.indexOf('#') - path.lastIndexOf('/');
var username = path.substr(path.lastIndexOf('/') + 1, hashPos - 1);
var pUrl = GM_getValue(BUZZ_PROFILE_URL + username, '');
if(pUrl == '' || gRefetch){
if( (LOC_REF.indexOf('/profiles/') > -1) && (username != '') ){
getProfileUrl(PROFILE_CORPUS + username + PROFILE_CORPUS_SUBDIR, username, node);
}
}else{
if(typeof username != undefined && username != null && username != ''){
render_miniavatar(node, username, pUrl);
}
}
});
setTimeout(add_miniavatars, 2000);
}
function render_miniavatar(node, username, pUrl){
if(node.find('.commentMiniAvatar').length == 0 && node.parent().find('.If').length == 0){ //avatar already prepended or on header profile?
node.prepend('<img height="25" width="25" style="position:absolute; left:-25px; top:-8px; margin-top:4px; border:none" class="commentMiniAvatar" src="' + pUrl + '" style="vertical-align:middle" /> &nbsp;');
}
}
function removeFriendfeedProfileImage(){
if(LOC_REF.indexOf('/profiles/') > -1
|| LOC_REF.indexOf('/mail/') > -1
|| LOC_REF.indexOf('/buzz/') > -1){
//continue
}else{
setTimeout(add_miniavatars, 4000);
return;
}
var contents = jQuery("#canvas_frame").contents();
if(contents.length == 0){
contents = jQuery("#buzz-root").contents();
}
//Remove Friendfeed Profile Image embedded in a Buzz post (it's just duplication of Buzz profile pic for the most part)
contents.find('img[src*="friendfeed-media.com%2Fp-"], img[src*="i.friendfeed.com%2Fp-"]').hide();
setTimeout(removeFriendfeedProfileImage, 3000);
}
/*************************************************************
************************** RUN MODULE ************************
******************** *********************/
add_miniavatars();
removeFriendfeedProfileImage();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment