From 2874463cb1ab184077a7a3b25fe6ad1117bafdcb Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Mon, 27 Mar 2023 22:09:15 +0800 Subject: [PATCH] Notification improvements (last longer, allow text selection) (#281) --- source/background.js | 1 + source/ghost-text.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/source/background.js b/source/background.js index ba87066..d3a8258 100644 --- a/source/background.js +++ b/source/background.js @@ -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 diff --git a/source/ghost-text.js b/source/ghost-text.js index fd8f296..d2b9958 100644 --- a/source/ghost-text.js +++ b/source/ghost-text.js @@ -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)) { @@ -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() {