Minimal Chrome extension (8ko) that output the content of clipboard to a new tab

background.js 682B

12345678910111213141516171819202122
  1. var result = '';
  2. function getContentFromClipboard() {
  3. var sandbox = document.getElementById('sandbox');
  4. sandbox.value = '';
  5. sandbox.select();
  6. if (document.execCommand('paste'))
  7. result = sandbox.value;
  8. chrome.browserAction.setBadgeText({text: result.length.toString() });
  9. return result;
  10. }
  11. function onClickHandler() {
  12. window.open().document.write('<pre>' + getContentFromClipboard() + '</pre>');
  13. }
  14. chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
  15. if (request.event == 'copy') getContentFromClipboard();
  16. });
  17. chrome.browserAction.setBadgeText({ text: '' });
  18. chrome.browserAction.onClicked.addListener(onClickHandler);