-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextcloud_check.js
164 lines (141 loc) · 4.81 KB
/
nextcloud_check.js
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
160
161
162
163
164
// try to find Nextcloud scripts and do observing (tested on Nextcloud since 28)
async function pingUrl(url){
try{
var result = await fetch(url, {
signal: AbortSignal.timeout(4000),
method: "GET",
mode: "no-cors",
cache: "no-cache",
referrerPolicy: "no-referrer"
});
//console.log(`result.type: ${result.type}`);
//console.log(`result.ok: ${result.ok}`);
if (result.ok) {
console.log(JSON.stringify({action: "alive"}));
$('.loading-state').css({'display': 'none'});
//checkURL();
} else {
console.log(JSON.stringify({action: "not_alive"}));
$('.loading-state').css({'display': 'flex'});
}
return result.ok;
}
catch(err){
//console.log(err);
console.log(JSON.stringify({action: "not_alive"}));
$('.loading-state').css({'display': 'flex'});
}
return 'error';
}
function create_spinner() {
let div = document.createElement('div');
let div2 = document.createElement('div');
div.classList.add("loading-state");
div2.classList.add("loading");
$(div).append(div2);
$('body').append(div);
let css =`
<style>
/*.loading {
width: 100px;
height: 100px;
border-radius: 50%;
border: 10px solid black;
border-top-color: white;
animation: loading 1s linear infinite;
}
@keyframes loading {
to {
transform: rotate(360deg);
}
}*/
.loading-state {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
backdrop-filter: blur(4px);
z-index: 9999;
display: none;
justify-content: center;
align-items: center;
}
</style>
`;
$('head').append(css);
}
function checkURL(auto_login){
// check current page is spreed
//console.log($('form.login-form').length < 1)
if ($('form.login-form').length < 1) {
if (!(location.pathname.includes('apps/spreed'))&&(!(location.pathname.includes('/call/')))&&(!location.pathname.includes('login'))) {
console.log(JSON.stringify({action: "redirect_to_spreed"}));
//window.location.replace("/apps/spreed")
}
} else {
// to force show app window if not logged in
// 5s timeout to pass SSO procedure
if (!(auto_login)) {
// hide autologin buttons
if ($("#alternative-logins > a").length > 0) {
$("#alternative-logins > a").hide();
}
setTimeout(function() {
// check localStorage to drop unread counter
recalc_counters_summary(true);
console.log(JSON.stringify({action: "force_show_app_win"}));
}, 5000);
} else {
if ($("#alternative-logins > a").length > 0) {
$("#alternative-logins > a")[0].click();
}
//window.location.href = "/apps/oidc_login/oidc";
}
}
}
if (typeof _oc_config === "undefined") {
console.log(JSON.stringify({action: "not_found"}));
} else {
if (_oc_config.version.localeCompare("28.0.0.0", undefined, { numeric: true, sensitivity: 'base' }) == '-1') {
console.log(JSON.stringify({action: "not_found"}));
} else {
create_spinner();
// check current page is spreed
checkURL();
// add open user settings menu link instead of default to prevent default behaviour
if ( !$('#user_settings_link').length ) {
let li = document.createElement( "li" );
li.classList.add("menu-entry");
li.setAttribute('id','user_settings_link');
let a = document.createElement( "a" );
a.setAttribute('href','/settings/user');
a.textContent += user_settings_link_loc;
let img = document.createElement( "img" );
img.setAttribute('src','/apps/settings/img/admin.svg');
$(a).prepend($(img));
$(li).append($(a));
$('#firstrunwizard_about').before( $(li) );
//console.log($('#profile'));
}
// add open NC in default browser menu link
if ( !$('#nc_link').length ) {
let li = document.createElement( "li" );
li.classList.add("menu-entry");
li.setAttribute('id','nc_link');
let a = document.createElement( "a" );
a.setAttribute('href','/');
a.setAttribute('target','_blank');
a.textContent += nc_link_loc;
let img = document.createElement( "img" );
img.setAttribute('src','/core/img/favicon-mask.svg');
$(a).prepend($(img));
$(li).append($(a));
$('#firstrunwizard_about').before( $(li) );
//console.log($('#profile'));
}
// add pinger every 10 seconds to check NC alive
var interval = setInterval(function () { pingUrl(location.protocol + '//' + location.host/* + location.pathname*/) }, 10000);
}
}