From ed652ae452d19b0c561d1b674940758f308ae4d7 Mon Sep 17 00:00:00 2001 From: Nik Rolls Date: Thu, 20 Apr 2017 14:00:27 +1200 Subject: [PATCH] Edge compatibility --- extension/js/background.js | 8 ++++++-- extension/js/content.js | 8 ++++++-- extension/manifest.json | 10 ++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/extension/js/background.js b/extension/js/background.js index c5b223a..768b7d3 100644 --- a/extension/js/background.js +++ b/extension/js/background.js @@ -31,7 +31,7 @@ */ /*jshint eqeqeq:true, forin:true, strict:true */ -/*global chrome, console */ +/*global browser, chrome, console */ (function () { @@ -47,6 +47,10 @@ TYPE_NULL = 6 ; + function getBrowser() { + return typeof browser !== 'undefined' ? browser : chrome; + } + // Utility functions function removeComments (str) { str = ('__' + str + '__').split(''); @@ -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) ; diff --git a/extension/js/content.js b/extension/js/content.js index b930379..96a1812 100644 --- a/extension/js/content.js +++ b/extension/js/content.js @@ -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, @@ -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) { diff --git a/extension/manifest.json b/extension/manifest.json index da90eb7..11aacef 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -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": [""], "js": ["js/content.js"], "run_at": "document_start" }