Skip to content

Instantly share code, notes, and snippets.

@engalar
Last active August 9, 2022 09:24
Show Gist options
  • Save engalar/40229359c7f6113e8b91fda45b921283 to your computer and use it in GitHub Desktop.
Save engalar/40229359c7f6113e8b91fda45b921283 to your computer and use it in GitHub Desktop.
Surfingkeys
api.Front.registerInlineQuery({
url: function(q) {
return `http://dict.youdao.com/w/eng/${q}/#keyfrom=dict2.index`;
},
parseResult: function(res) {
var parser = new DOMParser();
var doc = parser.parseFromString(res.text, "text/html");
var collinsResult = doc.querySelector("#collinsResult");
var authTransToggle = doc.querySelector("#authTransToggle");
var examplesToggle = doc.querySelector("#examplesToggle");
if (collinsResult) {
collinsResult.querySelectorAll("div>span.collinsOrder").forEach(function(span) {
span.nextElementSibling.prepend(span);
});
collinsResult.querySelectorAll("div.examples").forEach(function(div) {
div.innerHTML = div.innerHTML.replace(/<p/gi, "<span").replace(/<\/p>/gi, "</span>");
});
var exp = collinsResult.innerHTML;
return exp;
} else if (authTransToggle) {
authTransToggle.querySelector("div.via.ar").remove();
return authTransToggle.innerHTML;
} else if (examplesToggle) {
return examplesToggle.innerHTML;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment