Created
August 28, 2008 16:52
-
-
Save haoyayoi/7771 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
const WASSR_STATUS_MAXLEN = 255; | |
CmdUtils.CreateCommand({ | |
name: "wassr", | |
takes: {status: noun_arb_text}, | |
homepage: "http://wassr.jp", | |
author: {name: "haoyayoi", homepage: "http://d.hatena.ne.jp/hao_yayoi/"}, | |
license: "MPL", | |
preview: function(previewBlock, statusText) { | |
var previewTemplate = "Updates your Wassr status to: <br/>" + | |
"<b>${status}</b><br /><br />" + | |
"Characters remaining: <b>${chars}</b>"; | |
var truncateTemplate = "<br />The last <b>${truncate}</b> " + | |
"characters will be truncated!"; | |
var previewData = { | |
status: statusText.text, | |
chars: WASSR_STATUS_MAXLEN - statusText.text.length | |
}; | |
var previewHTML = CmdUtils.renderTemplate(previewTemplate, | |
previewData); | |
if(previewData.chars < 0) { | |
var truncateData = { | |
truncate: 0 - previewData.chars | |
}; | |
previewHTML += CmdUtils.renderTemplate(truncateTemplate, | |
truncateData); | |
} | |
previewBlock.innerHTML = previewHTML; | |
}, | |
execute: function(statusText) { | |
if(statusText.text.length < 1) { | |
displayMessage("Wassr requires a status to be entered"); | |
return; | |
} | |
var updateUrl = "http://api.wassr.jp/statuses/update.json"; | |
var updateParams = { | |
source: "ubiquity", | |
status: statusText.text | |
}; | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "json", | |
error: function() { | |
displayMessage("Wassr error - status not updated"); | |
}, | |
success: function() { | |
displayMessage("Wassr status updated"); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment