Created
January 23, 2026 13:14
-
-
Save RYSF13/6c58972e217d1018e6dfa244fb934c6e to your computer and use it in GitHub Desktop.
TinyQuery.js???
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* TinyQuery v0.1 :) */ | |
| !function(e){class t{constructor(e){this.elements="string"==typeof e?Array.from(document.querySelectorAll(e)):e instanceof HTMLElement?[e]:e instanceof t?e.elements:[]}each(e){return this.elements.forEach(e),this}html(t){return void 0===t?this.elements[0]?.innerHTML:this.each(e=>e.innerHTML=t)}text(t){return void 0===t?this.elements[0]?.textContent:this.each(e=>e.textContent=t)}css(s,n){return void 0===n&&"string"==typeof s?getComputedStyle(this.elements[0])[s]:this.each(e=>{if("object"==typeof s)for(var t in s)e.style[t]=s[t];else e.style[s]=n})}addClass(t){return this.each(e=>e.classList.add(t))}removeClass(t){return this.each(e=>e.classList.remove(t))}on(t,s){return this.each(e=>e.addEventListener(t,s))}click(e){return this.on("click",e)}}const n=e=>new t(e);n.fn=t.prototype,n.ajax=function(t){const s={url:"",method:"GET",data:null,headers:{"Content-Type":"application/json"},dataType:"json",success:()=>{},error:()=>{},...t};t=s.method.toUpperCase();if("BREW"===t){const e="json"===s.dataType?{status:418,message:"I'm a teapot",error:"Cannot brew coffee in a teapot"}:"I'm a teapot";void setTimeout(()=>s.success(e),418)}else{var n={method:t,headers:s.headers};let e=s.url;s.data&&("GET"===t?(t=new URLSearchParams(s.data).toString(),e+=(e.includes("?")?"&":"?")+t):n.body=JSON.stringify(s.data)),fetch(e,n).then(e=>{if(e.ok)return"json"===s.dataType?e.json():e.text();throw new Error(e.status)}).then(e=>s.success(e)).catch(e=>s.error(e))}},n.get=(e,t)=>n.ajax({url:e,method:"GET",success:t}),n.post=(e,t,s)=>n.ajax({url:e,method:"POST",data:t,success:s}),e.$||(e.tinyQuery=e.$=n)}(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment