-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
159 lines (135 loc) · 6.85 KB
/
index.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="styles.css" rel="stylesheet" />
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet">
</head>
<body>
<div id="notifications-wrapper-top-left" class="notifications-wrapper"></div>
<div id="notifications-wrapper-top-right" class="notifications-wrapper"></div>
<div id="notifications-wrapper-bottom-left" class="notifications-wrapper"></div>
<div id="notifications-wrapper-bottom-right" class="notifications-wrapper"></div>
<div id="notifications-wrapper-center-top" class="notifications-wrapper"></div>
<div id="notifications-wrapper-center-left" class="notifications-wrapper"></div>
<div id="notifications-wrapper-center-right" class="notifications-wrapper"></div>
<div id="notifications-wrapper-center-bottom" class="notifications-wrapper"></div>
<script>
$(document).ready(function () {
const wrappers = {
'top-left': $('#notifications-wrapper-top-left'),
'top-right': $('#notifications-wrapper-top-right'),
'bottom-left': $('#notifications-wrapper-bottom-left'),
'bottom-right': $('#notifications-wrapper-bottom-right'),
'center-top': $('#notifications-wrapper-center-top'),
'center-left': $('#notifications-wrapper-center-left'),
'center-right': $('#notifications-wrapper-center-right'),
'center-bottom': $('#notifications-wrapper-center-bottom'),
};
const config = {
progressBarStepInterval: 60,
hideDelay: 500,
defaultPosition: 'center-left', //default position
};
function parseColorCodes(text) {
return text.toString().replace(/~([a-z_]+)~/g, (match, code) => {
const tagMap = {
'r': 'red',
'g': 'green',
'b': 'blue',
'y': 'yellow',
't': 'menu-grey',
'o': 'orange',
'p': 'purple',
'q': 'pink',
'm': 'mid-grey-mp',
'l': 'black',
'd': 'blue-dark',
'w': 'reset',
's': 'reset',
'n': 'line-break',
'h': 'bold',
'bold': 'bold',
'italic': 'italic',
};
return `<span class="tag-${tagMap[code]}">`;
}).replace(/~s~/g, '</span>');
}
function createNotification(data) {
const position = data.position || config.defaultPosition;
const $notificationsWrapper = wrappers[position] || wrappers[config.defaultPosition];
let $notification = $('<div class="notification-container"></div>');
let $progressBar = $('<div class="progress-bar progress-bar-' + data.type + '"></div>');
let $header = $('<div class="notification-header"></div>');
$header.append('<img src="/svg/' + data.type + '.svg" alt="' + data.type + ' icon" class="' + data.type + '">'); // Utilisation des classes d'icône
$header.append('<div class="notification-title">' + parseColorCodes(data.title) + '</div>');
$notification.append($header);
$notification.append('<div class="notification-content">' + parseColorCodes(data.message) + '</div>');
if (data.image) {
let $imageDiv = $('<div class="notification-image"><img src="' + data.image + '" alt="Notification image" width="300px"></div>');
$notification.append($imageDiv);
}
$notification.append($progressBar);
$notificationsWrapper.append($notification);
if (data.playSound) {
playSound(data.type);
}
showNotification($notification, $progressBar, data);
}
function showNotification($notification, $progressBar, data) {
resetProgress($notification, true);
setTimeout(() => {
$notification.addClass('show');
let width = 0;
const maxWidth = 300;
const steps = data.time / config.progressBarStepInterval;
const widthIncrement = maxWidth / steps;
let intervalId = setInterval(() => {
if (width >= maxWidth) {
clearInterval(intervalId);
setTimeout(() => {
$notification.removeClass('show').addClass('hide');
setTimeout(() => {
$notification.remove();
}, config.hideDelay);
}, config.hideDelay);
} else {
width += widthIncrement;
$progressBar.width(Math.min(width, maxWidth));
}
}, config.progressBarStepInterval);
}, 100);
}
function resetProgress($notification, immediate = false) {
let $progressBar = $notification.find('.progress-bar');
if (immediate) {
$progressBar.css('transition', 'none');
$progressBar.width(0);
$progressBar[0].offsetHeight;
$progressBar.css('transition', '');
}
$notification.removeClass('show hide');
}
function playSound(type) {
let audio = new Audio('/sound/' + type + '.mp3');
audio.play();
}
window.addEventListener('message', function (event) {
const data = event.data;
if (data.action === "setConfig") {
config.defaultPosition = data.defaultPosition || config.defaultPosition;
}
if (data.action === "notification") {
createNotification(data);
}
});
});
</script>
</body>
</html>