background.js (968B)
1 chrome.runtime.onInstalled.addListener(function() { 2 var parentMenu = chrome.contextMenus.create({"title": "Anotools", "id": "anotools", "visible": false}); 3 chrome.contextMenus.create({"title": "Outline.com", "id": "outline", "parentId": parent.id}) 4 chrome.contextMenus.create({"title": "Hypothes.is", "id": "hypothesis", "parentId": parent.id}) 5 }); 6 7 chrome.contextMenus.onClicked.addListener(function handleContextMenuClick(info, tab) { 8 function sanitize(url) { 9 return url.replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"'); 10 } 11 12 function outline(tab) { 13 var newUrl = "https://outline.com/"+sanitize(tab.url); 14 chrome.tabs.update(tab.id, {url: newUrl}); 15 } 16 17 function hypothesis(tab) { 18 var newUrl = "https://via.hypothes.is/"+sanitize(tab.url); 19 chrome.tabs.update(tab.id, {url: newUrl}); 20 } 21 22 var clickedId = info.menuItemId; 23 if (clickedId == "outline") { 24 outline(tab); 25 } 26 else { 27 hypothesis(tab); 28 } 29 });