javascript:(async()=>{function y(e,t){return e.reduce((o,n,i)=>o+n+(t[i]??""),"").replace(/>\s+<").replace(/\s+/g," ").trim()}var h=(e,...t)=>y(e,t),b=(e,...t)=>y(e,t);var S="__NICE_PROXY_SERVER_URL__",E="__NICE_PROXY_USER__",I="__NICE_PROXY_TOKEN__";(async function(){"use strict";let e="https://uber.nicecloudsvc.com/wfm/webstation/my-schedule";if(!location.href.startsWith(e)){location.href=e;return}let t=document.querySelector("iframe");if(!t){alert("No schedule iframe found. Make sure you're on the NICE schedule page.");return}let o=C(t),n=o?x(o):new Date,i=await N(n);if(!i)return;let s=await F(t,i);if(console.log(`[NICE Upload] Total events: ${s.length}`),s.length===0){alert("No events found to upload.");return}let{wfhDaysSet:a}=$(s),{wfoDays:l,wfhDays:r}=k(s,a),c=Object.keys(l).length,d=Object.keys(r).length;console.log(`[NICE Upload] Redirecting with ${c} WFO days, ${d} WFH days`);let u={user:E,token:I,wfo:l,wfh:r};window.location.href=`${S}/upload#${encodeURIComponent(JSON.stringify(u))}`})();function k(e,t){let o=r=>`${r.getFullYear()}-${r.getMonth()}-${r.getDate()}`,n=r=>{let c=r.getFullYear(),d=String(r.getMonth()+1).padStart(2,"0"),u=String(r.getDate()).padStart(2,"0");return`${c}-${d}-${u}`},i=new Map;for(let r of e){let c=o(r.start);i.has(c)||i.set(c,n(r.start))}let s={},a={};for(let r of i.values())s[r]=[],a[r]=[];let l={};for(let r of e){let c=o(r.start),d=i.get(c),u=l[d]??0;l[d]=u+1;let g={key:`${d}#${u}`,summary:r.summary,start:r.start.toISOString(),end:r.end.toISOString(),status:"CONFIRMED"};t.has(c)?a[d].push(g):s[d].push(g)}return{wfoDays:s,wfhDays:a}}function $(e){let t=a=>`${a.getFullYear()}-${a.getMonth()}-${a.getDate()}`,o=new Map;for(let a of e){let l=t(a.start);o.has(l)||o.set(l,[]),o.get(l).push(a)}let n=new Set;for(let[a,l]of o)l.some(r=>r.summary.trimEnd().endsWith("WFH"))&&n.add(a);let i=[],s=[];for(let a of e)n.has(t(a.start))?i.push(a):s.push(a);return{wfh:i,wfo:s,wfhDaysSet:n}}function N(e){return new Promise(t=>{let o=L(e),n=document.createElement("dialog");n.innerHTML=h`

Upload Date Range

Leave blank to scrape until an empty week is reached.
`,n.classList.add("date-range");let i=!1,s=a=>{i||(i=!0,n.close(),n.remove(),t(a))};document.body.appendChild(n),n.showModal(),n.querySelector(".btn-start").addEventListener("click",()=>{let a=n.querySelector("#dr-start"),l=n.querySelector("#dr-end");if(!a.value){a.focus();return}let[r,c,d]=a.value.split("-").map(Number),u=new Date(r,c-1,d),g=null;if(l.value){let[p,f,m]=l.value.split("-").map(Number);g=new Date(p,f-1,m)}s({start:u,end:g})}),n.querySelector(".btn-cancel").addEventListener("click",()=>s(null)),n.querySelector(".btn-close").addEventListener("click",()=>s(null)),n.addEventListener("cancel",()=>s(null))})}function x(e){let t=parseInt(e.slice(1,3),10),o=parseInt(e.slice(3,5),10),n=parseInt(e.slice(5,7),10);return new Date(2e3+t,o-1,n)}function C(e){return(e.contentWindow?.location.href??e.src??"").match(/startDay=(\d+)/)?.[1]??null}function R(e){let t=String(e.getFullYear()%25100).padStart(2,"0"),o=String(e.getMonth()+1).padStart(2,"0"),n=String(e.getDate()).padStart(2,"0");return`1${t}${o}${n}`}function M(e){return`https://uber.nicecloudsvc.com/agent/displayMyScheduleAction.mvc?startDay=${e}&viewFormat=weekly`}async function T(e,t,o=2e4){return new Promise(n=>{let i=setTimeout(()=>{console.log(`[NICE Upload] Navigation timed out after ${o}ms`),n(!1)},o);e.addEventListener("load",()=>{clearTimeout(i),n(!0)},{once:!0}),e.contentWindow.location.href=t})}async function F(e,t){let o=[],n=t.end?1/0:52;console.log(`[NICE Upload] Starting from: ${t.start.toDateString()}`+(t.end?`, ending at week containing: ${t.end.toDateString()}`:` (go until done, cap ${n})`));for(let a=0;at.end)break;let r=M(R(l));if(console.log(`[NICE Upload] Page ${a+1}: navigating to ${r}`),!await T(e,r)){console.log("[NICE Upload] Navigation timed out, stopping");break}let d=e.contentDocument;if(!d){console.log("[NICE Upload] No iframe document, stopping");break}let u=_(d);if(u.length===0){if(t.end){console.log(`[NICE Upload] Page ${a+1}: no rows, continuing (end date set)`);continue}console.log(`[NICE Upload] Page ${a+1}: no rows, stopping`);break}let g=U(u);console.log(`[NICE Upload] Page ${a+1}: ${g.length} events`),o.push(...g)}let i=new Date(t.start.getFullYear(),t.start.getMonth(),t.start.getDate()),s=t.end?new Date(t.end.getFullYear(),t.end.getMonth(),t.end.getDate(),23,59,59,999):null;return o.filter(a=>!(a.starts))}function _(e){return Array.from(e.querySelectorAll("#scheduleDetailTableDiv > table tr")).filter(t=>{let o=t.textContent.trim();return!(t.className==="schedTableHdr"||o===""||o==="Add an activity"||o.endsWith("OFF")||o.endsWith("No data available")||t.children.length===1)}).map(t=>Array.from(t.children))}function U(e){let t=[],o,n,i;for(let s of e){if(s[0]?.querySelector('[title="Trade schedule"]')){let w=s[1]?.textContent?.trim(),[,v]=w?.split(" ")??["",""];[n,i,o]=v.split("/").map(Number)}let l=s[s.length-5]?.textContent?.trim()??"",r=s[s.length-4]?.textContent?.trim()??"12:00 AM",c=s[s.length-3]?.textContent?.trim()??"12:00 AM",[d,u]=D(r),[g,p]=D(c),f=new Date(2e3+o,n-1,i,d,u,0,0),m=new Date(2e3+o,n-1,i,g,p,0,0);m