Added clipboard methods to the script API
This commit is contained in:
parent
f7a8aa17a8
commit
fb8acdda40
2 changed files with 17 additions and 0 deletions
|
@ -92,6 +92,11 @@ export default {
|
||||||
console.log('Selected element (DOM)', targetDOM);
|
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
|
// Anything returned from the function will be returned to the called
|
||||||
return 42;
|
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) => {
|
openTab: (url) => {
|
||||||
const port = browser.runtime.connect({ name: 'url' });
|
const port = browser.runtime.connect({ name: 'url' });
|
||||||
port.postMessage({
|
port.postMessage({
|
||||||
|
|
Loading…
Reference in a new issue