Created
November 29, 2013 19:08
-
-
Save diffalot/7710505 to your computer and use it in GitHub Desktop.
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
/* Poultry, a twitter avatar updater for chat.meatspac.es | |
* installed with the following bookmarklet: | |
* javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://meat.lightcorp.net/javascripts/fowl-meat.js';})(); | |
*/ | |
(function ($) { | |
'use strict'; | |
document.body.appendChild(document.createElement('script')) | |
.src='https://oauth.io/auth/download/latest/oauth.js'; | |
var fingerprint = $('input[name=userid]').val(); | |
var twitter = undefined; | |
var lastAvatar = null; | |
var lastText = null; | |
var setAvatar = function() { | |
console.log('uploading'); | |
console.dir(twitter); | |
console.dir(lastAvatar); | |
twitter.post({ | |
url: '/1.1/account/update_profile_image.json', | |
data: lastAvatar | |
}); | |
}; | |
var sendTweet = function() { | |
console.log('sending tweet'); | |
console.dir(twitter); | |
console.dir(lastAvatar); | |
console.log(lastText); | |
twitter.post({ | |
url: '/1.1/status/send_update', | |
data: lastAvatar | |
}); | |
}; | |
var authTwitter = function() { | |
console.log('authorizing'); | |
OAuth.initialize('F6-Ns5MMCaG6zp4BkC-Ikfq3o-0'); | |
OAuth.popup('twitter', function(error, result){ | |
twitter = result; | |
console.log(result); | |
$('#fowl-meat').hide(); | |
$('.menu').append('<li><a id="fowl-avatar" href="javascript:;">Set Twitter Avatar</a></li>').children().last().click(setAvatar); | |
$('.menu').append('<li><a id="fowl-tweet" href="javascript:;">Send Tweet</a></li>').children().last().click(sendTweet); | |
}); | |
}; | |
var watch = function(addedNodes) { | |
$(addedNodes).each(function(i,v) { | |
console.log(fingerprint, v.dataset.fingerprint); | |
if (fingerprint === v.dataset.fingerprint) { | |
lastAvatar = v.children[0].src; | |
window.lastText = v.children; | |
} else { | |
console.log('ignoring'); | |
} | |
}); | |
}; | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
// mutations fire when <li>s are removed, so guard against that. | |
// multiple speakers collide, so just speak the 0th. | |
mutation.addedNodes && watch(mutation.addedNodes) | |
//.querySelector('p').textContent, {noWorker:true}); | |
}); | |
}); | |
observer.observe(document.querySelector('div.chats ul'), {childList: true}); | |
$('.menu').append('<li><a id="fowl-meat" href="javascript:;">Authorize Twitter</a></li>').children().last().click(authTwitter); | |
console.log('fowl loaded'); | |
}($)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment