Created
January 7, 2009 11:01
-
-
Save satyr/44249 to your computer and use it in GitHub Desktop.
Tweets via the web interface instead of the API
This file contains hidden or 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
const Name = 'say', | |
Twitter = 'https://twitter.com/', | |
Icon = Twitter +'favicon.ico', | |
MaxLen = 140, | |
Base = <div class={Name}><style><![CDATA[ | |
#timeline {list-style-type:none; font-size:92%; padding:0} | |
#timeline .actions {display:none} | |
#timeline img.fn {width:16px; height:16px; vertical-align:middle} | |
#status {font-size:112%; font-weight:700} | |
.screen-name {margin:0 0.2em} | |
$a img {border:none} | |
$.size {font-size:84%} | |
$.error {font-style:oblique; line-height:1.8} | |
$.excess {text-decoration:line-through} | |
$.logo {display:block} | |
$.loading + .logo {opacity:0.4} | |
$.error + .logo {opacity:0.7} | |
]]></style><div id={Name} | |
><span id="input"> </span><div id="TL"> </div | |
></div><a class="logo" href={Twitter}><img width="125" height="29" | |
src="http://assets0.twitter.com/images/twitter_logo_125x29.png"/></a></div | |
>.toXMLString().replace(/\$/g, '.'+ Name +' ').replace(/>\s+</g, '><'); | |
function showError(msg, type){ | |
displayMessage({icon: Icon, title: (type || '') +'Error', text: msg}); | |
pdate = new Date - 3e4; | |
} | |
function ajaxError(x) showError(x.status +' '+ x.statusText, 'Ajax'); | |
function setTL(tl, htm){ | |
if(/<form [^]+?<\/ol>/(htm)){ | |
var $f = jQuery(RegExp.lastMatch); | |
token = $f.find('input[name="authenticity_token"]').val(); | |
tl.innerHTML = ''; | |
$f.find('#timeline').appendTo(tl); | |
tl.parentNode.className = ''; | |
} else { | |
pdate = new Date - 4e4; | |
tl.textContent = 'Error (most likely not logged in)'; | |
tl.parentNode.className = 'error'; | |
} | |
} | |
var pdate, token; | |
CmdUtils.CreateCommand({ | |
name: Name, | |
synonyms: ['tweet'], | |
icon: Icon, | |
takes: {status: noun_arb_text}, | |
description: ''+<> | |
Sets your <a href={Twitter}>Twitter</a> status | |
using the web interface instead of the API.</>, | |
execute: function({text}){ | |
if(!token) return showError('No authenticity token.'); | |
if(!text) return showError('No status.'); | |
jQuery.ajax({ | |
type: 'POST', | |
url: Twitter +'status/update', | |
data: {status: text, authenticity_token: token, source: 'ubiquity'}, | |
error: ajaxError, | |
success: function(htm){ | |
var f = (jQuery((/<form [^]+?<\/form>/(htm) || 0)[0]) | |
.find('#latest_text_full')); | |
displayMessage({ | |
icon: Icon, | |
title: jQuery.trim(f.find('.status-text').text()), | |
text: f.find('.published').attr('title') })}}); | |
}, | |
preview: function(pbl, {text}){ | |
var size = text.length, date = new Date, doc = pbl.ownerDocument; | |
do var cn = doc.getElementById(Name); | |
while(!cn && (pdate = NaN, pbl.innerHTML = Base)); | |
if(text) cn.firstChild.innerHTML = ( | |
<><span class="status">{text}</span><span class={'size'} | |
><sup class={size > MaxLen ? 'excess' : ''} | |
>{size}</sup>/<sub>{MaxLen}</sub></span></>); | |
if(date - pdate < 6e4) return; | |
pdate = date; | |
cn.className += ' loading'; | |
jQuery.ajax({ | |
url: Twitter +'home', | |
error: ajaxError, | |
success: function(htm){ | |
setTL(cn.childNodes[1], htm); | |
}, | |
}); | |
}, | |
previewDelay: 0, | |
author: 'satyr'.link('http://ubigist.appjet.net/?o=satyr'), license: 'MIT', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment