From 544989bb388060a270c3ab14696c224cdb57e85e Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Wed, 12 Oct 2016 12:47:18 -0400 Subject: [PATCH 1/4] Add support for blacklisting file extensions --- css/options.css | 4 ++++ js/background.js | 17 ++++++++++++++++- js/options.js | 6 ++++++ options.html | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/css/options.css b/css/options.css index bbf3f42..9fa666f 100644 --- a/css/options.css +++ b/css/options.css @@ -12,6 +12,10 @@ select { margin-bottom: 10px; } +textarea { + margin-bottom: 10px; +} + pre { left: -10px; top: 10px; diff --git a/js/background.js b/js/background.js index 6192283..3f76fac 100644 --- a/js/background.js +++ b/js/background.js @@ -77,7 +77,8 @@ theme: 'sunburst', font: 'Inconsolata', fontSize: 'medium', - lineNumbers: true + lineNumbers: true, + extBlacklist: '' }; const OPTIONS = Object.keys(OPTIONS_DEFAULTS); @@ -121,6 +122,17 @@ return filename.split('.').pop(); } + function isExtensionBlacklisted(extension) { + var blacklist = localStorage.getItem('extBlacklist').split(/[\s,]+/); + var index, length = blacklist.length; + for (index = 0; index < length; index++) { + if (blacklist[index].toLowerCase() === extension) { + return true; + } + } + return false; + } + function getFragmentFromUrl(url) { var fragment = /#ft=(\w+)/.exec(url); return fragment && fragment[1]; @@ -130,6 +142,9 @@ if (BROWSER_CONTENT.indexOf(contentType) != -1) { return null; } + if (isExtensionBlacklisted(extension)) { + return null; + } return !!LANG_EXT_MAP[fragment] ? fragment : EXT_LANG_MAP[contentType] || EXT_LANG_MAP[extension] || EXT_LANG_MAP[filename]; diff --git a/js/options.js b/js/options.js index d5272ec..060afbd 100644 --- a/js/options.js +++ b/js/options.js @@ -43,6 +43,12 @@ codeEl.innerHTML = codeEl.textContent; hljs.highlightBlock(codeEl); } + }, + extBlacklist: { + selector: '#ext-blacklist', + value: 'value', + decode: id, + render: function(value) {} } }; diff --git a/options.html b/options.html index d1b00fc..f70c78b 100644 --- a/options.html +++ b/options.html @@ -91,6 +91,8 @@

Select your font size

+

Blacklist Extensions

+

Line numbers:

 package main

From 9c0d2f9b675d8893fd785ab3c73f632563ebdfbf Mon Sep 17 00:00:00 2001
From: Ilia Choly 
Date: Wed, 12 Oct 2016 13:12:56 -0400
Subject: [PATCH 2/4] Blacklist languages instead of extensions

---
 js/background.js | 13 +++++--------
 js/options.js    |  4 ++--
 options.html     |  4 ++--
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/js/background.js b/js/background.js
index 3f76fac..6d308fc 100644
--- a/js/background.js
+++ b/js/background.js
@@ -78,7 +78,7 @@
     font: 'Inconsolata',
     fontSize: 'medium',
     lineNumbers: true,
-    extBlacklist: ''
+    languageBlacklist: ''
   };
 
   const OPTIONS = Object.keys(OPTIONS_DEFAULTS);
@@ -122,11 +122,11 @@
     return filename.split('.').pop();
   }
 
