From d09255a6b81f14a2f4751bda8853038f71730267 Mon Sep 17 00:00:00 2001
From: Jason Barnabe <jason.barnabe@gmail.com>
Date: Thu, 29 Jan 2015 12:44:29 -0600
Subject: [PATCH]  Apply to file: protocol #25

---
 background.js | 9 ++++++---
 manifest.json | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/background.js b/background.js
index a5f0e8cf..9a59f095 100644
--- a/background.js
+++ b/background.js
@@ -47,7 +47,7 @@ function getStyles(options, callback) {
 			if (id != null && style.id != id) {
 				return false;
 			}
-			if (matchUrl != null && getApplicableSections(style, matchUrl) == 0) {
+			if (matchUrl != null && getApplicableSections(style, matchUrl).length == 0) {
 				return false;
 			}
 			return true;
@@ -132,8 +132,8 @@ function getApplicableSections(style, url) {
 }
 
 function sectionAppliesToUrl(section, url) {
-	// only http and https allowed
-	if (url.indexOf("http") != 0) {
+	// only http, https, and file allowed
+	if (url.indexOf("http") != 0 && url.indexOf("file") != 0) {
 		return false;
 	}
 	if (!section.urls && !section.domains && !section.urlPrefixes && !section.regexps) {
@@ -286,6 +286,9 @@ function saveFromJSONStyleReloaded(updateType, style, callback) {
 }
 
 function getDomains(url) {
+	if (url.indexOf("file:") == 0) {
+		return [];
+	}
 	var d = /.*?:\/*([^\/]+)/.exec(url)[1];
 	var domains = [d];
 	while (d.indexOf(".") != -1) {
diff --git a/manifest.json b/manifest.json
index 25634105..d395488d 100644
--- a/manifest.json
+++ b/manifest.json
@@ -19,7 +19,7 @@
 	},
 	"content_scripts": [
 		{
-			"matches": ["http://*/*", "https://*/*"],
+			"matches": ["http://*/*", "https://*/*", "file:///*"],
 			"run_at": "document_start",
 			"all_frames": true,
 			"js": ["apply.js"]