/
taskmonitor_part2.uc.js
130 lines (112 loc) · 6.4 KB
/
taskmonitor_part2.uc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* Firefox userChrome script
* Show tab cpu and memory bars on every tab button
* Show addon cpu and memory bars on every addon toolbar button
* Show all-task cpu and memory bars on a slender widget at the right of tab bar
* Dynamically show top tasks on popup menu of the widget
*
* Tested on Firefox 102, with xiaoxiaoflood's uc loader
*
* Author: garywill (https://garywill.github.io)
* https://github.com/garywill/firefoxtaskmonitor
*/
// ==UserScript==
// @include main
// @onlyonce
// ==/UserScript==
console.log("taskmonitor_part2.js");
(() => {
const barGap = 1;
const barWidth = 3;
const sss = Components.classes["@mozilla.org/content/style-sheet-service;1"].getService(Components.interfaces.nsIStyleSheetService);
widget_init();
function widget_init() {
const fftm_widget_label = "TaskManager Widget for all tasks";
const fftm_widget_id = "fftm_widget";
Components.utils.import("resource:///modules/CustomizableUI.jsm");
// if ( ! CustomizableUI.getWidget(fftm_widget_id) ) {
CustomizableUI.createWidget({
id: fftm_widget_id,
type: "custom",
defaultArea: CustomizableUI.AREA_TABSTRIP,
removable: true,
onBuild: function (doc) {
let btn = doc.createXULElement('toolbarbutton');
btn.id = fftm_widget_id;
btn.label = fftm_widget_label;
btn.tooltipText = fftm_widget_label;
btn.type = 'menu';
btn.className = 'toolbarbutton-1 chromeclass-toolbar-additional fftm_widget_class';
btn.style.MozBoxAlign="unset";
let mp = doc.createXULElement("menupopup");
mp.id = 'fftm_widget_menupopup';
mp.onclick = function(event) { event.preventDefault() ;} ;
const menu_show_tasks_num = 10;
for (var i=0; i<menu_show_tasks_num ; i++)
{
var menuitem = doc.createXULElement("menuitem");
menuitem.id = "fftm_widget_task_" + i;
menuitem.label = "Top task " + (i+1) ;
menuitem.className = 'menuitem-iconic fftm_widget_task' ;
mp.appendChild(menuitem);
}
mp.appendChild(doc.createXULElement('menuseparator'));
var menu_open_about_performance = doc.createXULElement("menuitem");
menu_open_about_performance.className = 'menuitem-iconic' ;
menu_open_about_performance.label = "Open about:performance";
menu_open_about_performance.onclick = function(event) {
if (event.button == 0) {
const win = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
win.gBrowser.selectedTab = win.gBrowser.addTrustedTab('about:performance');
}
}
mp.appendChild(menu_open_about_performance);
var menu_open_about_processes = doc.createXULElement("menuitem");
menu_open_about_processes.className = 'menuitem-iconic' ;
menu_open_about_processes.label = "Open about:processes";
menu_open_about_processes.onclick = function(event) {
if (event.button == 0) {
const win = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
win.gBrowser.selectedTab = win.gBrowser.addTrustedTab('about:processes');
}
}
mp.appendChild(menu_open_about_processes);
var menu_open_about_memory = doc.createXULElement("menuitem");
menu_open_about_memory.className = 'menuitem-iconic' ;
menu_open_about_memory.label = "Open about:memory";
menu_open_about_memory.onclick = function(event) {
if (event.button == 0) {
const win = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
win.gBrowser.selectedTab = win.gBrowser.addTrustedTab('about:memory');
}
}
mp.appendChild(menu_open_about_memory);
mp.appendChild(doc.createXULElement('menuseparator'));
var menu_donate = doc.createXULElement("menuitem");
menu_donate.className = 'menuitem-iconic' ;
menu_donate.label = "More scripts / Donate: Visit author";
menu_donate.onclick = function(event) {
if (event.button == 0) {
const win = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
win.gBrowser.selectedTab = win.gBrowser.addWebTab('https://garywill.github.io');
}
}
mp.appendChild(menu_donate);
btn.appendChild(mp);
return btn;
}
});
const fftm_widget_css = Services.io.newURI("data:text/css;charset=utf-8," + encodeURIComponent(`
#${fftm_widget_id} .toolbarbutton-icon {
max-width: ${ (barWidth*2 + barGap) }px !important ;
min-width: ${ (barWidth*2 + barGap) }px !important;
width: ${ (barWidth*2 + barGap) }px !important;
}
#${fftm_widget_id}:hover {
background-color: grey;
}
`
), null, null);
sss.loadAndRegisterSheet(fftm_widget_css, sss.USER_SHEET);
// }
}
}) ();