Add selected text to notes
This commit is contained in:
@@ -5,10 +5,29 @@ const reData = new RegExp('^data:(.*?);base64,(.*)$');
|
|||||||
async function handleClick(tab, e) {
|
async function handleClick(tab, e) {
|
||||||
const imgURL = await browser.tabs.captureTab(tab.id);
|
const imgURL = await browser.tabs.captureTab(tab.id);
|
||||||
|
|
||||||
|
const selecteds = await browser.tabs.executeScript(
|
||||||
|
tab.id,
|
||||||
|
{
|
||||||
|
code: 'getSelection().toString()',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const selected = selecteds.filter(x => x).join('\n');
|
||||||
|
|
||||||
|
let noteParts = [
|
||||||
|
`<body>`,
|
||||||
|
`<a href="${encodeURI(tab.url)}">${escapeHTML(tab.url)}</a>`,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (selected) {
|
||||||
|
noteParts.push(`\n\n${escapeHTML(selected)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
noteParts.push('</body>');
|
||||||
|
|
||||||
const store = {};
|
const store = {};
|
||||||
store[`create_${crypto.randomUUID()}`] = {
|
store[`create_${crypto.randomUUID()}`] = {
|
||||||
name: tab.title,
|
name: tab.title,
|
||||||
html_notes: `<body><a href="${encodeURI(tab.url)}">${escapeHTML(tab.url)}</a></body>`,
|
html_notes: noteParts.join(''),
|
||||||
attach: imgURL,
|
attach: imgURL,
|
||||||
filename: 'screenshot.png',
|
filename: 'screenshot.png',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user