diff --git a/README.md b/README.md index 0fa5959..832768b 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Provides user with tab related stats/data * Memory usage displayed on panel UI (JSON or Plain) * Preference to include url on memory usage panel UI * Prepend, append or disable tab memory usage in title +* Change tab title color if memory exceeds specified threshold * Preference to set interval between memory usage collection * Top 5 memory consumers drawn on graph * Graph types include: Line, Bar, Radar and PolarArea diff --git a/addon/data/html/view.html b/addon/data/html/view.html index cb13fd6..781345d 100644 --- a/addon/data/html/view.html +++ b/addon/data/html/view.html @@ -121,6 +121,14 @@

+ + + + + + + + diff --git a/addon/data/js/controller.js b/addon/data/js/controller.js index 344fdcb..54ae2b6 100644 --- a/addon/data/js/controller.js +++ b/addon/data/js/controller.js @@ -16,6 +16,7 @@ document.getElementById('memoryTracking').addEventListener("change", function (e document.getElementById('memoryUsageOnTabTitles').disabled = false; document.getElementById('memoryFormat').disabled = false; document.getElementById('memoryUrlInUsage').disabled = false; + document.getElementById('memoryCautionThreshold').disabled = false; document.getElementById('graphType').disabled = false; } else { @@ -25,6 +26,7 @@ document.getElementById('memoryTracking').addEventListener("change", function (e document.getElementById('memoryUsageOnTabTitles').disabled = true; document.getElementById('memoryFormat').disabled = true; document.getElementById('memoryUrlInUsage').disabled = true; + document.getElementById('memoryCautionThreshold').disabled = true; document.getElementById('graphType').disabled = true; document.getElementById("memoryDump").textContent = ''; @@ -36,6 +38,15 @@ document.getElementById('schedulePreciseGC').addEventListener("click", function self.port.emit("schedulePreciseGC", ''); }, false); +document.getElementById('memoryCautionThreshold').onkeyup = function (event) { + if (parseInt(document.getElementById('memoryCautionThreshold').value) >= 0) { + self.port.emit("memoryCautionThreshold", document.getElementById('memoryCautionThreshold').value); + document.getElementById('memoryCautionThreshold').className = 'green'; + } else { + document.getElementById('memoryCautionThreshold').className = 'red'; + } +}; + tabdata_helper.inputValueChanged('panelHeight', 185); tabdata_helper.inputValueChanged('panelWidth', 45); tabdata_helper.inputValueChanged('memoryInterval', 0); @@ -60,6 +71,7 @@ self.port.on("stats", function (stats) { document.getElementById("memoryUsageOnTabTitles").value = parsedStats.memoryUsageOnTabTitles; document.getElementById("memoryFormat").value = parsedStats.memoryFormat; document.getElementById("memoryUrlInUsage").checked = parsedStats.memoryUrlInUsage; + document.getElementById("memoryCautionThreshold").value = parsedStats.memoryCautionThreshold; document.getElementById("panelWidth").value = parsedStats.panelWidth; document.getElementById("panelHeight").value = parsedStats.panelHeight; document.getElementById("graphType").value = parsedStats.graphType; diff --git a/addon/lib/Panel.js b/addon/lib/Panel.js index f0fb182..aebec42 100644 --- a/addon/lib/Panel.js +++ b/addon/lib/Panel.js @@ -28,6 +28,7 @@ exports.init = function () { memoryFormat: Preference.get("memoryFormat"), memoryUsageOnTabTitles: Preference.get("memoryUsageOnTabTitles"), memoryUrlInUsage: Preference.get("memoryUrlInUsage"), + memoryCautionThreshold: Preference.get("memoryCautionThreshold"), panelWidth: Preference.get("panelWidth"), panelHeight: Preference.get("panelHeight"), graphType: Preference.get("graphType") @@ -73,6 +74,10 @@ exports.init = function () { Tab.updateMemoryCounters(); }); + panel.port.on("memoryCautionThreshold", function (value) { + Preference.set('memoryCautionThreshold', value); + }); + panel.port.on("schedulePreciseGC", function (value) { Chrome.gc(panel); }); diff --git a/addon/lib/Tab.js b/addon/lib/Tab.js index 454a2c6..f18adee 100644 --- a/addon/lib/Tab.js +++ b/addon/lib/Tab.js @@ -3,6 +3,7 @@ var tabs = require("sdk/tabs"), Preference = require("./Preference"), Panel = require("./Panel"), Chrome = require("./Chrome"), + WindowUtils = require("./WindowUtils"), sessionCount = 0, currentCount = 0, markedTabs = [], @@ -243,9 +244,14 @@ function initFinishReporting() { if (repl.indexOf(tab.url) >= 0) { - /*if (JSON.parse(markedTabs[j]).amount >= (Preference.get('memoryCautionThreshold') * 1000000)) { - console.log('CAUTION! ' + tab.title + ': ' + JSON.parse(markedTabs[j]).amount); - }*/ + if (JSON.parse(markedTabs[j]).amount >= (Preference.get('memoryCautionThreshold') * 1000000)) { + + styleTab(repl, 'red'); + + } else { + + styleTab(repl, ''); + } // format data for panel memoryDump.push({ @@ -377,3 +383,25 @@ function initFinishReporting() { Panel.get().port.emit("memoryDump", payload); }; } + +function styleTab(currentUrl, color) { + + var allWindows = WindowUtils.getWindows(); + + for (var h = 0; h < allWindows.length; h++) { // loop all windows + + if (allWindows[h].gBrowser && allWindows[h].gBrowser.tabContainer) { + var browserTabs = allWindows[h].gBrowser.tabContainer.childNodes; + + for (var q = 0; q < browserTabs.length; q++) { // loop all tabs within window + + var browser = allWindows[h].gBrowser.getBrowserForTab(browserTabs[q]); + + if (currentUrl === browser.currentURI.spec) { + + browserTabs[q].style.color = color; + } + } + } + } +} diff --git a/addon/lib/WindowUtils.js b/addon/lib/WindowUtils.js new file mode 100644 index 0000000..9528635 --- /dev/null +++ b/addon/lib/WindowUtils.js @@ -0,0 +1,7 @@ +var window_utils = require('sdk/window/utils'); + +exports.getWindows = function () { + return window_utils.windows(null, { + includePrivate: true + }); +}; diff --git a/addon/locale/bg.properties b/addon/locale/bg.properties index ccf1d9f..98749bc 100644 --- a/addon/locale/bg.properties +++ b/addon/locale/bg.properties @@ -29,6 +29,7 @@ memoryFormat_title=Формат на използването на паметт memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Plain +memoryCautionThreshold_title=праг Memory повишено внимание? (В мегабайти) showUrl_title=Show Url на използване на паметта панел? garbageCollection_title=Извършване на събиране на боклука run_title=Run diff --git a/addon/locale/cs-CZ.properties b/addon/locale/cs-CZ.properties index b1a3b75..99ede9f 100644 --- a/addon/locale/cs-CZ.properties +++ b/addon/locale/cs-CZ.properties @@ -29,6 +29,7 @@ memoryFormat_title=Formát využití paměti na desce? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Plain +memoryCautionThreshold_title=Memory práh opatrnost? (V MB) showUrl_title=Zobrazit URL na využití panelu paměti? garbageCollection_title=Provést úklid run_title=Run diff --git a/addon/locale/de-DE.properties b/addon/locale/de-DE.properties index 90a2776..6b91678 100644 --- a/addon/locale/de-DE.properties +++ b/addon/locale/de-DE.properties @@ -29,6 +29,7 @@ memoryFormat_title=Format der Speichernutzung auf Holz? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Plain +memoryCautionThreshold_title=Speicher Vorsicht Schwelle? (In MB) showUrl_title=Anzeige URL auf die Speichernutzung Platte? garbageCollection_title=Führen Sie eine Garbage Collection run_title=Run diff --git a/addon/locale/en-GB.properties b/addon/locale/en-GB.properties index de354f0..2003f4e 100644 --- a/addon/locale/en-GB.properties +++ b/addon/locale/en-GB.properties @@ -28,6 +28,7 @@ memoryUsageOnTabTitlesPref_options.Disable=Disable memoryFormat_title=Format of memory usage on panel? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Plain +memoryCautionThreshold_title=Memory caution threshold? (In megabytes) showUrl_title=Show Url on memory usage panel? garbageCollection_title=Perform a garbage collection diff --git a/addon/locale/en-US.properties b/addon/locale/en-US.properties index de354f0..cb50ed6 100644 --- a/addon/locale/en-US.properties +++ b/addon/locale/en-US.properties @@ -29,6 +29,7 @@ memoryFormat_title=Format of memory usage on panel? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Plain +memoryCautionThreshold_title=Memory caution threshold? (In megabytes) showUrl_title=Show Url on memory usage panel? garbageCollection_title=Perform a garbage collection run_title=Run diff --git a/addon/locale/es-ES.properties b/addon/locale/es-ES.properties index c364778..05472fe 100644 --- a/addon/locale/es-ES.properties +++ b/addon/locale/es-ES.properties @@ -29,6 +29,7 @@ memoryFormat_title=Formato de uso de memoria en el panel? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Llanura +memoryCautionThreshold_title=umbral de precaución de memoria? (En megabytes) showUrl_title=Mostrar URL en el panel de uso de la memoria? garbageCollection_title=Realizar una recolección de basura run_title=Run diff --git a/addon/locale/fr-FR.properties b/addon/locale/fr-FR.properties index 7b8592f..8123067 100644 --- a/addon/locale/fr-FR.properties +++ b/addon/locale/fr-FR.properties @@ -29,6 +29,7 @@ memoryFormat_title=Format d'utilisation de la mémoire sur le panneau? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Plaine +memoryCautionThreshold_title=Mémoire seuil de précaution? (En mégaoctets) showUrl_title=Montrer URL sur le panneau d'utilisation de la mémoire? garbageCollection_title=Effectuer une collecte des ordures run_title=Run diff --git a/addon/locale/it-IT.properties b/addon/locale/it-IT.properties index fa91341..466fc1a 100644 --- a/addon/locale/it-IT.properties +++ b/addon/locale/it-IT.properties @@ -29,6 +29,7 @@ memoryFormat_title=Formato di utilizzo della memoria sul pannello? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Plain +memoryCautionThreshold_title=Memoria soglia prudenza? (In megabyte) showUrl_title=Mostra URL sul pannello di utilizzo della memoria? garbageCollection_title=Eseguire una garbage collection run_title=Run diff --git a/addon/locale/ja-JP.properties b/addon/locale/ja-JP.properties index 88c68e8..4293956 100644 --- a/addon/locale/ja-JP.properties +++ b/addon/locale/ja-JP.properties @@ -29,6 +29,7 @@ memoryFormat_title=パネル上のメモリ使用量の形式? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=平野 +memoryCautionThreshold_title=メモリ注意スレッショルド? (メガバイト単位) showUrl_title=のURLを表示? garbageCollection_title=ガベージコレクションを実行します run_title=ラン diff --git a/addon/locale/ko-KR.properties b/addon/locale/ko-KR.properties index d7b9226..4598bee 100644 --- a/addon/locale/ko-KR.properties +++ b/addon/locale/ko-KR.properties @@ -29,6 +29,7 @@ memoryFormat_title=패널에 메모리 사용량의 형식? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=일반 +memoryCautionThreshold_title=메모리주의 임계 값? (메가 바이트) showUrl_title=표시메모리 사용량 패널 URL? garbageCollection_title=가비지 수집을 수행 run_title=실행 diff --git a/addon/locale/pl.properties b/addon/locale/pl.properties index fccfc69..c9ce215 100644 --- a/addon/locale/pl.properties +++ b/addon/locale/pl.properties @@ -29,6 +29,7 @@ memoryFormat_title=Format zużycia pamięci na panelu? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Plain +memoryCautionThreshold_title=Pamięć próg ostrożności? (W megabajtach) showUrl_title=Pokaż URL na pamięci panelu użytkowania? garbageCollection_title=Wykonaj wywóz śmieci run_title=Run diff --git a/addon/locale/pt-PT.properties b/addon/locale/pt-PT.properties index 5d02c54..be67eca 100644 --- a/addon/locale/pt-PT.properties +++ b/addon/locale/pt-PT.properties @@ -29,6 +29,7 @@ memoryFormat_title=Formato de uso de memória no painel? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Plain +memoryCautionThreshold_title=limiar de cautela de memória? (Em megabytes) showUrl_title=Mostrar Url no painel uso de memória? garbageCollection_title=Executar uma coleta de lixo run_title=Run diff --git a/addon/locale/ru-RU.properties b/addon/locale/ru-RU.properties index 01ea092..ba02086 100644 --- a/addon/locale/ru-RU.properties +++ b/addon/locale/ru-RU.properties @@ -29,6 +29,7 @@ memoryFormat_title=формат использования памяти на п memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Обычная +memoryCautionThreshold_title=порог осторожность памяти? (В мегабайтах) showUrl_title=Показать URL на панели использования памяти? garbageCollection_title=Выполните сборку мусора run_title=Run diff --git a/addon/locale/sv-SE.properties b/addon/locale/sv-SE.properties index ad0b31b..67aeb66 100644 --- a/addon/locale/sv-SE.properties +++ b/addon/locale/sv-SE.properties @@ -29,6 +29,7 @@ memoryFormat_title=Format för minnesanvändning på panelen? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Plain +memoryCautionThreshold_title=Minnes försiktighet tröskel? (I megabyte) showUrl_title=Visa Url på minnesanvändningen panel? garbageCollection_title=Utför en sophämtning run_title=Kör diff --git a/addon/locale/uk-UA.properties b/addon/locale/uk-UA.properties index a33b2b4..20fa1d3 100644 --- a/addon/locale/uk-UA.properties +++ b/addon/locale/uk-UA.properties @@ -29,6 +29,7 @@ memoryFormat_title=формат використання пам'яті на па memoryFormat_options.JSON=JSON memoryFormat_options.Plain=Звичайна +memoryCautionThreshold_title=поріг обережність пам'яті? (В мегабайтах) showUrl_title=Показати URL на панелі використання пам'яті? garbageCollection_title=Виконайте збірку сміття run_title=Run diff --git a/addon/locale/zh-CN.properties b/addon/locale/zh-CN.properties index cee5538..cca74db 100644 --- a/addon/locale/zh-CN.properties +++ b/addon/locale/zh-CN.properties @@ -29,6 +29,7 @@ memoryFormat_title=內存使用的格式面板上? memoryFormat_options.JSON=JSON memoryFormat_options.Plain=平原 +memoryCautionThreshold_title=內存謹慎門檻? 兆) showUrl_title=顯示網址內存使用面板上? garbageCollection_title=執行垃圾回收 run_title=運行 diff --git a/addon/package.json b/addon/package.json index 66be265..bb35c7f 100644 --- a/addon/package.json +++ b/addon/package.json @@ -51,6 +51,11 @@ "title": "Show Url on memory usage panel?", "type": "bool", "value": true + }, { + "name": "memoryCautionThreshold", + "title": "Memory caution threshold? (In megabytes)?", + "type": "string", + "value": "20" }, { "name": "panelWidth", "title": "Width of Panel UI", @@ -60,7 +65,7 @@ "name": "panelHeight", "title": "Height of Panel UI", "type": "string", - "value": "500" + "value": "525" }, { "name": "graphType", "title": "Graph type?",