-
-
Save matthewfl/21768 to your computer and use it in GitHub Desktop.
Spellcheck for ubiquity
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
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