Show confirmation after site labeling

This commit is contained in:
shinigami-eyes 2019-10-06 14:29:26 +02:00
parent ce74cda636
commit 6f77313363
3 changed files with 33 additions and 2 deletions

View File

@ -457,7 +457,11 @@ function saveLabel(response: ShinigamiEyesSubmission) {
getPendingSubmissions().push(response); getPendingSubmissions().push(response);
submitPendingRatings(); submitPendingRatings();
//console.log(response); //console.log(response);
browser.tabs.sendMessage(response.tabId, { updateAllLabels: true }); browser.tabs.sendMessage(response.tabId, <ShinigamiEyesCommand>{
updateAllLabels: true,
confirmSetIdentifier: response.identifier,
confirmSetLabel: response.mark
});
//browser.tabs.executeScript(response.tabId, {code: 'updateAllLabels()'}); //browser.tabs.executeScript(response.tabId, {code: 'updateAllLabels()'});
return; return;
} }
@ -501,7 +505,14 @@ browser.contextMenus.onClicked.addListener(function (info, tab) {
// elementId: info.targetElementId, // elementId: info.targetElementId,
debug: <any>overrides.debug debug: <any>overrides.debug
}, { frameId: frameId }, response => { }, { frameId: frameId }, response => {
if (!response.identifier) return; if (!response.identifier){
browser.tabs.sendMessage(response.tabId, <ShinigamiEyesCommand>{
updateAllLabels: true,
confirmSetIdentifier: response.identifier,
confirmSetLabel: response.mark
});
return;
}
if (response.mark) { if (response.mark) {
if (badIdentifiers[response.identifier]) return; if (badIdentifiers[response.identifier]) return;
if (response.secondaryIdentifier && badIdentifiers[response.secondaryIdentifier]) if (response.secondaryIdentifier && badIdentifiers[response.secondaryIdentifier])

View File

@ -530,10 +530,26 @@ function getSnippet(node: HTMLElement) {
return null; 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<ShinigamiEyesMessage, ShinigamiEyesSubmission>((message, sender, sendResponse) => { browser.runtime.onMessage.addListener<ShinigamiEyesMessage, ShinigamiEyesSubmission>((message, sender, sendResponse) => {
if (message.updateAllLabels) { if (message.updateAllLabels) {
if(!isSocialNetwork && message.confirmSetLabel){
displayConfirmation(message.confirmSetIdentifier, message.confirmSetLabel);
}
updateAllLabels(true); updateAllLabels(true);
return; return;
} }
@ -569,5 +585,6 @@ browser.runtime.onMessage.addListener<ShinigamiEyesMessage, ShinigamiEyesSubmiss
if (message.debug <= 1) if (message.debug <= 1)
setTimeout(() => snippet.classList.remove(debugClass), 1500) setTimeout(() => snippet.classList.remove(debugClass), 1500)
} }
message.isSocialNetwork = isSocialNetwork;
sendResponse(message); sendResponse(message);
}) })

View File

@ -24,6 +24,7 @@ interface ShinigamiEyesSubmission {
contextPage?: string contextPage?: string
linkId?: number linkId?: number
snippet?: string snippet?: string
isSocialNetwork?: boolean
} }
interface ShinigamiEyesCommand { interface ShinigamiEyesCommand {
acceptClicked?: boolean acceptClicked?: boolean
@ -32,6 +33,8 @@ interface ShinigamiEyesCommand {
updateAllLabels?: boolean updateAllLabels?: boolean
closeCallingTab?: boolean closeCallingTab?: boolean
setTheme?: string setTheme?: string
confirmSetIdentifier?: string
confirmSetLabel?: LabelKind
} }
type LabelMap = { [identifier: string]: LabelKind }; type LabelMap = { [identifier: string]: LabelKind };