1
0
mirror of https://github.com/StarGazer114/stargazer114.github.io.git synced 2025-01-09 23:08:16 +08:00
stargazer114.github.io/pluginsSrc/butterfly-extsrc/dist/activate-power-mode.min.js

1 line
3.7 KiB
JavaScript
Raw Normal View History

2025-01-05 20:41:38 +08:00
const POWERMODE=(()=>{const t=document.createElement("canvas"),e=t.getContext("2d"),o=[];let n=0,i=!1;const r=()=>{t.width=window.innerWidth,t.height=window.innerHeight},a=(t,e)=>Math.random()*(e-t)+t,d=t=>{if(POWERMODE.colorful){const t=a(0,360);return`hsla(${a(t-10,t+10)}, 100%, ${a(50,80)}%, 1)`}return window.getComputedStyle(t).color},l=()=>{const t=document.activeElement;if("TEXTAREA"===t.tagName||"INPUT"===t.tagName&&["text","email"].includes(t.type)){const{left:e,top:o}=t.getBoundingClientRect(),n=((t,e)=>{const o=null!=window.mozInnerScreenX,n=document.createElement("div");n.id="input-textarea-caret-position-mirror-div",document.body.appendChild(n);const i=n.style,r=window.getComputedStyle?getComputedStyle(t):t.currentStyle;i.whiteSpace="pre-wrap","INPUT"!==t.nodeName&&(i.wordWrap="break-word"),i.position="absolute",i.visibility="hidden",["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize","MozTabSize"].forEach((t=>{i[t]=r[t]})),o?t.scrollHeight>parseInt(r.height)&&(i.overflowY="scroll"):i.overflow="hidden",n.textContent=t.value.substring(0,e),"INPUT"===t.nodeName&&(n.textContent=n.textContent.replace(/\s/g," "));const a=document.createElement("span");a.textContent=t.value.substring(e)||".",n.appendChild(a);const d={top:a.offsetTop+parseInt(r.borderTopWidth),left:a.offsetLeft+parseInt(r.borderLeftWidth)};return document.body.removeChild(n),d})(t,t.selectionEnd);return{x:n.left+e,y:n.top+o,color:d(t),element:t}}const e=window.getSelection();if(e.rangeCount){const t=e.getRangeAt(0),o=t.startContainer.nodeType===Node.TEXT_NODE?t.startContainer.parentNode:t.startContainer,{left:n,top:i}=t.getBoundingClientRect();return{x:n,y:i,color:d(o),element:o}}return{x:0,y:0,color:"transparent",element:null}},s=()=>{i=!0,e.clearRect(0,0,t.width,t.height);let n=!1;const r=t.getBoundingClientRect();o.forEach((t=>{t.alpha<=.1||(t.velocity.y+=.075,t.x+=t.velocity.x,t.y+=t.velocity.y,t.alpha*=.96,e.globalAlpha=t.alpha,e.fillStyle=t.color,e.fillRect(Math.round(t.x-1.5)-r.left,Math.round(t.y-1.5)-r.top,3,3),n=!0)})),n?requestAnimationFrame(s):i=!1},c={colorful:!1,shake:!0,mobile:!1,init:()=>{!c.mobile&&/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)||(t.width=window.innerWidth,t.height=window.innerHeight,t.style.cssText="position:fixed;top:0;left:0;pointer-events:none;z-index:999999",document.body.appendChild(t),window.addEventListener("resize",r))},explode:()=>{const t=l();(t=>{const e=5+Math.round(10*Math.random());for(let d=0;d<e;d++)o[n]=(i=t.x,r=t.y,a=t.color,{x:i,y:r,alpha:1,color:a,velocity:{x:2*Math.random()-1,y:2*Math.random()-3.5}}),n=(n+1)%500;var i,r,a})(t),(t=>{if(POWERMODE.shake){const e=1+2*Math.random(),o=e*(Math.random()>.5?-1:1),n=e*(Math.random()>.5?-1:1);if(document.body.style.marginLeft=`${o}px`,document.body.style.marginTop=`${n}px`,!t||"INPUT"!==t.tagName&&"TEXTAREA"!==t.tagName)setTimeout((()=>{document.body.style.marginLeft="",document.body.style.marginTop=""}),75);else{const e=t.style.position,i=t.style.transition;t.style.position="relative",t.style.transition="none",t.style.transform=`translate(${o}px, ${n}px)`,setTimeout((()=>{t.style.position=e,t.style.transition=i,t.style.transform="",document.body.style.marginLeft="",document.body.style.marginTop=""}),75)}}})(t.element),i||requestAnimationFrame(s)}};return c})();POWERMODE.init(),document.body.addEventListener("input",POWERMODE.explode);