Skip to content

Commit

Permalink
Edge compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nicole-ashley committed Apr 20, 2017
1 parent e494f29 commit ed652ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 6 additions & 2 deletions extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/

/*jshint eqeqeq:true, forin:true, strict:true */
/*global chrome, console */
/*global browser, chrome, console */

(function () {

Expand All @@ -47,6 +47,10 @@
TYPE_NULL = 6
;

function getBrowser() {
return typeof browser !== 'undefined' ? browser : chrome;
}

// Utility functions
function removeComments (str) {
str = ('__' + str + '__').split('');
Expand Down Expand Up @@ -395,7 +399,7 @@
}

// Listen for requests from content pages wanting to set up a port
chrome.extension.onConnect.addListener(function(port) {
getBrowser().runtime.onConnect.addListener(function(port) {

if (port.name !== 'jf') {
console.log('JSON Formatter error - unknown port name '+port.name, port) ;
Expand Down
8 changes: 6 additions & 2 deletions extension/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@
*/

/*jshint eqeqeq:true, forin:true, strict:true */
/*global chrome, console */
/*global browser, chrome, console */

(function() {

"use strict" ;

function getBrowser() {
return typeof browser !== 'undefined' ? browser : chrome;
}

var jfContent,
pre,
jfStyleEl,
Expand All @@ -51,7 +55,7 @@

// Open the port "jf" now, ready for when we need it
// console.time('established port') ;
port = chrome.extension.connect({name: 'jf'}) ;
port = getBrowser().runtime.connect({name: 'jf'}) ;

// Add listener to receive response from BG when ready
port.onMessage.addListener( function (msg) {
Expand Down
10 changes: 6 additions & 4 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "JSON Formatter",
"version": "0.6.0",
"version": "0.6.1",
"manifest_version": 2,
"description": "Makes JSON easy to read. Open source.",
"homepage_url": "https://github.com/callumlocke/json-formatter",
"minimum_chrome_version": "21",
"homepage_url": "https://github.com/nikrolls/json-formatter",
"author": "Nik Rolls, Callum Locke",
"minimum_edge_version": "38",
"icons": {
"128": "icons/128.png",
"32": "icons/32.png"
},
"background": {
"scripts": ["js/background.js"]
"scripts": ["js/background.js"],
"persistent": true
},
"content_scripts": [
{ "matches": ["<all_urls>"], "js": ["js/content.js"], "run_at": "document_start" }
Expand Down

0 comments on commit ed652ae

Please sign in to comment.