From b0ab93d92151e18a73babd868ac4ff3639810575 Mon Sep 17 00:00:00 2001 From: "Ilya Ig. Petrov" Date: Sun, 28 May 2017 02:18:28 -0700 Subject: [PATCH] Add popup available on error --- .../src/extension-common/70-menu-items.js | 69 ++++++++++++++++++ .../src/extension-common/75-context-menus.js | 45 ++++++++++++ .../src/extension-common/80-context-menus.js | 72 ------------------- .../src/extension-common/manifest.tmpl.json | 5 +- .../pages/on-error-menu/index.html | 13 ++++ .../pages/on-error-menu/index.js | 30 ++++++++ .../src/extension-full/80-error-menu.js | 36 ++++++++++ ...block-informer.js => 85-block-informer.js} | 0 .../src/templates-data.js | 6 +- 9 files changed, 199 insertions(+), 77 deletions(-) create mode 100644 extensions/chromium/runet-censorship-bypass/src/extension-common/70-menu-items.js create mode 100644 extensions/chromium/runet-censorship-bypass/src/extension-common/75-context-menus.js delete mode 100644 extensions/chromium/runet-censorship-bypass/src/extension-common/80-context-menus.js create mode 100644 extensions/chromium/runet-censorship-bypass/src/extension-common/pages/on-error-menu/index.html create mode 100644 extensions/chromium/runet-censorship-bypass/src/extension-common/pages/on-error-menu/index.js create mode 100644 extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js rename extensions/chromium/runet-censorship-bypass/src/extension-full/{70-block-informer.js => 85-block-informer.js} (100%) diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/70-menu-items.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/70-menu-items.js new file mode 100644 index 0000000..aa6590b --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/70-menu-items.js @@ -0,0 +1,69 @@ +'use strict'; + +{ + + window.apis.menus = { + + getItemsAsObject: () => ({ + + hostTracker: { + title: 'Сайт доступен из-за границы? Is up?', + getUrl: (blockedUrl) => `data:text/html;charset=utf8,Запрашиваю... +
+ +
+ + + + diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/on-error-menu/index.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/on-error-menu/index.js new file mode 100644 index 0000000..3da2309 --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/on-error-menu/index.js @@ -0,0 +1,30 @@ +'use strict'; + +chrome.runtime.getBackgroundPage( (bgWindow) => + bgWindow.apis.errorHandlers.installListenersOn( + window, 'ERRM', async() => { + + const [currentTab] = await new Promise((resolve) => + chrome.tabs.query({ + active: true, + currentWindow: true, + }, resolve) + ); + + const itemsRoot = document.getElementById('menuItems'); + bgWindow.apis.menus.getItemsAsArray().forEach((item) => { + + const li = document.createElement('li'); + li.innerHTML = ` + ${item.title} + `; + li.querySelector('a').href = item.getUrl(currentTab.url); + itemsRoot.appendChild(li); + + }); + + document.documentElement.style.display = 'initial'; + + } + ) +); diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js b/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js new file mode 100644 index 0000000..aacff5d --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js @@ -0,0 +1,36 @@ +'use strict'; + +/* +window.chrome.browserAction.setBadgeBackgroundColor({ + color: '#db4b2f', +}); +*/ + +chrome.webNavigation.onErrorOccurred.addListener((details) => { + + const tabId = details.tabId; + if (!(tabId > 0)) { + alert(tabId); + return; + } + + //console.log('SETTING 2', details.tabId); + chrome.browserAction.setPopup({ + tabId, + popup: './pages/on-error-menu/index.html', + }); + + /* + window.chrome.browserAction.setBadgeBackgroundColor({ + tabId, + color: '#09f911', + }); + */ + + chrome.browserAction.setBadgeText({ + tabId, + text: '●●●', + }); + +}); + diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-full/70-block-informer.js b/extensions/chromium/runet-censorship-bypass/src/extension-full/85-block-informer.js similarity index 100% rename from extensions/chromium/runet-censorship-bypass/src/extension-full/70-block-informer.js rename to extensions/chromium/runet-censorship-bypass/src/extension-full/85-block-informer.js diff --git a/extensions/chromium/runet-censorship-bypass/src/templates-data.js b/extensions/chromium/runet-censorship-bypass/src/templates-data.js index 78f75ec..7d9d533 100644 --- a/extensions/chromium/runet-censorship-bypass/src/templates-data.js +++ b/extensions/chromium/runet-censorship-bypass/src/templates-data.js @@ -10,10 +10,10 @@ exports.contexts.full = Object.assign({}, commonContext, { versionSuffix: '', nameSuffixEn: '', nameSuffixRu: '', - extra_permissions: ', "webRequest"', + extra_permissions: ', "webRequest", "webNavigation"', persistent: '', scripts_2x: ', "20-ip-to-host-api.js"', - scripts_7x: ', "70-block-informer.js"', + scripts_8x: ', "80-error-menu.js", "85-block-informer.js"', }); exports.contexts.mini = Object.assign({}, commonContext, { @@ -23,6 +23,6 @@ exports.contexts.mini = Object.assign({}, commonContext, { extra_permissions: '', persistent: '"persistent": false,', scripts_2x: ', "20-for-mini-only.js"', - scripts_7x: '', + scripts_8x: '', });