ghost / sand.js
autobahn247365's picture
Ghost v1.4 — One List + Storm added to menu
1839ce1 verified
Raw History Blame Contribute Delete
3.59 kB
(()=>{
const css=`#sandbar{position:fixed;top:8px;right:8px;z-index:99999;display:flex;gap:6px;flex-wrap:wrap;justify-content:flex-end;font:13px system-ui}
#sandbar a,#sandbar button{background:rgba(10,16,32,.85);color:#f3e2b3;border:1px solid #c9a75d;border-radius:20px;padding:6px 11px;text-decoration:none;cursor:pointer;font:inherit}
#sandbar button.on{background:#c9a75d;color:#05070d}`;
const st=document.createElement('style');st.textContent=css;document.head.appendChild(st);
const bar=document.createElement('div');bar.id='sandbar';
bar.innerHTML=`<a href="/todo/">✅ One List</a><a href="/">🌍 Ghost</a><a href="/spidey.html">🕸️ Spidey</a><a href="/jump/">⬆️ Jump</a><a href="/storm/">🌪️ Storm</a><a href="/bgg.html">📊 Gantt</a><a href="/drop/">👻 Drop</a><button id="sandbtn">▶ SAND</button>`;
document.body.appendChild(bar);
const btn=document.getElementById('sandbtn');
let ctx,master,timer=null,step=0;
const BPM=96,S=60/BPM/2;
const hook=[62,0,69,66,0,64,62,0, 69,0,71,69,66,0,64,0, 62,0,69,66,0,64,66,0, 69,71,74,0,71,69,66,0];
const bass=[38,38,0,38,45,0,45,0, 43,43,0,43,40,0,40,0];
const f=m=>440*Math.pow(2,(m-69)/12);
function note(m,t,d,type,vol){const o=ctx.createOscillator(),g=ctx.createGain();o.type=type;o.frequency.value=f(m);
g.gain.setValueAtTime(0,t);g.gain.linearRampToValueAtTime(vol,t+.01);g.gain.exponentialRampToValueAtTime(.0001,t+d);o.connect(g).connect(master);o.start(t);o.stop(t+d+.05)}
function noise(sec){const b=ctx.createBuffer(1,ctx.sampleRate*sec,ctx.sampleRate),d=b.getChannelData(0);for(let i=0;i<d.length;i++)d[i]=Math.random()*2-1;return b}
function shaker(t,vol){const s=ctx.createBufferSource();s.buffer=noise(.08);const hp=ctx.createBiquadFilter();hp.type='highpass';hp.frequency.value=6000;
const g=ctx.createGain();g.gain.setValueAtTime(vol,t);g.gain.exponentialRampToValueAtTime(.0001,t+.07);s.connect(hp).connect(g).connect(master);s.start(t)}
function waves(){const s=ctx.createBufferSource();s.buffer=noise(4);s.loop=true;const lp=ctx.createBiquadFilter();lp.type='lowpass';lp.frequency.value=700;
const g=ctx.createGain();g.gain.value=.05;const lfo=ctx.createOscillator(),lg=ctx.createGain();lfo.frequency.value=.12;lg.gain.value=.045;
lfo.connect(lg).connect(g.gain);s.connect(lp).connect(g).connect(master);s.start();lfo.start()}
function tick(){const t=ctx.currentTime+.05;
const h=hook[step%32];if(h)note(h,t,S*1.6,'triangle',.18);
const b=bass[step%16];if(b)note(b,t,S*1.8,'sine',.25);
shaker(t,step%2?.05:.12);
if(step%8===0)note(step%32<16?74:78,t,S*6,'sine',.05);
step++}
function play(){if(!ctx){ctx=new (window.AudioContext||window.webkitAudioContext)();master=ctx.createGain();master.gain.value=.7;master.connect(ctx.destination);waves()}
ctx.resume();if(!timer)timer=setInterval(tick,S*1000);btn.textContent='❚❚ SAND';btn.classList.add('on');localStorage.sand='on'}
function stop(){clearInterval(timer);timer=null;ctx&&ctx.suspend();btn.textContent='▶ SAND';btn.classList.remove('on');localStorage.sand='off'}
btn.onclick=e=>{e.stopPropagation();timer?stop():play()};
if(localStorage.sand!=='off'){
try{play();if(ctx.state!=='running'){clearInterval(timer);timer=null;btn.textContent='▶ SAND';btn.classList.remove('on')}}catch(e){}
const unlock=()=>{if(localStorage.sand!=='off'&&!(timer&&ctx&&ctx.state==='running'))play();
['pointerdown','touchstart','keydown','scroll','wheel'].forEach(ev=>removeEventListener(ev,unlock,true))};
['pointerdown','touchstart','keydown','scroll','wheel'].forEach(ev=>addEventListener(ev,unlock,{capture:true,passive:true}));
}
})();