Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions chromium/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {
browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
if (message.doubleClickInterval) {
doubleClickInterval = message.doubleClickInterval;
} else if (message.error) {
await showNotification('Error', message.error);
} else if (message.warning) {
await showNotification('Warning', message.warning);
}
});

Expand Down Expand Up @@ -225,19 +225,24 @@ async function handleDoubleClick() {
* @returns {Promise<void>}
*/
async function sendIdLinkCopyMessage(info, tab, category) {
browser.tabs.sendMessage(
tab.id,
{ category: category }, // this will be the first input to the onMessage listener
{ frameId: info.frameId },
async function (clickedElementId) {
// clickedElementId may be undefined, an empty string, or a non-empty string
const errStr = await scriptWriteLinkToClipboard(tab, clickedElementId);
if (errStr !== null) {
await showNotification('Error', errStr);
await brieflyShowX();
return new Promise(async (resolve, reject) => {
browser.tabs.sendMessage(
tab.id,
{ category: category }, // this will be the first input to the onMessage listener
{ frameId: info.frameId },
async function (clickedElementId) {
// clickedElementId may be undefined, an empty string, or a non-empty string
const errStr = await scriptWriteLinkToClipboard(tab, clickedElementId);
if (errStr !== null) {
await showNotification('Error', errStr);
await brieflyShowX();
reject(errStr);
} else {
resolve();
}
}
}
);
);
});
}

/**
Expand Down
10 changes: 5 additions & 5 deletions chromium/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,30 +202,30 @@ function createTextFragmentArg(selection) {
result = window.generateFragment(selection);
} catch (err) {
if (err.message !== 'window.generateFragment is not a function') {
browser.runtime.sendMessage({ error: err });
browser.runtime.sendMessage({ warning: err });
return '';
}
}

switch (result.status) {
case 1:
browser.runtime.sendMessage({
error: 'text fragment: the selection provided could not be used'
warning: 'The selection provided could not be used to create a text fragment'
});
return '';
case 2:
browser.runtime.sendMessage({
error: 'text fragment: no unique fragment could be identified for this selection'
warning: 'No unique text fragment could be identified for this selection'
});
return '';
case 3:
browser.runtime.sendMessage({
error: 'text fragment: computation could not complete in time'
warning: 'Text fragment computation could not complete in time'
});
return '';
case 4:
browser.runtime.sendMessage({
error: 'text fragment: an exception was raised during generation'
warning: 'An exception was raised during text fragment generation'
});
return '';
}
Expand Down
35 changes: 19 additions & 16 deletions firefox/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {
browser.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
if (message.doubleClickInterval) {
doubleClickInterval = message.doubleClickInterval;
} else if (message.error) {
await showNotification('Error', message.error);
} else if (message.warning) {
await showNotification('Warning', message.warning);
}
});

Expand Down Expand Up @@ -219,20 +219,23 @@ async function getClickedElementId(info, tab) {
* @returns {Promise<void>}
*/
async function sendIdLinkCopyMessage(info, tab, category) {
browser.tabs.sendMessage(
tab.id,
{ category: category }, // this will be the first input to the onMessage listener
{ frameId: info.frameId },
async function (clickedElementId) {
// clickedElementId may be undefined, an empty string, or a non-empty string
const linkFormat = await getSetting('linkFormat', 'blockquote');
const subBrackets = await getSetting('subBrackets', 'underlined');
const text = await createTabLinkMarkdown(
tab, clickedElementId, linkFormat, subBrackets, true,
);
await navigator.clipboard.writeText(text);
},
);
return new Promise(async (resolve, reject) => {
await browser.tabs.sendMessage(
tab.id,
{ category: category }, // this will be the first input to the onMessage listener
{ frameId: info.frameId },
async function (clickedElementId) {
// clickedElementId may be undefined, an empty string, or a non-empty string
const linkFormat = await getSetting('linkFormat', 'blockquote');
const subBrackets = await getSetting('subBrackets', 'underlined');
const text = await createTabLinkMarkdown(
tab, clickedElementId, linkFormat, subBrackets, true,
);
await navigator.clipboard.writeText(text);
resolve();
},
);
});
}

/**
Expand Down
10 changes: 5 additions & 5 deletions firefox/create-text-fragment-arg.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,30 @@ function createTextFragmentArg(selection) {
result = window.generateFragment(selection);
} catch (err) {
if (err.message !== 'window.generateFragment is not a function') {
browser.runtime.sendMessage({ error: err.message });
browser.runtime.sendMessage({ warning: err.message });
return '';
}
}

switch (result.status) {
case 1:
browser.runtime.sendMessage({
error: 'text fragment: the selection provided could not be used'
warning: 'The selection provided could not be used to create a text fragment'
});
return '';
case 2:
browser.runtime.sendMessage({
error: 'text fragment: no unique fragment could be identified for this selection'
warning: 'No unique text fragment could be identified for this selection'
});
return '';
case 3:
browser.runtime.sendMessage({
error: 'text fragment: computation could not complete in time'
warning: 'Text fragment computation could not complete in time'
});
return '';
case 4:
browser.runtime.sendMessage({
error: 'text fragment: an exception was raised during generation'
warning: 'An exception was raised during text fragment generation'
});
return '';
}
Expand Down