Repository navigation
Expand file tree
/
Copy pathusername.html
More file actions
115 lines (102 loc) · 4.24 KB
/
Copy pathusername.html
File metadata and controls
115 lines (102 loc) · 4.24 KB
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
<script>
const Misc = kiwi.require('helpers/Misc');
function randString(n) {
let text = '';
const possible = 'abcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < n; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
/*
Ident IRC : 11 chars — [source][browser][os][8 random]
Source : c = chat-fr, e = europnet, a = andromede, f = fantasya, l = 123love,
v = loovchat, o = other, m = Mikochat, x = xchat-fr, z = mobile app,
d = direct (direct access without origin nor chatnow)
Browser : c = Chrome, f = Firefox, s = Safari, e = Edge, b = Brave,
i = Internet Explorer, p = Opera, o = other
OS : w = Windows, m = MacOS, l = Linux, a = Android, i = iOS, o = other
*/
function getSource() {
if (Misc.queryStringVal('origine') !== undefined) {
const origin = Misc.queryStringVal('origine');
// List of EuropNet's source prefixes
const prefixes = {'3': 'c', '4': 'e', '5': 'f', '6': 'a', '7': 'c', '8': 'e', '9': 'e', '10': 'l',
'11': 'l', '12': 'l', '13': 'l', '14': 'v', '15': 'm', '16': 'x', '17': 'z'};
if (origin !== '' && prefixes[origin] !== undefined) return prefixes[origin];
}
if (Misc.queryStringVal('chatnow') === '1') return 'o';
return 'd';
}
function getBrowser() {
const ua = navigator.userAgent;
if (/OPR\/|Opera/.test(ua)) return 'p'; // Opera (OPR/ = modern, Opera = legacy)
if (/Edg/.test(ua)) return 'e'; // Edge : Edge/, Edg/, EdgA/, EdgiOS/
if (navigator.brave) return 'b'; // Brave: UA is identical to Chrome, only reliable detection
if (/Chrome|CriOS/.test(ua)) return 'c'; // Chrome desktop + Chrome iOS (CriOS)
if (/Firefox|FxiOS/.test(ua)) return 'f'; // Firefox desktop + Firefox iOS (FxiOS)
if (/Trident\/|MSIE/.test(ua)) return 'i'; // IE11 (Trident/) + IE≤10 (MSIE)
if (/Safari/.test(ua)) return 's';
return 'o';
}
function getOs() {
const ua = navigator.userAgent;
if (/Win/.test(ua)) return 'w';
if (/Android/i.test(ua)) return 'a'; // before Linux: Android UAs contain "Linux"
if (/iPad|iPhone|iPod/.test(ua)) return 'i';
if (/Mac/.test(ua)) return 'm';
if (/Linux/.test(ua)) return 'l';
return 'o';
}
// Cookies
function createCookie(name, value, days) {
let expires = "";
if (days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
document.cookie = name + "=" + value + expires + "; path=/; SameSite=Lax; Secure";
}
function readCookie(name) {
const nameEQ = name + "=";
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}
function getStoredIdent() {
let ls = null;
try {
ls = window.localStorage.getItem('username');
} catch(e) {}
return ls || readCookie('username');
}
function syncToAllStorages(value) {
try {
window.localStorage.setItem('username', value);
} catch(e) {}
createCookie('username', value, 365);
}
function getUsername() {
const stored = getStoredIdent();
if (stored && stored.length === 11) {
syncToAllStorages(stored);
return stored;
}
const username = getSource() + getBrowser() + getOs() + randString(8);
syncToAllStorages(username);
return username;
}
kiwi.plugin('username', function(kiwi) {
kiwi.state.$on('network.new', function(event) {
event.network.username = getUsername();
});
});
</script>