summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-03-09 16:39:49 +0300
committerAndrew Dolgov <[email protected]>2021-03-09 16:39:49 +0300
commit7a57bb1610c935ad7edb243a959b8558a0bfcdfd (patch)
treee413ebc604149d8338e037ef856a5bd8d003cfba
initial
-rw-r--r--init.js66
-rw-r--r--init.php22
2 files changed, 88 insertions, 0 deletions
diff --git a/init.js b/init.js
new file mode 100644
index 0000000..dd3d780
--- /dev/null
+++ b/init.js
@@ -0,0 +1,66 @@
+/* global require, App, Feeds */
+
+require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
+ ready(function() {
+ function updateFaviconBadge(unread = 0, fresh = 0) {
+
+ window.requestAnimationFrame(() => {
+
+ const canvas = document.createElement('canvas');
+ canvas.width = 16;
+ canvas.height = 16;
+ 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 = "#257aa7";
+ let count = unread;
+
+ if (fresh > 0) {
+ count = fresh;
+ bg_color = "#25a738";
+ }
+
+ if (count > 99)
+ count = 99;
+
+ ctx.fillStyle = bg_color;
+ ctx.fillRect(0, 0, 16, 16);
+
+ ctx.fillStyle = 'white';
+ ctx.font = 'bold 10px sans-serif';
+ ctx.textAlign = 'center';
+ ctx.fillText(count, 8, 11);
+
+ } else {
+ ctx.drawImage(img, 0, 0, 16, 16);
+ }
+
+ link.type = 'image/x-icon';
+ link.href = canvas.toDataURL("image/x-icon");
+ };
+ }
+
+
+ });
+ }
+
+ App.updateTitle = function() {
+ let tmp = "Tiny Tiny RSS";
+
+ if (App.global_unread > 0) {
+ tmp = "(" + App.global_unread + ") " + tmp;
+ }
+
+ updateFaviconBadge(App.global_unread, Feeds.getUnread(-3, 0));
+
+ document.title = tmp;
+ }
+ });
+});
diff --git a/init.php b/init.php
new file mode 100644
index 0000000..11b84d6
--- /dev/null
+++ b/init.php
@@ -0,0 +1,22 @@
+<?php
+class Favicon_Unread extends Plugin {
+ private $host;
+
+ function about() {
+ return array(1.0,
+ "Shows unread/fresh articles count in a favicon",
+ "fox");
+ }
+
+ function init($host) {
+ $this->host = $host;
+ }
+
+ function get_js() {
+ return file_get_contents(__DIR__ . "/init.js");
+ }
+
+ function api_version() {
+ return 2;
+ }
+}