-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
156 lines (137 loc) · 5.77 KB
/
background.js
File metadata and controls
156 lines (137 loc) · 5.77 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"use strict"
var panel = 0;
var iconinterval = 1000;
var barinterval = 1000;
var clickbar = false;
var clickpanel = true;
var autoinject = false;
var textcolor = "#000000";
var background = "#ffffff";
var notified = false;
var low = 0;
var canvas = (new OffscreenCanvas(19, 19)).getContext("2d", { willReadFrequently: true })
chrome.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({ id: "panel", title: "Install Floating Panel App", contexts: ["action"] }, function() {})
chrome.runtime.setUninstallURL("https://forms.danielherr.software/Uninstalled/Memory_Monitor")
})
function open() {
chrome.windows.create({ url: "panel.html", type: "panel", width: 100, height: 100
}, function(window) { if (window.type === "panel") {
chrome.windows.update(window.id, { state: "minimized"});
panel = window.id;
} else {
chrome.windows.remove(window.id);
} } ) }
function options() { chrome.storage.sync.get({
browserinterval: 1, barinterval: 1, clickbar: false, clickpanel: true, low: 0,
browsertextcolor: "#000000", browserbackground: "#ffffff", autopanel: false
}, function(items) {
iconinterval = items.browserinterval * 1000;
barinterval = items.barinterval * 1000;
textcolor = items.browsertextcolor;
background = items.browserbackground;
clickbar = items.clickbar;
clickpanel = items.clickpanel;
low = items.low;
if (items.autopanel == true) {
chrome.runtime.sendMessage("kbilomlpmhhhaimaigidhnjijhiajbam", { launch: true })
} } )}
options()
chrome.storage.onChanged.addListener(options);
chrome.notifications.onClicked.addListener(function(notification) {
if(notification == "eol") {
chrome.tabs.create({ url: "https://danielherr.software/Processor_Monitor" })
} else {
chrome.tabs.create({ url: "options.html"})
}
})
chrome.notifications.onButtonClicked.addListener(function() {
chrome.tabs.create({ url: "https://danielherr.software/Processor_Monitor" })
})
chrome.notifications.onClosed.addListener(function() { notified = false });
function infoicon() {
chrome.system.memory.getInfo(function(memory) {
var short = (Math.round(memory.availableCapacity / 1024 / 1024 / 100)) / 10;
var long = (Math.round(memory.availableCapacity / 1024 / 1024)) / 1000;
canvas.font = "20px Noto Sans, sans-serif";
canvas.clearRect(0, 0, 19, 19);
canvas.fillStyle = background;
canvas.fillRect(0, 0, 19, 19);
canvas.fillStyle = textcolor;
canvas.fillText(short.toString()[0], -1, 14);
if (short.toString()[2] !== undefined) { canvas.fillText(short.toString()[2], 9, 14)}
else { canvas.fillText("0", 9, 14)}
canvas.fillText(".", 7, 18);
chrome.action.setTitle({ title: "Available: " + long + " GB " + "Capacity: " + (Math.round(memory.capacity / 1024 / 1024 / 100 )) / 10 + " GB" });
if (long < low && notified === false) {
chrome.notifications.create("lowram", {
type: "progress", title: "Memory Monitor", message: "Your available RAM is low.", iconUrl: "icon.png", progress: Math.round((memory.availableCapacity / memory.capacity) * 100)
}, function() { notified = true }
) }
else if (long < low && notified === true) {
chrome.notifications.update("lowram", { progress: Math.round((memory.availableCapacity / memory.capacity) * 100) }, function() { } );
}
else if (notified === true) { chrome.notifications.clear("lowram",
function() { notified = false }
) }
chrome.action.setIcon({ imageData: canvas.getImageData(0, 0, 19, 19)});
});
setTimeout(infoicon, iconinterval);
}
infoicon()
function infobar() {
if(clickbar || autoinject) {
chrome.system.memory.getInfo(function(memory) {
chrome.tabs.query({ active: true }, function(tabs) {
for (var number in tabs) {
chrome.tabs.sendMessage(tabs[number].id, { available: (Math.round(memory.availableCapacity / 1024 / 1024)) / 1000 });
} }) }) }
setTimeout(infobar, barinterval);
}
infobar()
function inject() { if (autoinject === true) {
chrome.tabs.query({}, function(tabs) {
for (var number in tabs) {
chrome.scripting.executeScript({ target: { tabId: tabs[number].id }, files: [ "inject.js" ]})
} }) }}
function permissions() {
chrome.permissions.contains({
origins: ["<all_urls>"] }, function(result) {
if (result) { autoinject = true;
chrome.tabs.onCreated.addListener(inject);
chrome.tabs.onUpdated.addListener(inject);
chrome.tabs.onReplaced.addListener(inject);
}
else { autoinject = false }
} )}
permissions()
chrome.permissions.onAdded.addListener(permissions)
chrome.action.onClicked.addListener(function(tab) {
if (clickbar === true && autoinject === false) {
chrome.scripting.executeScript({ target: { tabId: tab.id }, files: [ "inject.js" ]})
}
if (clickpanel == true) {
chrome.runtime.sendMessage("kbilomlpmhhhaimaigidhnjijhiajbam", { launch: true })
} });
chrome.runtime.onMessageExternal.addListener(function(message, sender, sendResponse) {
chrome.tabs.create({ url: "options.html"}, function() {
sendResponse({ opened: true })
}) });
chrome.contextMenus.onClicked.addListener(function() {
chrome.tabs.create({ url: "https://chrome.google.com/webstore/detail/kbilomlpmhhhaimaigidhnjijhiajbam"})
})
chrome.runtime.onStartup.addListener(function() {}) // dummy to fix extension not loading on startup
let eol = true
if(navigator.userAgentData) { // Chromium 90
let version = navigator.userAgentData.brands.find(entry => entry.brand == "Chromium").version
eol = version < 109
}
if(eol) {
chrome.notifications.create("eol", {
type: "basic",
title: "Processor Monitor Action Required",
iconUrl: "/icon.png",
message: "Your current installation of Processor Monitor will no longer be updated. To continue receiving updates, install Processor Monitor from its website or upgrade to a current web browser.",
buttons: [{ title: "Upgrade" }]
})
}