-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhead.html
61 lines (53 loc) · 1.92 KB
/
head.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
<!DOCTYPE html>
<script type="text/discourse-plugin" version="0.8">
var div = document.createElement('div');
div.className = 'universal_auth_div';
div.id = 'op';
div.style.cssText = 'position: absolute; z-index: 999; height: 16px; width: 16px; top:70px; display:none';
// dec2hex :: Integer -> String
// i.e. 0-255 -> '00'-'ff'
function dec2hex (dec) {
return dec.toString(16).padStart(2, "0")
}
// generateId :: Integer -> String
function generateId (len) {
var arr = new Uint8Array((len || 40) / 2)
window.crypto.getRandomValues(arr)
return Array.from(arr, dec2hex).join('')
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
const user = api.getCurrentUser();
console.log(user);
if(user) {
var myStringArray = ["xjtu.men","xjtu.app","xjtu.live"];
var arrayLength = myStringArray.length;
var imgHtml = "";
let cookie_key = getCookie("universal_auth");
if (cookie_key == "") {
cookie_key = generateId(128);
document.cookie = "universal_auth=" + cookie_key;
}
for (var i = 0; i < arrayLength; i++) {
imgHtml += "<img src=\"https://" + myStringArray[i] + "/share_sessions/universal.gif?username=" +
user.username + "&key=" + cookie_key + "\"\n" +
" style=\"display: none\"\n" +
" crossorigin=\"use-credentials\"/>"
}
div.innerHTML = '<span>' + imgHtml + '</span>';
document.body.appendChild(div);
}
</script>