From 6f773133637758ebd869132d3a22b91c2c7c6c28 Mon Sep 17 00:00:00 2001 From: shinigami-eyes <43276258+shinigami-eyes@users.noreply.github.com> Date: Sun, 6 Oct 2019 14:29:26 +0200 Subject: [PATCH] Show confirmation after site labeling --- extension/background.ts | 15 +++++++++++++-- extension/content.ts | 17 +++++++++++++++++ extension/definitions.d.ts | 3 +++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/extension/background.ts b/extension/background.ts index 60a2d58..acc1c4b 100644 --- a/extension/background.ts +++ b/extension/background.ts @@ -457,7 +457,11 @@ function saveLabel(response: ShinigamiEyesSubmission) { getPendingSubmissions().push(response); submitPendingRatings(); //console.log(response); - browser.tabs.sendMessage(response.tabId, { updateAllLabels: true }); + browser.tabs.sendMessage(response.tabId, { + updateAllLabels: true, + confirmSetIdentifier: response.identifier, + confirmSetLabel: response.mark + }); //browser.tabs.executeScript(response.tabId, {code: 'updateAllLabels()'}); return; } @@ -501,7 +505,14 @@ browser.contextMenus.onClicked.addListener(function (info, tab) { // elementId: info.targetElementId, debug: overrides.debug }, { frameId: frameId }, response => { - if (!response.identifier) return; + if (!response.identifier){ + browser.tabs.sendMessage(response.tabId, { + updateAllLabels: true, + confirmSetIdentifier: response.identifier, + confirmSetLabel: response.mark + }); + return; + } if (response.mark) { if (badIdentifiers[response.identifier]) return; if (response.secondaryIdentifier && badIdentifiers[response.secondaryIdentifier]) diff --git a/extension/content.ts b/extension/content.ts index 7b51f51..8f9f284 100644 --- a/extension/content.ts +++ b/extension/content.ts @@ -530,10 +530,26 @@ function getSnippet(node: HTMLElement) { return null; } +function displayConfirmation(identifier: string, label: LabelKind){ + const confirmation = document.createElement('div'); + confirmation.style.cssText = 'position: fixed; padding: 15px; z-index: 99999999;'; + confirmation.textContent = identifier + ( + label == 't-friendly' ? ' will be displayed as trans-friendly' : + label == 'transphobic' ? ' will be displayed as anti-trans' : + ' has been cleared.' + ) + ' on search engines and social networks.' + document.body.appendChild(confirmation); + setTimeout(() => { + confirmation.remove(); + }, 3000); +} browser.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.updateAllLabels) { + if(!isSocialNetwork && message.confirmSetLabel){ + displayConfirmation(message.confirmSetIdentifier, message.confirmSetLabel); + } updateAllLabels(true); return; } @@ -569,5 +585,6 @@ browser.runtime.onMessage.addListener snippet.classList.remove(debugClass), 1500) } + message.isSocialNetwork = isSocialNetwork; sendResponse(message); }) \ No newline at end of file diff --git a/extension/definitions.d.ts b/extension/definitions.d.ts index 471cbe7..53fafbc 100644 --- a/extension/definitions.d.ts +++ b/extension/definitions.d.ts @@ -24,6 +24,7 @@ interface ShinigamiEyesSubmission { contextPage?: string linkId?: number snippet?: string + isSocialNetwork?: boolean } interface ShinigamiEyesCommand { acceptClicked?: boolean @@ -32,6 +33,8 @@ interface ShinigamiEyesCommand { updateAllLabels?: boolean closeCallingTab?: boolean setTheme?: string + confirmSetIdentifier?: string + confirmSetLabel?: LabelKind } type LabelMap = { [identifier: string]: LabelKind };