Browse Source

add icons; ping check the proxy before setting

Andrew Dolgov 2 years ago
parent
commit
68a1c9814a
6 changed files with 136 additions and 4 deletions
  1. 61 2
      background.js
  2. 7 0
      common.js
  3. 59 0
      img/icon.svg
  4. BIN
      img/icon128.png
  5. BIN
      img/icon16.png
  6. 9 2
      manifest.json

+ 61 - 2
background.js

@@ -25,13 +25,72 @@ function auth_callback(details) {
 	return {};
 }
 
+function set_title(title) {
+	chrome.browserAction.setTitle({title: title});
+}
+
+function set_badge(text, color) {
+	chrome.browserAction.setBadgeText({text: text});
+
+	if (color)
+		chrome.browserAction.setBadgeBackgroundColor({color: color});
+
+}
+
+function ping() {
+
+	try {
+		var settings = JSON.parse(localStorage.settings);
+		var url = 'https://' + settings.url;
+
+		var req = new XMLHttpRequest();
+
+		req.open('POST', url, true);
+		req.onreadystatechange = function() {
+
+			if (req.readyState == 4) {
+				if (req.status == 400) {
+					set_badge("ok", 'green');
+					set_title("Connected");
+
+					localStorage["proxy_reachable"] = "1";
+				} else {
+					set_badge('err', 'red');
+					set_title("Connection failed");
+
+					localStorage["proxy_reachable"] = "0";
+				}
+			}
+
+			set_proxy();
+		}
+		req.send(null);
+	} catch (e) {
+		set_badge('err', 'red');
+		set_title("Configuration error");
+		localStorage["proxy_reachable"] = 0;
+	}
+
+}
+
 chrome.webRequest.onAuthRequired.addListener(
 	auth_callback,
 	{urls: ["<all_urls>"]},
 	['blocking'] );
 
-set_proxy();
 update_whitelist();
+ping();
+
+chrome.browserAction.onClicked.addListener(function(tab) {
+	ping();
+});
+
+setInterval(function() {
+	update_whitelist();
+}, 3600 * 1000 );
+
+setInterval(function() {
+	ping();
+}, 60 * 1000);
 
-setInterval(function() { update_whitelist(); }, 1000 * 60 * 60 );
 

+ 7 - 0
common.js

@@ -44,6 +44,13 @@ function generate_pac() {
 
 function set_proxy() {
 
+	if (localStorage["proxy_reachable"] != "1") {
+		console.log("proxy set as unreachable, not changing anything");
+		return;
+	} else {
+		console.log("setting proxy...");
+	}
+
 	var pac = generate_pac();
 
 	if (!pac) return;

+ 59 - 0
img/icon.svg

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   id="cloud"
+   viewBox="0 0 1024 1234"
+   width="64"
+   height="64"
+   version="1.1"
+   inkscape:version="0.91 r13725"
+   sodipodi:docname="Cloud.svg"
+   inkscape:export-filename="C:\Users\andrew\Downloads\Cloud16.png"
+   inkscape:export-xdpi="22.5"
+   inkscape:export-ydpi="22.5">
+  <metadata
+     id="metadata9">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <defs
+     id="defs7" />
+  <sodipodi:namedview
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1920"
+     inkscape:window-height="1137"
+     id="namedview5"
+     showgrid="false"
+     inkscape:zoom="3.6875"
+     inkscape:cx="32"
+     inkscape:cy="32"
+     inkscape:window-x="-8"
+     inkscape:window-y="-8"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="cloud"
+     inkscape:snap-page="false" />
+  <path
+     d="m 768,1001 -544,0 q -93,0 -158.5,-65.49999 -65.5,-65.5 -65.5,-158.5 0,-57 27,-106 27,-49 73,-80 34,69 96.5,116.5 62.5,47.5 139.5,62.5 -66,-38 -105,-104 -39,-66 -39,-145 0,-119 84.5,-203.5 84.5,-84.5 203.5,-84.5 88,0 159.5,48 71.5,48 104.5,126 -68,22 -118,73.5 -50,51.5 -70,121.5 35,-52 91,-82.5 56,-30.5 121,-30.5 106,0 181,75 75,75 75,181 0,106 -75,181 Q 874,1001 768,1001 Z"
+     id="path3"
+     style="fill:#4f45a6;fill-opacity:1"
+     inkscape:connector-curvature="0" />
+</svg>

BIN
img/icon128.png


BIN
img/icon16.png


+ 9 - 2
manifest.json

@@ -1,6 +1,6 @@
 {
   "name": "Selective HTTPS proxy",
-  "version": "0.2",
+  "version": "0.3",
   "manifest_version": 2,
   "description": "Routes specified domains via HTTPS proxy",
   "permissions": [ "proxy", "unlimitedStorage", 
@@ -9,5 +9,12 @@
   "background": {
         "scripts": [ "common.js", "background.js" ]
     },
-  "options_page": "options.html"
+  "options_page": "options.html",
+  "browser_action": {
+	  "default_icon": "img/icon16.png"
+  },
+  "icons": { 
+	  "16": "img/icon16.png",
+	  "128": "img/icon128.png"
+  }
 }