-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
57 lines (44 loc) · 1.31 KB
/
init.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
/* global require, App, Feeds, PluginHost */
require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
ready(function() {
function updateFaviconBadge(unread = 0, fresh = 0) {
const canvas = document.createElement('canvas');
canvas.width = 72;
canvas.height = 72;
if (canvas.getContext) {
const link = App.find("link[rel='shortcut icon']");
const ctx = canvas.getContext('2d');
const img = new Image();
img.src = 'images/favicon.png';
img.onload = function() {
if (unread > 0 || fresh > 0) {
let bg_color = "#2a89bc";
let count = unread;
let font_size = "42px";
if (fresh > 0) {
count = fresh;
bg_color = "#3ea447";
}
if (count > 99) {
count = "∞";
font_size = "52px";
}
ctx.fillStyle = bg_color;
ctx.fillRect(0, 0, 72, 72);
ctx.fillStyle = 'white';
ctx.font = `bold ${font_size} Segoe UI, sans-serif`;
ctx.textAlign = 'center';
ctx.fillText(count, 36, 50);
} else {
ctx.drawImage(img, 0, 0, 72, 72);
}
link.type = 'image/x-icon';
link.href = canvas.toDataURL("image/x-icon");
};
}
}
PluginHost.register(PluginHost.HOOK_COUNTERS_PROCESSED, () => {
updateFaviconBadge(App.global_unread, Feeds.getUnread(-3, 0));
});
});
});