Added clipboard methods to the script API

dependabot/npm_and_yarn/prismjs-1.21.0
Fabio Manganiello 2 years ago
parent f7a8aa17a8
commit fb8acdda40
  1. 5
      examples/example.js
  2. 12
      src/script.js

@ -92,6 +92,11 @@ export default {
console.log('Selected element (DOM)', targetDOM);
}
// Read and set the clipboard with getClipboard/setClipboard
const text = await app.getClipboard();
console.log('Text in clipboard', text);
await app.setClipboard(`<p>${text}</p>`);
// Anything returned from the function will be returned to the called
return 42;
},

@ -36,6 +36,18 @@ export default {
});
},
getClipboard: () => {
return new Promise((resolve, reject) => {
navigator.clipboard.readText().then(text => resolve(text), error => reject(error));
});
},
setClipboard: (text) => {
return new Promise((resolve, reject) => {
navigator.clipboard.writeText(text).then(() => resolve(), error => reject(error));
});
},
openTab: (url) => {
const port = browser.runtime.connect({ name: 'url' });
port.postMessage({

Loading…
Cancel
Save