Repository navigation
Expand file tree
/
Copy pathf3cc.js
More file actions
1 lines (1 loc) · 3.68 KB
/
Copy pathf3cc.js
File metadata and controls
1 lines (1 loc) · 3.68 KB
1
(()=>{var b="f3cc";var v="essential",q=new RegExp(`(?:^|;\\s*)${b}=([^;]*)`),g=()=>document.cookie.match(q)?.[1];var E=".f3cc{font-size:16px;line-height:1.3;--_b:var(--f3cc-background,#e9e9e9);--_f:var(--f3cc-foreground,#000);--_B:var(--f3cc-button-background,#cbcbcb);--_A:var(--f3cc-accept-background,#90f690);--_F:var(--f3cc-button-foreground,var(--_f));--_E:var(--f3cc-accept-foreground,var(--_F))}.f3cc .f3cc-banner{position:fixed;bottom:0;width:100%;background:var(--_b);color:var(--_f);z-index:2000;padding:1rem 1rem 1.25rem}.f3cc .f3cc-embed{background:var(--_b);color:var(--_f);padding:4rem}.f3cc .f3cc-container{display:flex;gap:2rem;max-width:70em;margin:0 auto;width:80%}@media(max-width:60rem){.f3cc .f3cc-container{width:100%;flex-direction:column}}.f3cc .f3cc-title{font-size:1.5em;font-weight:700;margin-bottom:.25em}.f3cc .f3cc-description a{color:inherit;text-decoration:underline}.f3cc .f3cc-description a:hover{opacity:.7}.f3cc .f3cc-buttons{display:flex;flex-direction:column;gap:1rem;justify-content:center;align-items:stretch}.f3cc .f3cc-button{display:inline-block;background:var(--_B);color:var(--_F);padding:.8rem 1.2rem;white-space:nowrap;text-decoration:none;text-align:center;cursor:pointer;border:none}.f3cc .f3cc-button:hover{opacity:.7}.f3cc .f3cc-button.accept{background:var(--_A);color:var(--_E)}.f3cc .f3cc-button.modify{position:fixed;z-index:2000;bottom:1rem;right:1rem}.f3cc-embed .f3cc-description{margin-bottom:1em}";var m=window,f=document,x=(e,t=f)=>t.querySelector(e),S=(e,t=f)=>t.querySelectorAll(e),C=f.body,i="className",a="textContent",N="innerHTML",s=m.f3ccData||JSON.parse(x("#f3cc-data")[a]),w={},$="f3cc-embed-providers",h,l,d,n=(e,t,o=[])=>{let c=f.createElement(e);for(let r in t)c[r]=t[r];return c.append(...o),c},y=()=>{if(l){p(l);return}l=n("div",{[i]:"f3cc f3cc-banner"},[n("div",{[i]:"f3cc-container"},[n("div",{[i]:"f3cc-content"},[n("div",{[i]:"f3cc-title",[a]:s.heading}),n("div",{[i]:"f3cc-description",[N]:s.description})]),n("div",{[i]:"f3cc-buttons"},[n("a",{[i]:"f3cc-button accept",[a]:s.buttonAccept,onclick:A(!0)}),n("a",{[i]:"f3cc-button reject",[a]:s.buttonReject,onclick:A(!1)})])])]),_().append(l)},M=()=>{if(d){p(d);return}let e=x(".f3cc-modify");if(e){d=e,e.addEventListener("click",c=>{c.preventDefault(),y()});return}let t=s.ppu,o=m.location;s.buttonModify&&(!t||t===`${o.protocol}//${o.host}${o.pathname}`)&&(d=n("a",{[i]:"f3cc-button modify",[a]:s.buttonModify,onclick:()=>{p(d,"none"),y()}}),_().append(d))},z=e=>{let t=`${b}=${e};max-age=31536000;path=/;sameSite=Strict`;s.domain&&(t+=`;domain=${s.domain}`),f.cookie=t},F=()=>{let e=g();return"all"===e||v===e},j=()=>g()==="all",p=(e,t="")=>{e&&(e.style.display=t)},A=e=>()=>{z(e?"all":v),p(l,"none"),M(),u(),L(),m.dispatchEvent(new Event(`f3cc_consent_${e?"granted":"denied"}`))},L=()=>{if(j()){for(let e of s.cookies)if(!w[e.name]){let t=w[e.name]=n("div");t.dataset.name=e.name,_().append(t),B(t,e.script)}}},_=()=>(h||C.append(h=n("div",{[i]:"f3cc"})),h),R,T=()=>{let e=R;try{e=JSON.parse(localStorage.getItem($))}catch{}return Array.isArray(e)?e:[]},I=e=>{R=e;try{localStorage.setItem($,JSON.stringify(e))}catch{}},u=()=>{let e=T();for(let t of S(".f3cc-embed")){let o=x("template",t),c=t.dataset.provider;if(o&&c&&(j()||e.includes(c))){let r=o.content.cloneNode(!0);(t.closest(".f3cc")||t).replaceWith(r)}}},B=(e,t)=>{e[N]=t;for(let o of S("script",e)){let c=n("script");for(let r of o.attributes)c.setAttribute(r.name,r.value);c[a]=o[a],o.replaceWith(c)}};f.head.append(n("style",{[a]:E}));m.f3ccRenderEmbeds=u;C.addEventListener("click",e=>{let t=e.target.closest(".f3cc-button"),o=t?.closest(".f3cc-embed");if(t&&o){e.preventDefault();let c=T(),r=o.dataset.provider;c.includes(r)||(c.push(r),I(c)),u()}});L();u();F()?M():y();})();