Skip to content

Instantly share code, notes, and snippets.

@ar1a
Created June 4, 2018 03:27
Show Gist options
  • Save ar1a/ed206575136f85972ecba1882c6c3c5a to your computer and use it in GitHub Desktop.
Save ar1a/ed206575136f85972ecba1882c6c3c5a to your computer and use it in GitHub Desktop.
Ctrl+click to copy from lastpass fields
// ==UserScript==
// @name Lastpass copier
// @namespace ar1as.space/lastpass
// @match https://lastpass.com/*
// ==/UserScript==
'use strict';
const copyToClipboard = target => {
const { type, selectionStart, selectionEnd } = target;
target.type = 'text';
target.focus();
target.select();
document.execCommand('copy');
target.type = type;
target.setSelectionRange(selectionStart, selectionEnd);
};
(() => {
const observer = new MutationObserver((records, observer) => {
for (const { addedNodes } of records) {
for (const node of addedNodes) {
if (node.id == 'siteDialog') {
node.addEventListener('click', ({ target, button, ctrlKey }) => {
if (button == 0 && ctrlKey)
if (
target.id === 'siteDialogPassword' ||
target.id === 'siteDialogUsername'
) {
copyToClipboard(target);
}
});
observer.disconnect();
}
}
}
});
observer.observe(document.body, { childList: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment