I made a very simple chrome extension which allows users to highlight a DOI number, right-click and choose \"Resolve DOI\", and it sends them to the associated web page. Right n
You would need to control content menu creation from a content script. Dynamic menu creation/deletion should execute pretty fast and the delay will be unnoticeable for a user.
Something along those lines (not tested):
content_script.js:
document.addEventListener("mousedown", function(event){
var selection = window.getSelection().toString();
if(selection.match(/^10\./)) {
chrome.extension.sendRequest({cmd: "create_menu"});
} else {
chrome.extension.sendRequest({cmd: "delete_menu"});
}
}, true);
background.html:
chrome.extension.onRequest.addListener(function(request) {
if(request.cmd == "create_menu") {
chrome.contextMenus.removeAll(function() {
chrome.contextMenus.create({
"title" : "Resolve DOI",
"type" : "normal",
"contexts" : ["selection"],
"onclick" : getClickHandler()
});
});
} else if(request.cmd == "delete_menu") {
chrome.contextMenus.removeAll();
}
});