-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1 lines (1 loc) · 3.31 KB
/
index.js
1
document.addEventListener("DOMContentLoaded",()=>{document.getElementById("chat-search").addEventListener("click",()=>{var e=document.querySelector(".cis-header-search");e.action="https://www.ecosia.org/chat",e.submit(),console.log(e)})});const timer={init:function(){timer.cell=document.querySelector('.grid-cell[data-label="Timer"]'),timer.cell.classList.add("timer","static"),timer.iframe=document.createElement("IFRAME"),timer.iframe.className=timer.cell.className,timer.iframe.src="https://gcm.schule/timer/#embed",timer.iframe.allowFullscreen=!0,timer.cell.replaceWith(timer.iframe)}},vp=(document.addEventListener("DOMContentLoaded",timer.init),{init:function(){vp.cell=document.querySelector('.grid-cell[data-label="Vertretungsplan"]'),vp.cell.removeAttribute("href"),vp.cell.classList.add("vertretungsplan"),vp.cell.classList.add("static"),vp.cell.innerHTML+='<div class="spinner"></div>';fetch("https://gcm.schule/cis/api/plan/sus").then(e=>{if(e.ok)return e.json();vp.error(vp.errors.failed)}).then(e=>{vp.cell.innerHTML="",vp.populate(e)}).catch(e=>{console.error(e),vp.error(vp.errors.failed)})},populate:function(e){if(!e)return vp.error(vp.errors.empty);const t=a("div",{class:"vp-general"},[a("div",{class:"vp-header"},new Date(e.date).toLocaleDateString("de-DE",{weekday:"long",year:"numeric",month:"long",day:"numeric"}))]),r=(e.info.forEach(e=>t.append(a("div",{class:"vp-content"},e))),a("div",{class:"vp-container"},[t]));function a(e,t={},r=[]){const n=document.createElement(e);for(attr in t)n.setAttribute(attr,t[attr]);return"string"==typeof r?n.innerHTML=r:r.forEach(e=>n.append(e)),n}vp.cell.append(r),e.list.forEach(e=>{const l=a("div",{class:"vp-body"});r.append(a("div",{class:"vp-header"},[a("div",{class:"class-label"},e.name)]),l),e.contents.forEach(e=>{var t=e.type||"",r=e.note||"",n=e=>"object"==typeof e?`<s>${e.old}</s> <strong>${e.new}</strong>`:e||"";l.append(a("div",{class:"vp-content"},[a("div",{class:"vp-content1"},(e.time?`<strong>${e.time||""}.</strong> `:"")+n(e.subject)),a("div",{class:"vp-content2"},n(e.room)),a("div",{class:"vp-content3"},"Vertretung"==e.type?n(e.teacher):""),a("div",{class:"vp-content3"},t+(t&&r?": ":"")+r)]))})}),vp.cell.innerHTML+=`<a class="button" href="https://gcm.schule/vertretungsplan/" target="_blank" rel="noreferrer">Vertretungsplan öffnen ${vp.external_link_icon}</a>`},error:function(e){-1<Object.values(vp.errors).indexOf(e)?console.error(e):console.error("unknown error"),vp.cell.innerHTML="",vp.cell.appendChild(document.createTextNode("Kein Vertretungsplan verfügbar"));var t=document.createElement("DIV"),e=(t.innerHTML=e,t.classList.add("subtitle","error-message"),vp.cell.appendChild(t),document.createElement("A"));e.innerHTML="DSB "+vp.external_link_icon,e.setAttribute("href","https://dsbmobile.de"),e.setAttribute("class","button primary"),e.setAttribute("rel","noreferrer"),vp.cell.appendChild(e)},errors:{failed:"network unreachable or request failed",empty:"no data available"},external_link_icon:'<svg width="16" height="16" viewBox="0 1 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>'});document.addEventListener("DOMContentLoaded",vp.init);