1 <!-- 2 Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 3 source code is governed by a BSD-style license that can be found in the 4 LICENSE file. 5 --> 6 7 <script> 8 var selectedId = -1; 9 function refreshLanguage() { 10 chrome.tabs.detectLanguage(null, function(language) { 11 console.log(language); 12 if (language == " invalid_language_code") 13 language = "???"; 14 chrome.browserAction.setBadgeText({"text": language, tabId: selectedId}); 15 }); 16 } 17 18 chrome.tabs.onUpdated.addListener(function(tabId, props) { 19 if (props.status == "complete" && tabId == selectedId) 20 refreshLanguage(); 21 }); 22 23 chrome.tabs.onSelectionChanged.addListener(function(tabId, props) { 24 selectedId = tabId; 25 refreshLanguage(); 26 }); 27 28 chrome.tabs.getSelected(null, function(tab) { 29 selectedId = tab.id; 30 refreshLanguage(); 31 }); 32 </script> 33