diff --git a/packages/browser-extension/src/scripts/snackbar.js b/packages/browser-extension/src/scripts/snackbar.js new file mode 100644 index 0000000..fcfc3cd --- /dev/null +++ b/packages/browser-extension/src/scripts/snackbar.js @@ -0,0 +1,97 @@ +/** + * @description Listens to messages + */ + +chrome.runtime.onMessage.addListener((message) => { + switch (message.type) { + case 'HIDE_REPORT_CONFIRMATION': + hideReportConfirmation(); + break; + case 'SHOW_REPORT_CONFIRMATION': + showReportConfirmation(); + break; + default: + break; + } +}); + +/** + * @description Report confirmation ID + */ + +const REPORT_CONFIRMATION_ID = 'report-confirmation'; + +/** + * @description Report confirmation outer HTML + */ + +const REPORT_CONFIRMATION_HTML = ` +
+
+
+ + ${chrome.i18n.getMessage('reportText')} +
+
+ `; + +/** + * @description Hides report confirmation + */ + +const hideReportConfirmation = () => { + document.getElementById(REPORT_CONFIRMATION_ID)?.setAttribute('hidden', 'true'); +}; + +/** + * @description Shows report confirmation + */ + +const showReportConfirmation = () => { + const element = document.getElementById(REPORT_CONFIRMATION_ID); + + if (element) { + element.removeAttribute('hidden'); + } else { + const parser = new DOMParser(); + const result = parser.parseFromString(REPORT_CONFIRMATION_HTML, 'text/html'); + const snackbar = result.body.firstElementChild; + + document.body.appendChild(snackbar); + } + + setTimeout(() => hideReportConfirmation(), 3750); +}; diff --git a/packages/browser-extension/src/styles/snackbar.css b/packages/browser-extension/src/styles/snackbar.css new file mode 100644 index 0000000..12f3e46 --- /dev/null +++ b/packages/browser-extension/src/styles/snackbar.css @@ -0,0 +1,65 @@ +#report-confirmation { + bottom: 30px; + font-family: 'Lato', Arial, Helvetica, sans-serif !important; + min-width: 250px; + position: fixed; + right: 10px; + text-align: left; + visibility: hidden; + z-index: 99999; +} + +#report-confirmation:not([hidden]) { + animation: fadeIn 0.5s, fadeOut 0.5s 3.5s; + visibility: visible !important; +} + +#report-confirmation:not([hidden]) #report-confirmation-bar { + animation: roundTime 3.5s linear forwards; +} + +#report-confirmation-content { + align-items: center; + background-color: #34495e !important; + border-radius: 2px; + color: #fff !important; + display: flex; + font-size: 14px !important; + gap: 16px; + overflow: hidden; + padding: 16px; +} + +#report-confirmation-bar { + background-color: #3dd9eb !important; + height: 4px; + transform-origin: left center; +} + +@keyframes fadeIn { + from { + bottom: 0; + opacity: 0; + } + to { + bottom: 30px; + opacity: 1; + } +} + +@keyframes fadeOut { + from { + bottom: 30px; + opacity: 1; + } + to { + bottom: 0; + opacity: 0; + } +} + +@keyframes roundTime { + to { + transform: scaleX(0); + } +}