diff --git a/extensions/chromium/minimalistic-pac-setter/extension/1-sync-pac-script-with-pac-provider.js b/extensions/chromium/minimalistic-pac-setter/extension/1-sync-pac-script-with-pac-provider.js index e2d5001..4910b6a 100755 --- a/extensions/chromium/minimalistic-pac-setter/extension/1-sync-pac-script-with-pac-provider.js +++ b/extensions/chromium/minimalistic-pac-setter/extension/1-sync-pac-script-with-pac-provider.js @@ -155,7 +155,8 @@ (pushErr) => cb(pacErr || ipsErr || pushErr, pacRes) ); - } + }, + cb ); }, @@ -346,6 +347,37 @@ } + function setPac(pacData, cb) { + + const config = { + mode: 'pac_script', + pacScript: { + mandatory: false, + data: pacData + } + }; + console.log('Setting chrome proxy settings...'); + chrome.proxy.settings.set( {value: config}, () => { + + const err = checkChromeError(); + if (err) { + return cb(err); + } + chrome.proxy.settings.get({}, (details) => { + + const ifThis = details.levelOfControl.startsWith('controlled_by_this'); + if (!ifThis) { + console.warn('Failed, other extension is in control.'); + return cb({clarification: {message:'Настройки прокси контролирует другое расширение. Какое?'}}); + } + console.log('Successfuly set PAC in proxy settings..'); + return cb(); + }); + + }); + + } + function httpGet(url, cb) { const start = Date.now(); @@ -518,16 +550,7 @@ }; return cb(err); } - - const config = { - mode: 'pac_script', - pacScript: { - mandatory: false, - data: pacData - } - }; - console.log('Setting chrome proxy settings...'); - chrome.proxy.settings.set( {value: config}, chromified(cb) ); + setPac(pacData, cb); } ); @@ -548,3 +571,9 @@ window.addEventListener('unhandledrejection', (event) => { throw event.reason; }); + +chrome.proxy.settings.onChange.addListener((details) => { + + console.log('Settings changed:', details); + +}); diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.html b/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.html index 7e0fa9e..30118fa 100755 --- a/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.html +++ b/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.html @@ -50,8 +50,9 @@
Загрузка...
+ diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.js b/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.js index 3b12ea2..f2148be 100755 --- a/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.js +++ b/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.js @@ -1,29 +1,27 @@ 'use strict'; -chrome.runtime.getBackgroundPage( backgroundPage => { +chrome.runtime.getBackgroundPage( (backgroundPage) => { - function getStatus() { + const getStatus = () => document.querySelector('#status'); - return document.querySelector('#status'); - - } - - function setStatusTo(msg) { + const setStatusTo = (msg) => { const status = getStatus(); if (msg) { status.classList.remove('off'); status.innerHTML = msg; - } else + } + else { status.classList.add('off'); + } - } + }; const antiCensorRu = backgroundPage.antiCensorRu; // SET DATE - function setDate() { + const setDate = () => { let dateForUser = 'никогда'; if( antiCensorRu.lastPacUpdateStamp ) { @@ -52,7 +50,7 @@ chrome.runtime.getBackgroundPage( backgroundPage => { dateElement.innerText = dateForUser; dateElement.title = new Date(antiCensorRu.lastPacUpdateStamp).toLocaleString('ru-RU'); - } + }; setDate(); chrome.storage.onChanged.addListener( (changes) => changes.lastPacUpdateStamp.newValue && setDate() ); @@ -83,12 +81,12 @@ chrome.runtime.getBackgroundPage( backgroundPage => { } const ul = document.querySelector('#list-of-providers'); - //const _firstChild = ul.firstChild; - for( const providerKey of Object.keys(antiCensorRu.pacProviders) ) { + const _firstChild = ul.firstChild; + for( const providerKey of Object.keys(antiCensorRu.pacProviders).sort() ) { const li = document.createElement('li'); li.innerHTML = ' [обновить]'; li.querySelector('.link-button').onclick = () => { triggerChosenProvider(); return false; }; - ul.insertBefore( li, ul.firstChild ); + ul.insertBefore( li, _firstChild ); } const radios = [].slice.apply( document.querySelectorAll('[name=pacProvider]') ); @@ -99,10 +97,13 @@ chrome.runtime.getBackgroundPage( backgroundPage => { if (pacKey === 'none') return antiCensorRu.clearPac(); - function enableDisableInputs() { + const enableDisableInputs = function () { + const inputs = document.querySelectorAll('input'); - for (const i = 0; i < inputs.length; i++) + for ( let i = 0; i < inputs.length; i++ ) { inputs[i].disabled = !inputs[i].disabled; + } + } enableDisableInputs(); @@ -120,31 +121,27 @@ chrome.runtime.getBackgroundPage( backgroundPage => { let clarification = err.clarification; do { message = message +' '+ (clarification && clarification.message || err.message || ''); - clarification = clarification.prev; + clarification = clarification && clarification.prev; } while( clarification ); message = message.trim(); setStatusTo( `${ifNotCritical ? 'Некритичная ошибка.' : 'Ошибка!'}
${message} +
[Ещё подробнее]` ); getStatus().querySelector('.link-button').onclick = function() { const div = document.createElement('div'); + backgroundPage.console.log('ERROR', err); div.innerHTML = ` Более подробную информацию можно узнать из логов фоновой страницы:
-chrome://extensions › Это расширение › Отладка страниц: фоновая страница › Console (DevTools) +chrome://extensions › Это расширение › Отладка страниц: фоновая страница › Console (DevTools)
Ещё: ${JSON.stringify({err: err, stack: err.stack})} `; getStatus().replaceChild(div, this); - div.querySelector('.ext').onclick = () => { - - chrome.tabs.create({ url: 'chrome://extensions?id='+ chrome.runtime.id }); - return false; - - } return false; }; @@ -156,11 +153,8 @@ chrome.runtime.getBackgroundPage( backgroundPage => { setStatusTo(''); checkChosenProvider(); - if (antiCensorRu.ifFirstInstall) + if (antiCensorRu.ifFirstInstall) { triggerChosenProvider(); - - // Debug - - document.querySelector('#debug-link').onclick = () => chrome.tabs.create({ url: chrome.extension.getURL('./pages/debug/index.html') }); + } }); diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/keep-links-clickable.js b/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/keep-links-clickable.js new file mode 100644 index 0000000..8f12e4b --- /dev/null +++ b/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/keep-links-clickable.js @@ -0,0 +1,29 @@ +'use strict'; +/* +In popup links are not clickable at all, fix it. +On other pages "chrome://" links are not clickable, fix it. +Use only if really required because of performance penalty. +*/ + +const target = document.getElementById('status'); + +const updateLinks = () => { + + const links = document.querySelectorAll('a:not([href=""])'); + for (let i = 0; i < links.length; i++) { + const ln = links[i]; + const location = ln.href; + ln.onclick = function () { + + chrome.tabs.create({ active: !this.dataset.inBg, url: location }); + return false; + + }; + } + +}; + +new MutationObserver( updateLinks ) + .observe(target, { attributes: false, subtree: true, childList: true, characterData: false }); + +document.addEventListener('DOMContentLoaded', updateLinks); diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/index.html b/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/index.html index 14dd0ce..42ab7e8 100644 --- a/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/index.html +++ b/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/index.html @@ -18,7 +18,10 @@ height: 100%; } nav { - text-align: center; + padding: 0.2em; + } + #status { + padding-left: 0.5em; } @@ -26,9 +29,10 @@ -
Press READ button.
- - +
+ + diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/index.js b/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/index.js index 52c1342..7e6c8d7 100644 --- a/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/index.js +++ b/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/index.js @@ -1,22 +1,35 @@ 'use strict'; -const editor = ace.edit("editor"); +const setStatusTo = (msg) => document.getElementById('status').innerHTML = msg; + +const red = (text) => '' + text + ''; + +const editor = ace.edit('editor'); editor.getSession().setOptions({ mode: "ace/mode/javascript", useSoftTabs: true }); +chrome.proxy.settings.onChange.addListener( (details) => setStatusTo(red( details.levelOfControl + '!') ) ); + document.querySelector('#read-button').onclick = () => { chrome.proxy.settings.get({}, (details) => { - editor.setValue( details.value.pacScript.data ); + let control = details.levelOfControl; + if (control.startsWith('controlled_by_other')) { + control = red(control); + } + setStatusTo(control); + console.log(details); + const pac = details.value.pacScript; + const data = pac && pac.data || 'PAC скрипт не установлен.'; + editor.setValue( data ); }); }; - document.querySelector('#save-button').onclick = () => { const config = { diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/ace.js b/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/vendor/ace-editor/ace.js similarity index 100% rename from extensions/chromium/minimalistic-pac-setter/extension/pages/debug/ace.js rename to extensions/chromium/minimalistic-pac-setter/extension/pages/debug/vendor/ace-editor/ace.js diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/ext-searchbox.js b/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/vendor/ace-editor/ext-searchbox.js similarity index 100% rename from extensions/chromium/minimalistic-pac-setter/extension/pages/debug/ext-searchbox.js rename to extensions/chromium/minimalistic-pac-setter/extension/pages/debug/vendor/ace-editor/ext-searchbox.js diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/mode-javascript.js b/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/vendor/ace-editor/mode-javascript.js similarity index 100% rename from extensions/chromium/minimalistic-pac-setter/extension/pages/debug/mode-javascript.js rename to extensions/chromium/minimalistic-pac-setter/extension/pages/debug/vendor/ace-editor/mode-javascript.js diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/worker-javascript.js b/extensions/chromium/minimalistic-pac-setter/extension/pages/debug/vendor/ace-editor/worker-javascript.js similarity index 100% rename from extensions/chromium/minimalistic-pac-setter/extension/pages/debug/worker-javascript.js rename to extensions/chromium/minimalistic-pac-setter/extension/pages/debug/vendor/ace-editor/worker-javascript.js