From 8aad0dea98a35d947e607c73420267f7be57ae8a Mon Sep 17 00:00:00 2001 From: Fredrick Brennan Date: Fri, 13 Mar 2015 19:18:56 +0800 Subject: [PATCH] Desktop notifications in auto-reload.js --- inc/config.php | 2 +- inc/instance-config.php | 1 - js/auto-reload.js | 60 +++++++++++++++++++++++++++++++------- static/favicon-error.ico | Bin 0 -> 318 bytes static/favicon-quoted.ico | Bin 0 -> 318 bytes static/favicon-reply.ico | Bin 0 -> 318 bytes static/favicon.ico | Bin 0 -> 318 bytes templates/header.html | 2 +- 8 files changed, 52 insertions(+), 13 deletions(-) create mode 100755 static/favicon-error.ico create mode 100755 static/favicon-quoted.ico create mode 100755 static/favicon-reply.ico create mode 100755 static/favicon.ico diff --git a/inc/config.php b/inc/config.php index 35a2fdc7..28dc577b 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1230,7 +1230,7 @@ // $config['url_javascript'] = 'http://static.example.org/main.js'; // Website favicon. - // $config['url_favicon'] = '/favicon.gif'; + $config['url_favicon'] = 'static/favicon.ico'; // EXPERIMENTAL: Try not to build pages when we shouldn't have to. $config['try_smarter'] = true; diff --git a/inc/instance-config.php b/inc/instance-config.php index 0a21ceea..f140ed2c 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -113,7 +113,6 @@ $config['additional_javascript'][] = 'js/local-time.js'; $config['additional_javascript'][] = 'js/no-animated-gif.js'; $config['additional_javascript'][] = 'js/expand.js'; - $config['additional_javascript'][] = 'js/titlebar-notifications.js'; $config['additional_javascript'][] = 'js/auto-reload.js'; $config['additional_javascript'][] = 'js/options/user-css.js'; $config['additional_javascript'][] = 'js/options/user-js.js'; diff --git a/js/auto-reload.js b/js/auto-reload.js index 20989dde..528dd68d 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -8,7 +8,7 @@ * Copyright (c) 2012 Michael Save * Copyright (c) 2013-2014 Marcin Ɓabanowski * Copyright (c) 2013 undido - * Copyright (c) 2014 Fredrick Brennan + * Copyright (c) 2014-2015 Fredrick Brennan * * Usage: * $config['additional_javascript'][] = 'js/jquery.min.js'; @@ -17,16 +17,20 @@ * */ +function makeIcon(mode){ + var favicon = $("link[rel='shortcut icon']"); -au = false; -auto_reload_enabled = true; // for watch.js to interop + if (!favicon.length) { + var favicon = $('').appendTo('head'); + } -function makeIcon(){ - if(au) return; - au = true; - $("link[rel='icon']").attr("href", "../static/favicon_au.png"); + $("link[rel='shortcut icon']").attr("href", configRoot+"static/favicon"+(mode?"-"+mode:"")+".ico"); } ++function(){ +var notify = false; +auto_reload_enabled = true; // for watch.js to interop + $(document).ready(function(){ // Adds Options panel item @@ -34,7 +38,12 @@ $(document).ready(function(){ localStorage.auto_thread_update = 'true'; //default value } if (window.Options && Options.get_tab('general')) { - Options.extend_tab('general', ''); + Options.extend_tab("general", "
"+_("Auto update")+"" + + ('') + + ('') + + ('') + + '
'); + $('#auto-thread-update>input').on('click', function() { if ($('#auto-thread-update>input').is(':checked')) { localStorage.auto_thread_update = 'true'; @@ -42,9 +51,35 @@ $(document).ready(function(){ localStorage.auto_thread_update = 'false'; } }); + + $('#auto_thread_desktop_notifications>input,#auto_thread_desktop_notifications_all>input').on('click', function() { + if (!("Notification" in window)) return; + + var setting = $(this).parent().attr('id'); + + if ($(this).is(':checked')) { + Notification.requestPermission(); + if (Notification.permission === "granted") { + localStorage[setting] = 'true'; + } + } else { + localStorage[setting] = 'false'; + } + }); + if (localStorage.auto_thread_update === 'true') { $('#auto-thread-update>input').prop('checked', true); } + + if (localStorage.auto_thread_desktop_notifications === 'true') { + $('#auto_thread_desktop_notifications>input').prop('checked', true); + notify = "mention"; + } + + if (localStorage.auto_thread_desktop_notifications_all === 'true') { + $('#auto_thread_desktop_notifications_all>input').prop('checked', true); + notify = "all"; + } } // not thread @@ -84,6 +119,7 @@ $(document).ready(function(){ document.title = "("+new_posts+") "+title; } else { document.title = title; + makeIcon(false); } }; } @@ -178,7 +214,11 @@ $(document).ready(function(){ if($('#' + id).length == 0) { if (!new_posts) { first_new_post = this; - makeIcon(); + makeIcon('reply'); + if (notify === "all" || (notify === "mention" && $(this).find('.own_post').length)) { + var body = $(this).children('.body').html().replace(//gi, "\n"); + var n = new Notification("New reply to "+$('title').text(), {body: $('
').html(body).text()}); + } } $(this).insertAfter($('div.post:not(.post-hover):last').next()).after('
'); new_posts++; @@ -264,4 +304,4 @@ $(document).ready(function(){ auto_update(poll_interval_delay); } }); - +}(); diff --git a/static/favicon-error.ico b/static/favicon-error.ico new file mode 100755 index 0000000000000000000000000000000000000000..6ce08d287de547b1787dd15ac4a4d3e8b8061662 GIT binary patch literal 318 zcma)%u?hk)42J)ppkvaA(+$??*3ui?`zM@+wAJ=x!1k#+{g0*kTo4Y literal 0 HcmV?d00001 diff --git a/static/favicon-quoted.ico b/static/favicon-quoted.ico new file mode 100755 index 0000000000000000000000000000000000000000..dfcbbbfbb557125bd1cac36b34f31afe7060b03d GIT binary patch literal 318 zcma)%JqiLr4254%&@zdP)fVn-Gwu2VcH#xZ0S{!o&0fii2p&XO6Na@B7H4<~NxnyB z0J6)>7UxI=tN|nwn>HrzPagAh*9zSwp}$2Op8HAs&!LEeBq58vWEDe>H7Ke`-LTfw zM2iYI*IFGi>zTG1a=T+_;lKXE{j44aVAT5rycWP?2HfpWOIuqVOZM9PK6h^Pd;r9O B9d!Tz literal 0 HcmV?d00001 diff --git a/static/favicon-reply.ico b/static/favicon-reply.ico new file mode 100755 index 0000000000000000000000000000000000000000..5322cd744a86a4a5ff5ec23292880a6fdde83ec8 GIT binary patch literal 318 zcma)%F%H5o3`M^M5{$M{m^zSj$y!+05Enp1;y}z@xDrRyXY&5+F;9PO&|fkhw}hd-XYoIWA`X&-BKDF^3MEBQQjyrQMrxBq y1)S@w4u$nhdkv*KFm&X<{*n7xT`MqYI03H}@LT|Q`_tOiHpel0?R}p+H+eo&?H?!r literal 0 HcmV?d00001 diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100755 index 0000000000000000000000000000000000000000..e3fcfa17553f2a5fc974f201e3a1a05b31f43dc9 GIT binary patch literal 318 zcmb7p>UO*f?kl@zEGdXz>4^s0}gf13LcnQgSAqhyj zs%Bi#3v7Tsp^0sx_7^Q@hD*nA?s;5eQTjJ24K#U48!F*Qn49m^Ts$&bG7cr{Xw^=# lw_@d>*rew>|6}nu!W{1xJnwMJpVqmyJ5IUQwO{$U{sSz&9#8-P literal 0 HcmV?d00001 diff --git a/templates/header.html b/templates/header.html index b4e5aede..a92b6dbc 100644 --- a/templates/header.html +++ b/templates/header.html @@ -1,5 +1,5 @@ - {% if config.url_favicon %}{% endif %} + {% if config.url_favicon %}{% endif %} {% if config.meta_keywords %}{% endif %}