├── .gitignore ├── icons └── icon128.png ├── README.md ├── background.js ├── manifest.json └── inject.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /icons/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/igrigorik/netinfo-monitor/HEAD/icons/icon128.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Network Information Monitor 2 | 3 | Displays network quality, as reported by Network Information API. 4 | 5 | ![image](https://user-images.githubusercontent.com/10652/32406625-f85652b2-c138-11e7-975c-b78f7699471e.png) 6 | -------------------------------------------------------------------------------- /background.js: -------------------------------------------------------------------------------- 1 | chrome.runtime.onMessage.addListener( 2 | function(request, sender, sendResponse) { 3 | console.log(sender.tab ? 4 | "from a content script:" + sender.tab.url : 5 | "from the extension: " + request); 6 | 7 | chrome.browserAction.setBadgeText({ 8 | text: request.ect 9 | }); 10 | chrome.browserAction.setBadgeBackgroundColor({ 11 | color: "#F00" 12 | }); 13 | 14 | sendResponse(); 15 | } 16 | ); 17 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Network Quality", 3 | "version": "0.0.1", 4 | "manifest_version": 2, 5 | "description": "Displays network quality as reported by Network Information API.", 6 | "homepage_url": "https://github.com/igrigorik/netinfo", 7 | "icons": { 8 | "128": "icons/icon128.png" 9 | }, 10 | "background": { 11 | "scripts": [ 12 | "background.js" 13 | ], 14 | "persistent": true 15 | }, 16 | "browser_action": { 17 | "default_icon": "icons/icon128.png", 18 | "default_title": "NQE" 19 | }, 20 | "permissions": [ 21 | "https://*/*" 22 | ], 23 | "content_scripts": [ 24 | { 25 | "all_frames": false, 26 | "matches": [ 27 | "https://*/*" 28 | ], 29 | "js": [ 30 | "inject.js" 31 | ] 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /inject.js: -------------------------------------------------------------------------------- 1 | chrome.extension.sendMessage({}, function(response) { 2 | 3 | function updateECT(newECT) { 4 | chrome.runtime.sendMessage({ 5 | ect: newECT 6 | }, function(response) { 7 | console.log("Acked.") 8 | }); 9 | } 10 | 11 | var readyStateCheckInterval = setInterval(function() { 12 | if (document.readyState === "complete") { 13 | clearInterval(readyStateCheckInterval); 14 | 15 | updateECT(navigator.connection.effectiveType); 16 | navigator.connection.addEventListener('change', function() { 17 | console.dir("Connection change: ", navigator.connection); 18 | if (navigator.onLine) { 19 | updateECT(navigator.connection.effectiveType); 20 | } 21 | else { 22 | updateECT("X"); 23 | } 24 | }); 25 | } 26 | }, 10); 27 | }); 28 | --------------------------------------------------------------------------------