I am trying to trigger a search on a Mediawiki site upon double click on a word but it does not work. This is what added in Common.js.
document.addEventListener("dblclick", function () {
var w = String(window.getSelection());
if (w) browser.runtime.sendMessage(null, { searchFor: w, dblClick: true });
});
function doSearch(word) {
if (!word) return;
word = word.replace(/[\r\n ]+/g, " ").trim();
if (!word || word.length > 70) return;
browser.tabs.create({
"url": "https://lsj.gr/index.php?search=" + encodeURIComponent(word)
});
}
I don't see doSearch being called. If you add it to your event listener, then things might work as you expect:
document.addEventListener("dblclick", function () {
var w = String(window.getSelection());
if (w){
browser.runtime.sendMessage(null, { searchFor: w, dblClick: true });
doSearch(w)
}
});
Maybe try window.open()
Working example
document.addEventListener("dblclick", function () {
var w = String(window.getSelection());
if (w){
window.open("https://www.mediawiki.org/w/index.php?search=" + encodeURIComponent(w) )
}
});