Extended
This commit is contained in:
66
script.js
66
script.js
@@ -1,21 +1,49 @@
|
|||||||
console.log("Keycloak Script running!");
|
document.querySelectorAll("link[rel~='icon']").forEach(el => el.href = "https://gitlab.ms-ds.org/msds/icons/-/raw/main/icons/schmoekerei.png");
|
||||||
const keycloak = new Keycloak({
|
document.title = "Schmökerei";
|
||||||
realm: "schmoekerei",
|
|
||||||
url: "https://auth.xn--schmkerei-37a.de",
|
|
||||||
clientId: "heimdall"
|
|
||||||
});
|
|
||||||
|
|
||||||
keycloak.init({ onLoad: 'login-required' }).then(function(authenticated) {
|
const s1 = document.createElement('script');
|
||||||
if (authenticated) {
|
s1.src = "https://auth.xn--schmkerei-37a.de/js/keycloak.js";
|
||||||
console.log("User is authenticated");
|
s1.type = "text/javascript";
|
||||||
}
|
document.head.appendChild(s1);
|
||||||
}).catch(function() {
|
|
||||||
console.error("Authenticated Failed");
|
|
||||||
});
|
|
||||||
|
|
||||||
const wrapper = document.querySelector("#config-buttons");
|
var s2 = document.createElement('script');
|
||||||
const kcUserLink = wrapper.querySelector("#users").cloneNode(true);
|
s2.setAttribute("defer", "");
|
||||||
kcUserLink.href = "https://auth.xn--schmkerei-37a.de/realms/schmoekerei/account";
|
s2.setAttribute("event-source", "Heimdall");
|
||||||
kcUserLink.id = "kcUserSettings";
|
s2.setAttribute("data-domain", "schmökerei.de");
|
||||||
wrapper.append(kcUserLink);
|
s2.src = "https://plsbl.ms-ds.org/js/script.pageview-props.outbound-links.js";
|
||||||
kcUserLink.querySelector("div").innerHTML = "Account-Einstellungen";
|
document.head.appendChild(s2);
|
||||||
|
|
||||||
|
const headEl = document.createElement('h1');
|
||||||
|
headEl.id = "headGreeting";
|
||||||
|
headEl.innerHTML = "Hallo!";
|
||||||
|
headEl.style.color = "white";
|
||||||
|
document.querySelector("#main").prepend(headEl);
|
||||||
|
|
||||||
|
s1.onload = function() {
|
||||||
|
console.log("Keycloak Script running!");
|
||||||
|
const keycloak = new Keycloak({
|
||||||
|
realm: "schmoekerei",
|
||||||
|
url: "https://auth.xn--schmkerei-37a.de",
|
||||||
|
clientId: "heimdall"
|
||||||
|
});
|
||||||
|
|
||||||
|
keycloak.init({ onLoad: 'login-required' }).then(function(authenticated) {
|
||||||
|
if (authenticated) {
|
||||||
|
console.log("User is authenticated");
|
||||||
|
|
||||||
|
const userProfile = keycloak.tokenParsed;
|
||||||
|
const firstName = userProfile.given_name;
|
||||||
|
|
||||||
|
headEl.innerHTML = `Hallo, ${firstName}!`;
|
||||||
|
}
|
||||||
|
}).catch(function() {
|
||||||
|
console.error("Authentication Failed");
|
||||||
|
});
|
||||||
|
|
||||||
|
const wrapper = document.querySelector("#config-buttons");
|
||||||
|
const kcUserLink = wrapper.querySelector("#users").cloneNode(true);
|
||||||
|
kcUserLink.href = "https://auth.xn--schmkerei-37a.de/realms/schmoekerei/account";
|
||||||
|
kcUserLink.id = "kcUserSettings";
|
||||||
|
wrapper.append(kcUserLink);
|
||||||
|
kcUserLink.querySelector("div").innerHTML = "Account-Einstellungen";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user