Skip to content

Instantly share code, notes, and snippets.

@ninoseki
Created June 25, 2018 22:59
Show Gist options
  • Save ninoseki/1c7cb8e9550f0c0799a83894f7bae760 to your computer and use it in GitHub Desktop.
Save ninoseki/1c7cb8e9550f0c0799a83894f7bae760 to your computer and use it in GitHub Desktop.
document.addEventListener('selectionchange', () => {
const selection: string = window.getSelection().toString().trim();
chrome.runtime.sendMessage({
request: 'updateContextMenu',
target: selection,
});
});
const links = document.getElementsByTagName('a');
for (const link of links) {
const RIGHT = 2;
link.addEventListener('mousedown', (e) => {
if (e.button === RIGHT) {
const selection = link.getAttribute('href');
if (selection !== null) {
chrome.runtime.sendMessage({
request: 'updateContextMenu',
target: selection,
});
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment