forked from jakobht/AUB-Chrome-Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
27 lines (24 loc) · 879 Bytes
/
popup.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
function renderStatus(statusText) {
document.getElementById('status').innerHTML = statusText;
}
chrome.tabs.query({'active': true}, function(tabs) {
var tab = tabs[0];
var url = tab.url;
var testRequest = new Request("https://content.aub.aau.dk/zorac/zoracjson.php?&url=" + url);
renderStatus('Looking up');
fetch(testRequest).then(function (response) {
return response.json();
})
.then(function (body) {
console.log(body.proxy);
if(body.proxy == 1){
renderStatus("Redirecting");
var newurl = 'https://login.zorac.aub.aau.dk/login?qurl=' + encodeURIComponent(url);
chrome.tabs.update(tab.id, {url: newurl});
} else {
renderStatus("No access");
}
}, function (error) {
renderStatus("Error!<br />You are probably not on a http page.");
});
});