Skip to content

Instantly share code, notes, and snippets.

@matthewfl
Created November 3, 2008 00:07
Show Gist options
  • Save matthewfl/21768 to your computer and use it in GitHub Desktop.
Save matthewfl/21768 to your computer and use it in GitHub Desktop.
Spellcheck for ubiquity
var conf = {
first_find: "spell=1\" class=p>",
last_find: "</a>",
correct: ""
};
CmdUtils.CreateCommand({
name: "spellcheck",
takes: {"Text To check": noun_arb_text},
preview: function(pblock, statusText) {
var text = statusText.text
if (text == "") text = CmdUtils.getSelection();
if(text == "") {
pblock.innerHTML = "(enter text the check the spelling of)";
return;
}
var url = 'http://www.google.com/search?q=' + text;
jQuery.get(url, null, function(page) {
var first = page.indexOf(conf.first_find);
if(first != -1) {
first+=conf.first_find.length;
var result = page.substring(first);
var last = result.indexOf(conf.last_find);
result = result.substring(0, last);
pblock.innerHTML = "Did you mean: " + result + "?";
result = result.replace(/<[bi]>/g,'').replace(/<\/[bi]>/g,'');
conf.correct = result;
}else{
pblock.innerHTML = "No spelling errors found."
conf.correct = "";
}
});
},
execute: function() {
CmdUtils.setSelection(conf.correct);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment