From e7ca14a6d5555c8ddf1745b6636992b790961403 Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 21 Nov 2020 17:50:58 +0300 Subject: [PATCH] restore CWS check in popup --- popup/popup.css | 2 +- popup/popup.js | 94 ++++++++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/popup/popup.css b/popup/popup.css index a4b8ae1e..ab6a351c 100644 --- a/popup/popup.css +++ b/popup/popup.css @@ -504,7 +504,7 @@ body > .actions { vertical-align: middle; } -body.blocked #installed > *, +body.blocked #installed > :not(.frame), body.blocked .actions > .main-controls { display: none; } diff --git a/popup/popup.js b/popup/popup.js index c1d0330e..dc092f96 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -129,7 +129,7 @@ async function initTabUrls() { } /** @param {chrome.webNavigation.GetAllFrameResultDetails[]} frames */ -function initPopup(frames) { +async function initPopup(frames) { installed = $('#installed'); setPopupWidth(); @@ -170,52 +170,52 @@ function initPopup(frames) { el.onclick = () => el.classList.toggle('expanded'); } - getActiveTab().then(function ping(tab, retryCountdown = 10) { - msg.sendTab(tab.id, {method: 'ping'}, {frameId: 0}) - .catch(() => false) - .then(pong => { - if (pong) { - return; - } - // FF and some Chrome forks (e.g. CentBrowser) implement tab-on-demand - // so we'll wait a bit to handle popup being invoked right after switching - if (retryCountdown > 0 && ( - tab.status !== 'complete' || - FIREFOX && tab.url === ABOUT_BLANK)) { - setTimeout(ping, 100, tab, --retryCountdown); - return; - } - const info = t.template.unreachableInfo; - if (!FIREFOX) { - // Chrome "Allow access to file URLs" in chrome://extensions message - info.appendChild($create('p', t('unreachableFileHint'))); - } - if (FIREFOX && tabURL.startsWith(URLS.browserWebStore)) { - $('label', info).textContent = t('unreachableAMO'); - const note = (FIREFOX < 59 ? t('unreachableAMOHintOldFF') : t('unreachableAMOHint')) + - (FIREFOX < 60 ? '' : '\n' + t('unreachableAMOHintNewFF')); - const renderToken = s => s[0] === '<' - ? $create('a', { - textContent: s.slice(1, -1), - onclick: handleEvent.copyContent, - href: '#', - className: 'copy', - tabIndex: 0, - title: t('copy'), - }) - : s; - const renderLine = line => $create('p', line.split(/(<.*?>)/).map(renderToken)); - const noteNode = $create('fragment', note.split('\n').map(renderLine)); - info.appendChild(noteNode); - } - // Inaccessible locally hosted file type, e.g. JSON, PDF, etc. - if (tabURL.length - tabURL.lastIndexOf('.') <= 5) { - info.appendChild($create('p', t('InaccessibleFileHint'))); - } - document.body.classList.add('unreachable'); - document.body.insertBefore(info, document.body.firstChild); - }); - }); + const isStore = tabURL.startsWith(URLS.browserWebStore); + if (isStore && !FIREFOX) { + blockPopup(); + return; + } + + for (let retryCountdown = 10; retryCountdown-- > 0;) { + const tab = await getActiveTab(); + if (await msg.sendTab(tab.id, {method: 'ping'}, {frameId: 0}).catch(() => {})) { + return; + } + if (tab.status === 'complete' && (!FIREFOX || tab.url !== ABOUT_BLANK)) { + break; + } + // FF and some Chrome forks (e.g. CentBrowser) implement tab-on-demand + // so we'll wait a bit to handle popup being invoked right after switching + await new Promise(resolve => setTimeout(resolve, 100)); + } + const info = t.template.unreachableInfo; + if (!FIREFOX) { + // Chrome "Allow access to file URLs" in chrome://extensions message + info.appendChild($create('p', t('unreachableFileHint'))); + } else if (isStore) { + $('label', info).textContent = t('unreachableAMO'); + const note = (FIREFOX < 59 ? t('unreachableAMOHintOldFF') : t('unreachableAMOHint')) + + (FIREFOX < 60 ? '' : '\n' + t('unreachableAMOHintNewFF')); + const renderToken = s => s[0] === '<' + ? $create('a', { + textContent: s.slice(1, -1), + onclick: handleEvent.copyContent, + href: '#', + className: 'copy', + tabIndex: 0, + title: t('copy'), + }) + : s; + const renderLine = line => $create('p', line.split(/(<.*?>)/).map(renderToken)); + const noteNode = $create('fragment', note.split('\n').map(renderLine)); + info.appendChild(noteNode); + } + // Inaccessible locally hosted file type, e.g. JSON, PDF, etc. + if (tabURL.length - tabURL.lastIndexOf('.') <= 5) { + info.appendChild($create('p', t('InaccessibleFileHint'))); + } + document.body.classList.add('unreachable'); + document.body.insertBefore(info, document.body.firstChild); } /** @param {chrome.webNavigation.GetAllFrameResultDetails} frame */