-  function isExtensionBlacklisted(extension) {
-    var blacklist = localStorage.getItem('extBlacklist').split(/[\s,]+/);
+  function isLanguageBlacklisted(language) {
+    var blacklist = localStorage.getItem('languageBlacklist').split(/[\s,]+/);
     var index, length = blacklist.length;
     for (index = 0; index < length; index++) {
-      if (blacklist[index].toLowerCase() === extension) {
+      if (blacklist[index].toLowerCase() === language) {
         return true;
       }
     }
@@ -142,9 +142,6 @@
     if (BROWSER_CONTENT.indexOf(contentType) != -1) {
       return null;
     }
-    if (isExtensionBlacklisted(extension)) {
-      return null;
-    }
     return !!LANG_EXT_MAP[fragment] ?  fragment : EXT_LANG_MAP[contentType] ||
                                                   EXT_LANG_MAP[extension]   ||
                                                   EXT_LANG_MAP[filename];
@@ -171,7 +168,7 @@
     var filename = getFilenameFromUrl(details.url);
     var extension = getExtensionFromFilename(filename);
     var language = detectLanguage(contentType, fragment, filename, extension);
-    if (!language) {
+    if (!language || isLanguageBlacklisted(language)) {
       return;
     }
 
diff --git a/js/options.js b/js/options.js
index 060afbd..105af9b 100644
--- a/js/options.js
+++ b/js/options.js
@@ -44,8 +44,8 @@
         hljs.highlightBlock(codeEl);
       }
     },
-    extBlacklist: {
-      selector: '#ext-blacklist',
+    languageBlacklist: {
+      selector: '#language-blacklist',
       value: 'value',
       decode: id,
       render: function(value) {}
diff --git a/options.html b/options.html
index f70c78b..2b9fd6e 100644
--- a/options.html
+++ b/options.html
@@ -91,8 +91,8 @@ 

Select your font size

-

Blacklist Extensions

- +

Blacklist Languages

+

Line numbers:

 package main

From fd47f24b00020b51ba5ee61cb7816f1146adf04c Mon Sep 17 00:00:00 2001
From: Ilia Choly 
Date: Wed, 12 Oct 2016 17:49:26 -0400
Subject: [PATCH 3/4] add noop function

---
 js/options.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/js/options.js b/js/options.js
index 105af9b..14c3650 100644
--- a/js/options.js
+++ b/js/options.js
@@ -2,6 +2,7 @@
   function id(a) { return a }
   function eq(b) { return function(a) { return a === b } }
   function val(obj, key) { return obj[key] }
+  function noop() {}
   function set(sel, path, fn) {
     var parts = path.split('.');
     var target = parts[parts.length-1];
@@ -48,7 +49,7 @@
       selector: '#language-blacklist',
       value: 'value',
       decode: id,
-      render: function(value) {}
+      render: noop
     }
   };
 

From fd362f3bcf9800dc1fb6985eee0e5218c6cc59d8 Mon Sep 17 00:00:00 2001
From: Ilia Choly 
Date: Mon, 17 Oct 2016 11:45:35 -0400
Subject: [PATCH 4/4] Rename 'blacklist' to 'ignore'

---
 js/background.js | 12 ++++++------
 js/options.js    |  4 ++--
 options.html     |  4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/js/background.js b/js/background.js
index 6d308fc..92bc039 100644
--- a/js/background.js
+++ b/js/background.js
@@ -78,7 +78,7 @@
     font: 'Inconsolata',
     fontSize: 'medium',
     lineNumbers: true,
-    languageBlacklist: ''
+    ignoreLanguages: ''
   };
 
   const OPTIONS = Object.keys(OPTIONS_DEFAULTS);
@@ -122,11 +122,11 @@
     return filename.split('.').pop();
   }
 
-  function isLanguageBlacklisted(language) {
-    var blacklist = localStorage.getItem('languageBlacklist').split(/[\s,]+/);
-    var index, length = blacklist.length;
+  function isLanguageIgnored(language) {
+    var ignored = localStorage.getItem('ignoreLanguages').split(/[\s,]+/);
+    var index, length = ignored.length;
     for (index = 0; index < length; index++) {
-      if (blacklist[index].toLowerCase() === language) {
+      if (ignored[index].toLowerCase() === language) {
         return true;
       }
     }
@@ -168,7 +168,7 @@
     var filename = getFilenameFromUrl(details.url);
     var extension = getExtensionFromFilename(filename);
     var language = detectLanguage(contentType, fragment, filename, extension);
-    if (!language || isLanguageBlacklisted(language)) {
+    if (!language || isLanguageIgnored(language)) {
       return;
     }
 
diff --git a/js/options.js b/js/options.js
index 14c3650..5dd2f94 100644
--- a/js/options.js
+++ b/js/options.js
@@ -45,8 +45,8 @@
         hljs.highlightBlock(codeEl);
       }
     },
-    languageBlacklist: {
-      selector: '#language-blacklist',
+    ignoreLanguages: {
+      selector: '#ignore-languages',
       value: 'value',
       decode: id,
       render: noop
diff --git a/options.html b/options.html
index 2b9fd6e..77b7bf4 100644
--- a/options.html
+++ b/options.html
@@ -91,8 +91,8 @@ 

Select your font size

-

Blacklist Languages

- +

Ignore Languages

+

Line numbers:

 package main