Text lookup
Jump to navigation
Jump to search
Red links can be selected or any text can be highlighted in a Wikipedia article or image description field to bring up a contextual search menu. The menu will in the first phase direct the user to that topic page. Later on it can be modified to make annotations that can be consumed by different projects.
var getSelectedText = function () {
var selectedText = ;
if (window.getSelection()) {
selectedText = window.getSelection();
} else if (document.getSelection()) {
selectedText = document.getSelection();
} else if (document.selection) {
selectedText = document.selection.createRange().text;
}
return selectedText;
};
window.addEventListener('mouseup', function () {
var result = getSelectedText();
// Now you can do whatever you want with your selected text
});