1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| // ==UserScript==
// @name Z**** DeskSound Notifier
// @namespace
// @version 0.1
// @description Notification desktop et sons lors de l'arrivé d'un nouveau ticket.
// @match http://**************
// @require http://code.jquery.com/jquery.min.js
// @copyright 2014+, Soundlicious
// ==/UserScript==
// List of users
var users = [
'-',
'rzXbrain'
];
// Notification icon
var ico = './img.jpg';
// buffers automatically when created
var snd = new Audio('http://*********/soundmanager/notify.wav');
// At first, let's check if we have permission for notification
// If not, let's ask for it
if (window.Notification && Notification.permission !== 'granted') {
Notification.requestPermission(function (status) {
if (Notification.permission !== status) {
Notification.permission = status;
}
});
}
var auto_refresh = setInterval(function () {
$('.frame.tickets_table') .load('# .frame.tickets_table') .fadeIn('slow');
$('.content.content_grey > h2') .replaceWith('<h2>Functional TICKETS <span class="item_count">(' + $('td[class="assignee"]') .length + ')</span>');
$('.updated') .each(function (i) {
if ($(this) .text() .indexOf(':') >= 0) {
var tab = $(this) .text() .split(RegExp('[:]+', 'g'));
var d = new Date();
var H = d.getHours();
var M = d.getMinutes();
if (parseInt(tab[0]) <= H && users.indexOf($('.assignee') .eq(i) .text()) > - 1) {
var notif = $('.assignee') .eq(i) .text();
var bod = $('.description') .eq(i - 2) .text();
// If the user agreed to get notified
if (window.Notification && Notification.permission === 'granted') {
$(this) .html('vu!');
snd.play();
var n = new Notification(notif, {icon: ico, body: bod});
}
// If the user hasn't told if he wants to be notified or not
// Note: because of Chrome, we are not sure the permission property
// is set, therefore it's unsafe to check for the "default" value.
else if (window.Notification && Notification.permission !== 'denied') {
Notification.requestPermission(function (status) {
if (Notification.permission !== status) {
Notification.permission = status;
}
// If the user said okay
if (status === 'granted') {
snd.play();var n = new Notification(notif, {icon: ico, body: bod});
}
// Otherwise, we can fallback to a regular modal alert
else {
alert('It seem that you\'re browser don\'t allow to use desktop notification, we recommand you to use Chrome or firefox.');
}
});
}
// If the user refuses to get notified
else {
// We can fallback to a regular modal alert
alert('This application need the permission to display desktop notification. Click allow if you want to use it.');
}
}
}
//
//
});
}, 10000); |
Partager