Browse Source

Initial commit

Adam 5 years ago
parent
commit
5ef5776ee1
2 changed files with 48 additions and 0 deletions
  1. 30 0
      background.js
  2. 18 0
      manifest.json

+ 30 - 0
background.js

@@ -0,0 +1,30 @@
+var allowed_domain = "2020census.gov";
+var redirect_url = "http://2020census.gov";
+
+function redirect(requestDetails) {
+	request_url = requestDetails.url;
+
+	var regex = new RegExp("^(?:http(?:s)?:\/\/)?(?:[^\.]+\.)?"+allowed_domain+"(/.*)?$");
+
+	// Check if within the same domain
+	if(request_url.match(regex)) {
+		// If within the domain
+		console.log('Request passed')
+	}
+	else
+	{
+		// If prohibited domain
+		console.log('Prohibitied Domain: ' + request_url)
+		return {
+			redirectUrl:  browser.runtime.getURL(redirect_url)
+		}
+	}
+}
+
+
+// Intercept all requests
+browser.webRequest.onBeforeSendHeaders.addListener (
+  redirect,
+  {urls:["<all_urls>"],types:["main_frame"]},
+  ["blocking"]
+);

+ 18 - 0
manifest.json

@@ -0,0 +1,18 @@
+// manifest.json
+
+{
+  "manifest_version": 2,
+  "name": "2020 Census Kiosk",
+  "version": "1.0",
+  "description": "Only allows access to http://2020Census.gov.",
+
+  "background": {
+    "scripts": ["background.js"]
+  },
+
+  "permissions": [
+    "<all_urls>",
+    "webRequest",
+    "webRequestBlocking"
+  ]
+}