// ==UserScript== // @name Agora Fast Booking // @namespace https://agora.fastweb.it/ // @version 4.6.3 // @description BOOXX — Bulk desk booking with smart seat matching, rebook & cancel for Agora // @icon https://raw.githubusercontent.com/Bonobomagno/solid-fast-booking-dist/main/logo-icon.png // @downloadURL https://raw.githubusercontent.com/Bonobomagno/solid-fast-booking-dist/main/solid-fast-booking.user.js // @updateURL https://raw.githubusercontent.com/Bonobomagno/solid-fast-booking-dist/main/solid-fast-booking.meta.js // @match https://agora.fastweb.it/* // @grant GM_getValue // @grant GM_setValue // @run-at document-idle // ==/UserScript== (function () { 'use strict'; const Xt=(e,t)=>e===t,fe=Symbol("solid-proxy"),ot=Symbol("solid-track"),Ne={equals:Xt};let Bt=Ft;const ae=1,Re=2,Mt={owned:null,cleanups:null,context:null,owner:null};var R=null;let Qe=null,N=null,G=null,oe=null,Je=0;function _e(e,t){const n=N,o=R,i=e.length===0,s=t===void 0?o:t,l=i?Mt:{owned:null,cleanups:null,context:s?s.context:null,owner:s},r=i?e:()=>e(()=>re(()=>Oe(l)));R=l,N=null;try{return me(r,!0)}finally{N=n,R=o;}}function Z(e,t){t=t?Object.assign({},Ne,t):Ne;const n={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},o=i=>(typeof i=="function"&&(i=i(n.value)),jt(n,i));return [Et.bind(n),o]}function T(e,t,n){const o=dt(e,t,false,ae);Le(o);}function Ve(e,t,n){Bt=nn;const o=dt(e,t,false,ae);o.user=true,oe?oe.push(o):Le(o);}function xe(e,t,n){n=n?Object.assign({},Ne,n):Ne;const o=dt(e,t,true,0);return o.observers=null,o.observerSlots=null,o.comparator=n.equals||void 0,Le(o),Et.bind(o)}function Jt(e){return me(e,false)}function re(e){if(N===null)return e();const t=N;N=null;try{return e()}finally{N=t;}}function Ot(e){Ve(()=>re(e));}function Qt(e){return R===null||(R.cleanups===null?R.cleanups=[e]:R.cleanups.push(e)),e}function st(){return N}function Et(){if(this.sources&&this.state)if(this.state===ae)Le(this);else {const e=G;G=null,me(()=>Ue(this),false),G=e;}if(N){const e=this.observers?this.observers.length:0;N.sources?(N.sources.push(this),N.sourceSlots.push(e)):(N.sources=[this],N.sourceSlots=[e]),this.observers?(this.observers.push(N),this.observerSlots.push(N.sources.length-1)):(this.observers=[N],this.observerSlots=[N.sources.length-1]);}return this.value}function jt(e,t,n){let o=e.value;return (!e.comparator||!e.comparator(o,t))&&(e.value=t,e.observers&&e.observers.length&&me(()=>{for(let i=0;i1e6)throw G=[],new Error},false)),t}function Le(e){if(!e.fn)return;Oe(e);const t=Je;en(e,e.value,t);}function en(e,t,n){let o;const i=R,s=N;N=R=e;try{o=e.fn(t);}catch(l){return e.pure&&(e.state=ae,e.owned&&e.owned.forEach(Oe),e.owned=null),e.updatedAt=n+1,Lt(l)}finally{N=s,R=i;}(!e.updatedAt||e.updatedAt<=n)&&(e.updatedAt!=null&&"observers"in e?jt(e,o):e.value=o,e.updatedAt=n);}function dt(e,t,n,o=ae,i){const s={fn:e,state:o,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:R,context:R?R.context:null,pure:n};return R===null||R!==Mt&&(R.owned?R.owned.push(s):R.owned=[s]),s}function Ye(e){if(e.state===0)return;if(e.state===Re)return Ue(e);if(e.suspense&&re(e.suspense.inFallback))return e.suspense.effects.push(e);const t=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt=0;n--)if(e=t[n],e.state===ae)Le(e);else if(e.state===Re){const o=G;G=null,me(()=>Ue(e,t[0]),false),G=o;}}function me(e,t){if(G)return e();let n=false;t||(G=[]),oe?n=true:oe=[],Je++;try{const o=e();return tn(n),o}catch(o){n||(oe=null),G=null,Lt(o);}}function tn(e){if(G&&(Ft(G),G=null),e)return;const t=oe;oe=null,t.length&&me(()=>Bt(t),false);}function Ft(e){for(let t=0;t=0;t--)Oe(e.tOwned[t]);delete e.tOwned;}if(e.owned){for(t=e.owned.length-1;t>=0;t--)Oe(e.owned[t]);e.owned=null;}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null;}e.state=0;}function on(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function Lt(e,t=R){throw on(e)}const sn=Symbol("fallback");function ht(e){for(let t=0;t1?[]:null;return Qt(()=>ht(s)),()=>{let a=e()||[],u=a.length,d,g;return a[ot],re(()=>{let f,p,b,m,h,A,v,y,D;if(u===0)l!==0&&(ht(s),s=[],o=[],i=[],l=0,r&&(r=[])),n.fallback&&(o=[sn],i[0]=_e(k=>(s[0]=k,n.fallback())),l=1);else if(l===0){for(i=new Array(u),g=0;g=A&&y>=A&&o[v]===a[y];v--,y--)b[y]=i[v],m[y]=s[v],r&&(h[y]=r[v]);for(f=new Map,p=new Array(y+1),g=y;g>=A;g--)D=a[g],d=f.get(D),p[g]=d===void 0?-1:d,f.set(D,g);for(d=A;d<=v;d++)D=o[d],g=f.get(D),g!==void 0&&g!==-1?(b[g]=i[d],m[g]=s[d],r&&(h[g]=r[d]),g=p[g],f.set(D,g)):s[d]();for(g=A;ge(t||{}))}const rn=e=>`Stale read from <${e}>.`;function se(e){const t="fallback"in e&&{fallback:()=>e.fallback};return xe(ln(()=>e.each,e.children,t||void 0))}function te(e){const t=e.keyed,n=xe(()=>e.when,void 0,void 0),o=t?n:xe(n,void 0,{equals:(i,s)=>!i==!s});return xe(()=>{const i=o();if(i){const s=e.children;return typeof s=="function"&&s.length>0?re(()=>s(t?i:()=>{if(!re(o))throw rn("Show");return n()})):s}return e.fallback},void 0,void 0)}const Ee=e=>xe(()=>e());function an(e,t,n){let o=n.length,i=t.length,s=o,l=0,r=0,a=t[i-1].nextSibling,u=null;for(;ld-r){const p=t[l];for(;r{i=s,t===document?e():I(t,e(),t.firstChild?null:void 0,n);},o.owner),()=>{i(),t.textContent="";}}function L(e,t,n,o){let i;const s=()=>{const r=document.createElement("template");return r.innerHTML=e,r.content.firstChild},l=()=>(i||(i=s())).cloneNode(true);return l.cloneNode=l,l}function le(e,t=window.document){const n=t[xt]||(t[xt]=new Set);for(let o=0,i=e.length;oe(t,n))}function I(e,t,n,o){if(n!==void 0&&!o&&(o=[]),typeof t!="function")return We(e,t,o,n);T(i=>We(e,t(),i,n),o);}function cn(e){let t=e.target;const n=`$$${e.type}`,o=e.target,i=e.currentTarget,s=a=>Object.defineProperty(e,"target",{configurable:true,value:a}),l=()=>{const a=t[n];if(a&&!t.disabled){const u=t[`${n}Data`];if(u!==void 0?a.call(t,u,e):a.call(t,e),e.cancelBubble)return}return t.host&&typeof t.host!="string"&&!t.host._$host&&t.contains(e.target)&&s(t.host),true},r=()=>{for(;l()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:true,get(){return t||document}}),e.composedPath){const a=e.composedPath();s(a[0]);for(let u=0;u{let r=t();for(;typeof r=="function";)r=r();n=We(e,r,n,o);}),()=>n;if(Array.isArray(t)){const r=[],a=n&&Array.isArray(n);if(lt(r,t,n,i))return T(()=>n=We(e,r,n,o,true)),()=>n;if(r.length===0){if(n=pe(e,n,o),l)return n}else a?n.length===0?yt(e,r,o):an(e,n,r):(n&&pe(e),yt(e,r));n=r;}else if(t.nodeType){if(Array.isArray(n)){if(l)return n=pe(e,n,o,t);pe(e,n,null,t);}else n==null||n===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t;}}return n}function lt(e,t,n,o){let i=false;for(let s=0,l=t.length;s=0;l--){const r=t[l];if(i!==r){const a=r.parentNode===e;!s&&!l?a?e.replaceChild(i,r):e.insertBefore(i,n):a&&r.remove();}else s=true;}}else e.insertBefore(i,n);return [i]}const rt=Symbol("store-raw"),ye=Symbol("store-node"),ne=Symbol("store-has"),zt=Symbol("store-self");function _t(e){let t=e[fe];if(!t&&(Object.defineProperty(e,fe,{value:t=new Proxy(e,gn)}),!Array.isArray(e))){const n=Object.keys(e),o=Object.getOwnPropertyDescriptors(e);for(let i=0,s=n.length;ie[fe][t]),n}function Nt(e){st()&&Fe(qe(e,ye),zt)();}function un(e){return Nt(e),Reflect.ownKeys(e)}const gn={get(e,t,n){if(t===rt)return e;if(t===fe)return n;if(t===ot)return Nt(e),n;const o=qe(e,ye),i=o[t];let s=i?i():e[t];if(t===ye||t===ne||t==="__proto__")return s;if(!i){const l=Object.getOwnPropertyDescriptor(e,t);st()&&(typeof s!="function"||e.hasOwnProperty(t))&&!(l&&l.get)&&(s=Fe(o,t,s)());}return Ge(s)?_t(s):s},has(e,t){return t===rt||t===fe||t===ot||t===ye||t===ne||t==="__proto__"?true:(st()&&Fe(qe(e,ne),t)(),t in e)},set(){return true},deleteProperty(){return true},ownKeys:un,getOwnPropertyDescriptor:fn};function Ke(e,t,n,o=false){if(!o&&e[t]===n)return;const i=e[t],s=e.length;n===void 0?(delete e[t],e[ne]&&e[ne][t]&&i!==void 0&&e[ne][t].$()):(e[t]=n,e[ne]&&e[ne][t]&&i===void 0&&e[ne][t].$());let l=qe(e,ye),r;if((r=Fe(l,t,i))&&r.$(()=>n),Array.isArray(e)&&e.length!==s){for(let a=e.length;a1){o=t.shift();const l=typeof o,r=Array.isArray(e);if(Array.isArray(o)){for(let a=0;a1){Se(e[o],t,[o].concat(n));return}i=e[o],n=[o].concat(n);}let s=t[0];typeof s=="function"&&(s=s(i,n),s===i)||o===void 0&&s==null||(s=je(s),o===void 0||Ge(i)&&Ge(s)&&!Array.isArray(s)?Rt(i,s):Ke(e,o,s));}function bn(...[e,t]){const n=je(e||{}),o=Array.isArray(n),i=_t(n);function s(...l){Jt(()=>{o&&l.length===1?pn(n,l[0]):Se(n,l);});}return [i,s]}const[$,C]=bn({userId:null,sede:null,sedeNumeric:null,floors:[],islands:{},mapData:{},availability:{},plan:[],scanning:false,booking:false,planIndex:0,drawerOpen:false,progress:[],logs:[],bookButtonState:"idle",resumeAvailable:false}),[ie,Vt]=Z(null),[De,et]=Z(new Set);function B(e){const t=new Date().toLocaleTimeString("it-IT");C("logs",n=>[...n,`[${t}] ${e}`]);}function Yt(e,t){C("progress",n=>[...n,{label:e,completed:0,total:t,done:false,success:false}]);}function He(e,t,n){C("progress",o=>o.label===e,{completed:t,total:n});}function Ut(e,t){C("progress",n=>n.label===e,{done:true,success:t});}const x={green:"#22c55e",yellow:"#eab308",orange:"#f97316",red:"#ef4444",blue:"#3b82f6",gray:"#6b7280",purple:"#8b5cf6",primary:"#1565c0",white:"#ffffff",border:"#e2e8f0",text:"#1e293b",textMuted:"#64748b"},kt={primary:x.green,"fallback-same-island":x.yellow,"fallback-same-floor":x.orange,"fallback-other-floor":x.orange,"no-seat-available":x.red,"already-booked":x.blue,rebook:x.purple,cancel:x.red,skip:x.gray},hn="display:inline-flex;align-items:center;justify-content:center;height:18px;border:none;border-radius:3px;padding:0 6px;font-size:10px;font-weight:600;user-select:none;line-height:1;white-space:nowrap;";function Pe(e,t,n){return hn+`background:${e};color:${t};`+(n?"cursor:pointer;opacity:1;":"cursor:not-allowed;opacity:0.3;")}const Wt="P01B",xn=["Do","Lu","Ma","Me","Gi","Ve","Sa"],Te=["P01B","P02B","P03B","P04B","P05B"],yn={P01B:["ISOLA128"],P02B:["ISOLA238"],P03B:["ISOLA347","ISOLA336","ISOLA334","ISOLA337"],P04B:["ISOLA439","ISOLA441","ISOLA445","ISOLA447"],P05B:["ISOLA522","ISOLA523","ISOLA524","ISOLA525","ISOLA527"]},Xe=[],Gt="FT",qt=4,mt=200,tt=1e3,be=3;function Ce(e,t,n){return fetch(e,{credentials:"same-origin",...t,signal:n??t?.signal})}function X(e){const t=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0");return `${t}-${n}-${o}`}function U(e){const[,t,n]=e.split("-");return `${n}/${t}`}function nt(e){const[t,n,o]=e.split("-");return `${o}/${n}/${t}`}function kn(e){const t=new Date(e+"T00:00:00");return xn[t.getDay()]}function ze(e,t){const n=[],o=new Date(e+"T00:00:00"),i=new Date(t+"T00:00:00");for(let s=new Date(o);s<=i;s.setDate(s.getDate()+1)){const l=s.getDay();if(l===0||l===6)continue;const r=X(s);Xe.includes(r)||n.push(r);}return n}function mn(){const e=/^\d{4}-\d{2}-\d{2}$/;for(const t of Xe)e.test(t)||console.warn(`[ABA] Warning: invalid holiday format "${t}" — expected YYYY-MM-DD`);}const Be=e=>new Promise(t=>setTimeout(t,e));function vn(e,t){let n;return function(...o){clearTimeout(n),n=setTimeout(()=>e.apply(this,o),t);}}function ce(e){if(!e)return "";const t=e.replace("ISOLA","");if(t.length>=2){const n=t.slice(0,-2),o=t.slice(-2);return n+"-"+o}return t}async function Kt(e,t,n,o){const i=new Array(e.length);let s=0;async function l(a){for(await Be(a*Math.floor(mt/n));s1){n=Array.from(i.options).map(s=>s.value);break}}n.length||(n=["P01B","P02B","P03B","P04B","P05B"]),C("floors",n.filter(o=>Te.includes(o))),B(`User: ${$.userId||"?"}, Sede: ${$.sede||"?"}, Floors: ${$.floors.join(", ")}`);}async function An(e,t,n){const i=`/deskbooking/mappa/${$.sede||"SY"}/${e}/${t}`,s=await Ce(i,{headers:{Accept:"text/html"}},n);if(!s.ok)throw new Error(`HTTP ${s.status} for ${e}/${U(t)}`);const l=await s.text(),a=new DOMParser().parseFromString(l,"text/html").querySelector('script[data-drupal-selector="drupal-settings-json"]');if(!a)throw new Error(`No settings in ${e}/${U(t)}`);const d=JSON.parse(a.textContent||"").deskbooking||{};!$.sedeNumeric&&d.tid_sede&&C("sedeNumeric",d.tid_sede);const g=yn[e]||[],c=(d.isole||[]).filter(p=>!g.includes(p.id)).map(p=>({id:p.id,name:p.nome_isola||p.id,posti:parseInt(String(p.posti),10)||0})),f=d.prenotazione||null;return {floor:e,dateStr:t,islands:c,prenotazione:f}}var vt=typeof GM_getValue<"u"?GM_getValue:void 0,wt=typeof GM_setValue<"u"?GM_setValue:void 0;const[he,Ie]=Z(null),[Ht,$e]=Z(null),[ke,Me]=Z(Wt);function Sn(){const e=vt("aba-seat",""),t=vt("aba-floor",Wt);if(e){let n=e.trim().toUpperCase();const o=n.match(/^(\d+)-(\d+)-(\d+)$/);o&&(n=o[1]+o[2]+"P"+o[3]),Ie(n);const i=n.match(/^(\d+)P/);$e(i?"ISOLA"+i[1]:null);const l="P0"+n.charAt(0)+"B";Te.includes(l)&&Me(l);}t&&Te.includes(t)&&!e&&Me(t);}function In(){Ve(()=>{const e=he();wt("aba-seat",e||"");}),Ve(()=>{const e=ke();wt("aba-floor",e);});}var $n=L('
BOOXXBOOXX v
'),Fn=L("