| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 "use strict"; | 1 "use strict"; |
| 2 | 2 |
| 3 (function() | 3 (function() |
| 4 { | 4 { |
| 5 if (typeof chrome == "undefined" || typeof chrome.extension == "undefined") | 5 if (typeof chrome == "undefined" || typeof chrome.extension == "undefined") |
| 6 window.chrome = browser; | 6 window.chrome = browser; |
| 7 const backgroundPage = chrome.extension.getBackgroundPage(); | 7 const backgroundPage = chrome.extension.getBackgroundPage(); |
| 8 window.ext = Object.create(backgroundPage.ext); | 8 window.ext = Object.create(backgroundPage.ext); |
| 9 | 9 |
| 10 window.ext.closePopup = () => | |
| 11 { | |
| 12 window.close(); | |
| 13 }; | |
| 14 | |
| 15 // Calling i18n.getMessage from the background page causes Edge to throw an | 10 // Calling i18n.getMessage from the background page causes Edge to throw an |
| 16 // exception. | 11 // exception. |
| 17 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/127939 75/ | 12 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/127939 75/ |
| 18 window.ext.i18n = chrome.i18n; | 13 window.ext.i18n = chrome.i18n; |
| 19 | 14 |
| 20 // We have to override ext.backgroundPage, because in order | 15 // We have to override ext.backgroundPage, because in order |
| 21 // to send messages the local "chrome" namespace must be used. | 16 // to send messages the local "chrome" namespace must be used. |
| 22 window.ext.backgroundPage = { | 17 window.ext.backgroundPage = { |
| 23 sendMessage: chrome.runtime.sendMessage, | 18 sendMessage: chrome.runtime.sendMessage, |
| 24 | 19 |
| 25 getWindow() | 20 getWindow() |
| 26 { | 21 { |
| 27 return backgroundPage; | 22 return backgroundPage; |
| 28 } | 23 } |
| 29 }; | 24 }; |
| 25 | |
| 26 window.ext.closePopup = () => | |
| 27 { | |
| 28 window.close(); | |
| 29 }; | |
|
Sebastian Noack
2017/09/13 02:49:39
While moving this function around anyway, how abou
Manish Jethani
2017/09/18 02:25:50
OK, this should happen naturally now after changes
| |
| 30 | |
| 31 window.ext.prefs = { | |
| 32 get(key, callback) | |
| 33 { | |
| 34 chrome.runtime.sendMessage({type: "prefs.get", key}, callback); | |
| 35 }, | |
| 36 toggle(key, callback) | |
| 37 { | |
| 38 chrome.runtime.sendMessage({type: "prefs.toggle", key}, callback); | |
| 39 } | |
| 40 }; | |
|
Sebastian Noack
2017/09/13 02:49:39
IMO, this doesn't belong into ext. Prefs are part
Manish Jethani
2017/09/18 02:25:50
I've moved it into popup.js now.
| |
| 41 | |
| 42 window.ext.createPageObject = tab => | |
| 43 { | |
| 44 if (!tab) | |
| 45 return null; | |
| 46 | |
| 47 // Create a lightweight page object that resembles ext.Page, but with only | |
| 48 // an id and an optional url property. | |
| 49 let page = {id: tab.id}; | |
| 50 | |
| 51 if (tab.url) | |
| 52 page.url = new URL(tab.url); | |
| 53 | |
| 54 return page; | |
| 55 }; | |
| 30 }()); | 56 }()); |
| OLD | NEW |