Last active
August 29, 2015 13:57
-
-
Save francisbesset/9543896 to your computer and use it in GitHub Desktop.
Office365 Google Chrome Notifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){var o365n=document.createElement('script');o365n.setAttribute('src','//gist.githubusercontent.com/francisbesset/9543896/raw/orrifice365notifier.js');document.head.appendChild(o365n);}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var orrifice365notifier = (function () { | |
return function () { | |
checkPermission() | |
var $polite = $('.o365cs-nav-notifications [aria-live=polite]')[0], | |
checkNotification = function () { | |
var $notificationSpans = $('button > span[class*="-white"]', $polite) | |
if (0 === $notificationSpans.length) { | |
return | |
} | |
$notificationSpans.each(function (index, element) { | |
var $element = $(element) | |
, $button = $(element).parent() | |
, iconType = 'mail' | |
if ('display: none;' === $button.attr('style')) { | |
if ('yes' === $button.data('notified')) { | |
$button.data('notified', 'no') | |
} | |
return | |
} else if ('yes' === $button.data('notified')) { | |
return | |
} | |
if ($element.hasClass('wf-owa-chat-white')) { | |
iconType = 'chat' | |
} | |
$button.data('notified', 'yes') | |
var notification = window.webkitNotifications.createNotification( | |
'//gist.githubusercontent.com/francisbesset/9543896/raw/icon-' + iconType + '.png', | |
'Office365 notification !', | |
$button.attr('title') | |
) | |
notification.onclick = function () { | |
window.focus() | |
notification.close() | |
} | |
notification.show() | |
}) | |
} | |
window.setInterval(checkNotification, 1000) | |
} | |
function checkPermission() { | |
var havePermission = window.webkitNotifications.checkPermission() | |
if (0 === havePermission) { | |
// 0 is PERMISSION_ALLOWED | |
return; | |
} | |
$('body').prepend( | |
'<div style="position: absolute; top: 5px; bottom: auto; left: 50%; height: 30px;" id="orrifice365notifier_permission">' | |
+ '<div style="padding: 0 10px; width: 520px; position: relative; z-index: 990; left: -50%; background-color: #f9edbe; border-color: #f0c36d; color: #222; font-weight: bold; font-size: 80%;">' | |
+ '<span onclick="window.webkitNotifications.requestPermission(); $(this).parents(\'#orrifice365notifier_permission\').remove();" style="cursor: pointer; text-decoration: underline;">Cliquez ici</span>' | |
+ ' pour activer les notification de bureau Google Chrome.' | |
+ ' <span onclick="$(this).parents(\'#orrifice365notifier_permission\').remove();" style="cursor: pointer; text-decoration: underline;">Masquer</span>' | |
+ '</div>' | |
+ '</div>' | |
) | |
} | |
})() | |
orrifice365notifier() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment