You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

newmail_notifier.min.js 3.2KB

123456789101112131415161718192021222324
  1. /**
  2. * New Mail Notifier plugin script
  3. *
  4. * @author Aleksander Machniak <alec@alec.pl>
  5. *
  6. * @licstart The following is the entire license notice for the
  7. * JavaScript code in this file.
  8. *
  9. * Copyright (c) 2013-2016, The Roundcube Dev Team
  10. *
  11. * The JavaScript code in this page is free software: you can redistribute it
  12. * and/or modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation, either version 3 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * @licend The above is the entire license notice
  17. * for the JavaScript code in this file.
  18. */
  19. window.rcmail&&"mail"==rcmail.env.task&&rcmail.addEventListener("plugin.newmail_notifier",newmail_notifier_run).addEventListener("actionbefore",newmail_notifier_stop).addEventListener("init",function(){rcmail.message_list&&rcmail.message_list.addEventListener("select",newmail_notifier_stop)});function newmail_notifier_run(a){a.basic&&newmail_notifier_basic();a.sound&&newmail_notifier_sound();a.desktop&&newmail_notifier_desktop(rcmail.get_label("body","newmail_notifier"))}
  20. function newmail_notifier_stop(a){!rcmail.env.favicon_href||!rcmail.env.favicon_changed||a&&"check-recent"==a.action||($('<link rel="shortcut icon" href="'+rcmail.env.favicon_href+'"/>').replaceAll('link[rel="shortcut icon"]'),rcmail.env.favicon_changed=0);try{window.external.msIsSiteMode()&&window.external.msSiteModeClearIconOverlay()}catch(b){}}
  21. function newmail_notifier_basic(){var a=rcmail.is_framed()?window.parent:window,b=rcmail.assets_path("plugins/newmail_notifier");a.focus();var c=$('<link rel="shortcut icon">').attr("href",b+"/favicon.ico"),a=$('link[rel="shortcut icon"]',a.document);rcmail.env.favicon_href||(rcmail.env.favicon_href=a.attr("href"));rcmail.env.favicon_changed=1;c.replaceAll(a);try{window.external.msIsSiteMode()&&window.external.msSiteModeSetIconOverlay(b+"/overlay.ico",rcmail.get_label("title","newmail_notifier"))}catch(d){}}
  22. function newmail_notifier_sound(){var a,b=rcmail.assets_path("plugins/newmail_notifier/sound"),c=navigator.mimeTypes?navigator.mimeTypes["audio/mp3"]:{},b=b+(bw.ie||c&&c.enabledPlugin?".mp3":".wav");try{a=$("<audio>").attr("src",b),a.get(0).play()}catch(d){a=$('<embed id="sound" src="'+b+'" hidden=true autostart=true loop=false />'),a.appendTo($("body")),window.setTimeout("$('#sound').remove()",5E3)}}
  23. function newmail_notifier_desktop(a,b){var c=rcmail.env.newmail_notifier_timeout||10,d=rcmail.assets_path("plugins/newmail_notifier/mail.png"),e=function(){var b=new window.Notification(rcmail.get_label("title","newmail_notifier"),{dir:"auto",lang:"",body:a,tag:"newmail_notifier",icon:d});b.onclick=function(){this.close()};setTimeout(function(){b.close()},1E3*c)};try{return window.Notification.requestPermission(function(a){"granted"==a?e():"denied"==a&&b&&b()}),!0}catch(f){return!1}}
  24. function newmail_notifier_test_desktop(){newmail_notifier_desktop(rcmail.get_label("testbody","newmail_notifier"),function(){rcmail.display_message(rcmail.get_label("desktopdisabled","newmail_notifier"),"error")})||rcmail.display_message(rcmail.get_label("desktopunsupported","newmail_notifier"),"error")}function newmail_notifier_test_basic(){newmail_notifier_basic()}function newmail_notifier_test_sound(){newmail_notifier_sound()};