const url = new URL(window.location.href); export const baseUrl = `${url.protocol}//${url.host}`; const api = baseUrl + '/api/alpha/site'; let jwt = null; let session_jwt = sessionStorage.getItem('jwt'); if (session_jwt != null) { jwt = session_jwt; } else { let local_jwt = localStorage.getItem('jwt'); if (local_jwt != null) { jwt = local_jwt; } } export { jwt }; const ul = document.getElementById('navbar_items'); if (jwt != null) { var request = {method: "GET", headers: {Authorization: `Bearer ${jwt}`}}; ul.innerHTML = '' + '' + '' + ''; } else { var request = {method: "GET"}; ul.innerHTML = '' + '' + '' + ''; } fetch(api, request) .then(response => response.json()) .then(data => { // head document.querySelector('#head_title').textContent = data.site.name; document.querySelector('#icon_152').href = data.site.icon_152; document.querySelector('#icon_32').href = data.site.icon_32; document.querySelector('#icon_16').href = data.site.icon_16; document.querySelector('#icon_shortcut').href = data.site.icon_32; document.querySelector('#favicon').href = baseUrl + '/static/images/favicon.ico'; // navbar document.querySelector('#navbar_title').innerHTML = 'Logo' + ' ' + data.site.name; // site info document.querySelector('#site_json').textContent = JSON.stringify(data, null, 2); })