Created
June 4, 2018 03:27
-
-
Save ar1a/ed206575136f85972ecba1882c6c3c5a to your computer and use it in GitHub Desktop.
Ctrl+click to copy from lastpass fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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