123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- /**
- * Created by Hongcai Deng on 2015/12/29.
- */
- $(function(){
- $('.ui.modal')
- .modal()
- ;
- var clipboard = new Clipboard('.copyable');
- $maillist = $('#maillist');
- $maillist.on('click', 'tr', function() {
- var mail = $(this).data('mail');
- $('#mailcard .header').text(mail.headers.subject || '无主题');
- $('#mailcard .content:last').html(mail.html);
- $('#mailcard i').click(function() {
- $('#raw').modal('show');
- });
- $('#raw .header').text('RAW');
- $('#raw .content').html($('<pre>').html($('<code>').addClass('language-json').html(JSON.stringify(mail, null, 2))));
- Prism.highlightAll();
- });
- var socket = io();
- var setMailAddress = function(id) {
- localStorage.setItem('shortid', id);
- var mailaddress = id + '@' + location.hostname;
- $('#shortid').val(mailaddress).parent().siblings('button').find('.mail').attr('data-clipboard-text', mailaddress);
- };
- $('#refreshShortid').click(function() {
- socket.emit('request shortid', true);
- });
- socket.on('connect', function() {
- if(('localStorage' in window)) {
- var shortid = localStorage.getItem('shortid');
- if(!shortid) {
- socket.emit('request shortid', true);
- }
- else {
- socket.emit('set shortid', true);
- setMailAddress(shortid);
- }
- }
- });
- socket.on('shortid', function(id) {
- setMailAddress(id);
- });
- socket.on('mail', function(mail) {
- if(('Notification' in window)) {
- if(Notification.permission === 'granted') {
- new Notification('New mail from ' + mail.headers.from);
- }
- else if(Notification.permission !== 'denied') {
- Notification.requestPermission(function(permission) {
- if(permission === 'granted') {
- new Notification('New mail from ' + mail.headers.from);
- }
- })
- }
- }
- $tr = $('<tr>').data('mail', mail);
- $tr
- .append($('<td>').text(mail.headers.from))
- .append($('<td>').text(mail.headers.subject || '无主题'))
- .append($('<td>').text((new Date(mail.headers.date)).toLocaleTimeString()));
- $maillist.prepend($tr);
- });
- });
|