From 04d5dd23467f2edbbbc975302ba35a2537fefe73 Mon Sep 17 00:00:00 2001 From: "Ilya Ig. Petrov" Date: Sun, 10 Apr 2016 10:39:11 +0100 Subject: [PATCH] fixed urls in context menus --- .../1-sync-pac-script-with-pac-provider.js | 10 ++-- .../extension/2-block-informer.js | 20 +++---- .../extension/3-context-menus.js | 57 ++++++++++--------- 3 files changed, 46 insertions(+), 41 deletions(-) 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 57c5826..c4c790b 100644 --- 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 @@ -17,12 +17,12 @@ window.antiCensorRu = { // PUBLIC - + version: chrome.runtime.getManifest().version, pacProviders: { Антизапрет: { - pacUrl: 'http://antizapret.prostovpn.org/proxy.pac', + pacUrl: 'https://antizapret.prostovpn.org/proxy.pac', proxyHosts: ['proxy.antizapret.prostovpn.org'], proxyIps: { '195.154.110.37': 'proxy.antizapret.prostovpn.org', @@ -37,8 +37,8 @@ window.antiCensorRu = { } }, Оба_и_на_свитчах: { - //pacUrl: 'https://drive.google.com/uc?export=download&id=0B-ZCVSvuNWf0akpCOURNS2VCTmc', - pacUrl: 'https://drive.google.com/uc?export=download&id=0B-ZCVSvuNWf0WGczNmJzY3gzMWc', + pacUrl: 'https://drive.google.com/uc?export=download&id=0B-ZCVSvuNWf0akpCOURNS2VCTmc', + //pacUrl: 'https://drive.google.com/uc?export=download&id=0B-ZCVSvuNWf0WGczNmJzY3gzMWc', // Beta proxyHosts: ['proxy.antizapret.prostovpn.org', 'gw2.anticenz.org'], proxyIps: { '195.154.110.37': 'proxy.antizapret.prostovpn.org', @@ -109,7 +109,7 @@ window.antiCensorRu = { (err, res) => { if (err) return reject(err); - + this.lastPacUpdateStamp = Date.now(); this.ifFirstInstall = false; this.setAlarms(); diff --git a/extensions/chromium/minimalistic-pac-setter/extension/2-block-informer.js b/extensions/chromium/minimalistic-pac-setter/extension/2-block-informer.js index bc4f96c..29c54fb 100644 --- a/extensions/chromium/minimalistic-pac-setter/extension/2-block-informer.js +++ b/extensions/chromium/minimalistic-pac-setter/extension/2-block-informer.js @@ -14,10 +14,10 @@ window.tabWithError2ip = {}; // For errors only: Error? -> Check this IP! -function getHostname(url) { - var a = document.createElement('a'); +function createLink(url) { + const a = document.createElement('a'); a.href = url; - return a.hostname; + return a; } +function() { @@ -38,7 +38,7 @@ function getHostname(url) { } chrome.tabs.onUpdated.addListener( onTabUpdate ); - + function isInsideTabWithIp(requestDetails) { return requestDetails.tabId !== -1 && requestDetails.ip } @@ -72,7 +72,7 @@ function getHostname(url) { } ) ); - + return true; function updateTitle(requestDetails, cb) { @@ -82,8 +82,8 @@ function getHostname(url) { title => { var ifTitleSetAlready = /\n/.test(title); var proxyHost = window.antiCensorRu.pacProvider.proxyIps[ requestDetails.ip ]; - - var hostname = getHostname( requestDetails.url ); + + var hostname = createLink( requestDetails.url ).hostname; var ifShouldUpdateTitle = false; var indent = ' '; @@ -99,7 +99,7 @@ function getHostname(url) { }); } else { - var hostsProxiesPair = title.split(proxyTitle); + const hostsProxiesPair = title.split(proxyTitle); if (hostsProxiesPair[1].indexOf(proxyHost) === -1) { title = title.replace(hostsProxiesPair[1], hostsProxiesPair[1] +'\n'+ indent + proxyHost); @@ -109,7 +109,7 @@ function getHostname(url) { if (hostsProxiesPair[0].indexOf(hostname) === -1) { title = title.replace(proxyTitle, indent + hostname +'\n'+ proxyTitle); ifShouldUpdateTitle = true; - + var _cb = cb; cb = () => chrome.browserAction.getBadgeText( {tabId: requestDetails.tabId}, @@ -144,4 +144,4 @@ function getHostname(url) { { urls: [''] } ); -}(); \ No newline at end of file +}(); diff --git a/extensions/chromium/minimalistic-pac-setter/extension/3-context-menus.js b/extensions/chromium/minimalistic-pac-setter/extension/3-context-menus.js index 8de5c9d..92b9e85 100644 --- a/extensions/chromium/minimalistic-pac-setter/extension/3-context-menus.js +++ b/extensions/chromium/minimalistic-pac-setter/extension/3-context-menus.js @@ -2,44 +2,49 @@ +function() { - var createMenuLinkEntry = (title, tab2url) => chrome.contextMenus.create({ + const createMenuLinkEntry = (title, tab2url) => chrome.contextMenus.create({ title: title, contexts: ['browser_action'], onclick: (menuInfo, tab) => Promise.resolve( tab2url( tab ) ).then( url => chrome.tabs.create({url: url}) ) }); - createMenuLinkEntry( 'Сайт доступен из-за границы? Is up?', tab => 'http://isup.me/'+ getHostname(tab.url) ); + const removeProtocol = (url) => { + const link = createLink(url); + return link.href.replace( link.protocol + '//', '' ); + }; + + createMenuLinkEntry( 'Сайт доступен из-за границы? Is up?', tab => 'http://isup.me/'+ createLink(tab.url).hostname ); window.reestrUrl = 'http://reestr.rublacklist.net/search/?q='; createMenuLinkEntry( 'Сайт в реестре блокировок?', tab => { - const ifIp = confirm('Да = искать по IP.\nНет = искать по домену.'); - const hostname = getHostname( tab.url ); - if (ifIp) { - var ip = window.tabWithError2ip[tab.id]; - if ( /^[.\d]+$/.test(hostname) || /^[:\dA-Fa-f]+$/.test(hostname) ) - ip = hostname; - return ip - ? reestrUrl + ip - : chrome.extension.getURL('./pages/is-ip-blocked/index.html') +'?'+ hostname - } - return reestrUrl + hostname - }); + const ifIp = confirm('Да = искать по IP.\nНет = искать по домену.'); + const hostname = createLink( tab.url ).hostname; + if (ifIp) { + var ip = window.tabWithError2ip[tab.id]; + if ( /^[.\d]+$/.test(hostname) || /^[:\dA-Fa-f]+$/.test(hostname) ) + ip = hostname; + return ip + ? reestrUrl + ip + : chrome.extension.getURL('./pages/is-ip-blocked/index.html') +'?'+ hostname + } + return reestrUrl + hostname + }); - createMenuLinkEntry( 'Из кэша Google', tab => 'https://webcache.googleusercontent.com/search?q=cache:'+ tab.url ); + createMenuLinkEntry( 'Из кэша Google', tab => 'https://webcache.googleusercontent.com/search?q=cache:' + removeProtocol(tab.url) ); - createMenuLinkEntry( 'Из архива archive.org', tab => 'https://web-beta.archive.org/web/submit?url='+ tab.url ); + createMenuLinkEntry( 'Из архива archive.org', tab => 'https://web.archive.org/web/*/' + removeProtocol(tab.url) ); - createMenuLinkEntry( 'Свежий снимок страницы', tab => ` - data:text/html;charset=utf8,Чиииз... -
- - - -
- ` - ); + createMenuLinkEntry( 'Свежий снимок страницы, Screenshot machine', tab => ` + data:text/html;charset=utf8,Screenshot machine +
+ + + +
+ ` + ); - createMenuLinkEntry( 'Разблокировать страницу по-другому', tab => chrome.extension.getURL('./pages/other-unblocks/index.html') +'?'+ tab.url ); + createMenuLinkEntry( 'Разблокировать страницу по-другому', tab => chrome.extension.getURL('./pages/other-unblocks/index.html') +'?'+ removeProtocol(tab.url) ); }();