Skip to content

Commit

Permalink
Notification improvements (last longer, allow text selection) (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Mar 27, 2023
1 parent 5c6e02c commit 2874463
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions source/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function handlePortListenerErrors(listener) {
await listener(port);
} catch (error) {
let {message} = error;
console.log({message});
if ([
'Failed to fetch',
'Load failed', // Safari
Expand Down
12 changes: 10 additions & 2 deletions source/ghost-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ function registerElements() {

function getMessageDisplayTime(message) {
const wpm = 100; // 180 is the average words read per minute, make it slower
return message.split(' ').length / wpm * 60_000;
// Add reaction time
return 2000 + (message.split(' ').length / wpm * 60_000);
}

function notify(type, message, timeout = getMessageDisplayTime(message)) {
Expand All @@ -281,7 +282,14 @@ function notify(type, message, timeout = getMessageDisplayTime(message)) {
timeout,
addnCls: type === 'log' ? '' : 'ghost-text-message-error',
});
document.addEventListener('click', () => notification.remove(), {once: true});
document.addEventListener('click', () => {
// Allow selections
if (!window.getSelection().isCollapsed) {
return;
}

notification.remove();
}, {once: true});
}

function startGT() {
Expand Down

0 comments on commit 2874463

Please sign in to comment.