Skip to content

Instantly share code, notes, and snippets.

@twobob
Last active February 19, 2026 01:45
Show Gist options
  • Select an option

  • Save twobob/f7ab901e8a126fa102d49a9c98aa3be3 to your computer and use it in GitHub Desktop.

Select an option

Save twobob/f7ab901e8a126fa102d49a9c98aa3be3 to your computer and use it in GitHub Desktop.
Bookmarklet to add a "download the last URL played as a file" button temporarily to the acemusic.ai UI - V2 with mp3 conversion
javascript:void%20function(){var%20a=Math.max;function%20b(a,b=%22%23222%22){let%20c=document.getElementById(%22ace-dl-status%22);c||(c=Object.assign(document.createElement(%22div%22),{id:%22ace-dl-status%22}),c.style.cssText=%22position:fixed;bottom:20px;right:20px;padding:10px%2014px;border-radius:8px;font:600%2013px/1.4%20system-ui;z-index:2147483647;box-shadow:0%204px%2012px%20rgba(0,0,0,.35);max-width:340px;word-break:break-word%22,document.body.appendChild(c)),Object.assign(c.style,{background:b,color:%22%23fff%22}),c.textContent=a,clearTimeout(window.__aceStatusTimer),window.__aceStatusTimer=setTimeout(()=%3Ec.remove(),6e3)}function%20c(a){if(!a||%22string%22!=typeof%20a)return!1;const%20b=a.toLowerCase();return%20b.includes(%22ace-music.s3%22)%26%26b.includes(%22/app/user/works/%22)%26%26b.includes(%22awsaccesskeyid=%22)%26%26b.includes(%22signature=%22)}function%20d(a){const%20b=(a||%22%22).split(%22%3F%22)[0].toLowerCase().match(/\.(aac|m4a|mp3|wav|ogg|mp4)$/);return%20b%3Fb[1]:%22mp4%22}function%20e(a){const%20b=(a||%22%22).split(%22%3F%22)[0].split(%22/%22),c=b.findIndex(a=%3E%22works%22===a),e=(0%3C=c%3Fb[c+1]:%22%22)||%22work%22,f=(0%3C=c%3Fb[c+2]:b.at(-1))||%22file%22,g=a=%3Ea.replace(/\.[^.]+$/,%22%22).replace(/[^a-z0-9_-]/gi,%22_%22),h=a=%3E(a+%22%22).padStart(2,%220%22),i=new%20Date,d=`${i.getFullYear()}${h(i.getMonth()+1)}${h(i.getDate())}`+`-${h(i.getHours())}${h(i.getMinutes())}${h(i.getSeconds())}`;return`ace_works-${g(e).slice(0,16)}_${g(f).slice(0,48)}_${d}`}function%20f(a){if(!c(a))return;const%20d=window[q]||(window[q]=[]),e=performance.now(),f=d.findLast(b=%3Eb.url===a);f%3Ff.t=e:d.push({url:a,t:e}),d.length%3Es%26%26d.splice(0,d.length-s),b(%22Track%20ready.%20Click%20DOWNLOAD.%22,%22%231e7e34%22)}function%20g(){const%20a=window[q]||[];if(a.length)return%20a.reduce((a,b)=%3Eb.t%3Ea.t%3Fb:a).url;try{const%20a=performance.getEntriesByType(%22resource%22);for(let%20b=a.length-1;0%3C=b;b--)if(c(a[b]%3F.name))return%20a[b].name}catch(a){}return%22%22}function%20h(){return%20window.__aceLameReady%3FPromise.resolve():new%20Promise((a,b)=%3E{if(window.lamejs)return%20window.__aceLameReady=!0,void%20a();const%20c=document.createElement(%22script%22);c.src=t,c.onload=()=%3E{window.__aceLameReady=!0,a()},c.onerror=()=%3Eb(new%20Error(%22Failed%20to%20load%20lamejs%20from%20cdnjs%22)),document.head.appendChild(c)})}async%20function%20i(b){var%20c=Math.min;await%20h();const%20d=new(window.AudioContext||window.webkitAudioContext),e=await%20d.decodeAudioData(b);await%20d.close();const%20f=e.numberOfChannels,g=e.sampleRate,k=e.getChannelData(0),l=1%3Cf%3Fe.getChannelData(1):k,m=1152,n=new%20lamejs.Mp3Encoder(2,g,128),o=[],p=b=%3E0|a(-32768,c(32767,0%3Eb%3F32768*b:32767*b));for(let%20a=0;a%3Ck.length;a+=m){const%20b=c(a+m,k.length),d=b-a,e=new%20Int16Array(d),f=new%20Int16Array(d);for(let%20b=0;b%3Cd;b++)e[b]=p(k[a+b]),f[b]=p(l[a+b]);const%20g=n.encodeBuffer(e,f);g.length%26%26o.push(new%20Uint8Array(g))}const%20q=n.flush();return%20q.length%26%26o.push(new%20Uint8Array(q)),new%20Blob(o,{type:%22audio/mpeg%22})}function%20j(b,c){const%20d=URL.createObjectURL(b),e=Object.assign(document.createElement(%22a%22),{href:d,download:c});e.style.display=%22none%22,document.body.appendChild(e),e.click(),e.remove(),setTimeout(()=%3EURL.revokeObjectURL(d),5e3)}async%20function%20k(a,b){const%20c=await%20fetch(a);if(!c.ok)throw%20new%20Error(`HTTP%20${c.status}`);j(await%20c.blob(),b)}async%20function%20l(a,c){b(%22Fetching%20audio\u2026%22,%22%230b5ed7%22);const%20d=await%20fetch(a);if(!d.ok)throw%20new%20Error(`HTTP%20${d.status}`);const%20e=await%20d.arrayBuffer();b(%22Encoding%20MP3\u2026%22,%22%230b5ed7%22);const%20f=await%20i(e);j(f,`${c}.mp3`)}async%20function%20m(a){try{return%20void(await%20navigator.clipboard.writeText(a))}catch(a){}const%20b=Object.assign(document.createElement(%22textarea%22),{value:a});b.style.cssText=%22position:fixed;left:-9999px%22,document.body.appendChild(b),b.select(),document.execCommand(%22copy%22),b.remove()}function%20n(a,b){return`curl.exe%20-L%20-H%20%22Referer:%20${location.origin}/%22%20-H%20%22User-Agent:%20Mozilla/5.0%22`+`%20-o%20%22%25USERPROFILE%25\\Downloads\\${b}%22%20%22${a}%22`}function%20o(){for(const%20a%20of%20document.querySelectorAll(%22use%22)){const%20b=(a.getAttribute(%22href%22)||a.getAttribute(%22xlink:href%22)||%22%22).trim();if(%22%23icon-play%22===b||%22%23icon-pause%22===b){const%20b=a.closest(%22button%22);if(b)return%20b}}return%20null}function%20p(){if(document.getElementById(r))return;const%20a=o();if(!a)return;const%20c=Object.assign(document.createElement(%22button%22),{id:r,type:%22button%22,textContent:%22\u2B07%20DL%22});c.style.cssText=%22margin-left:8px;padding:6px%2012px;border:0;border-radius:999px;cursor:pointer;background:%231890ff;color:%23fff;font:600%2012px/1%20system-ui;box-shadow:0%202px%204px%20rgba(0,0,0,.2)%22,c.addEventListener(%22click%22,async%20a=%3E{a.preventDefault(),a.stopPropagation(),c.disabled=!0,c.textContent=%22\u23F3%22;const%20f=()=%3EsetTimeout(()=%3E{c.textContent=%22\u2B07%20DL%22,c.disabled=!1},1500),h=g();if(!h)return%20c.textContent=%22\u274C%22,b(%22Press%20PLAY%20on%20the%20track%20first,%20then%20click%20DOWNLOAD.%22,%22%23b00020%22),void%20f();const%20i=e(h),j=d(h);try{%22mp3%22===j%3F(await%20k(h,`${i}.mp3`),b(%22Downloading%20MP3\u2026%22,%22%231e7e34%22)):(await%20l(h,i),b(%22Saved%20as%20MP3.%22,%22%231e7e34%22)),c.textContent=%22\u2705%22}catch(a){console.warn(%22[ace-dl]%22,a),await%20m(n(h,`${i}.${j}`)),b(%22Download%20blocked%20\u2014%20curl%20command%20copied%20to%20clipboard.%22,%22%23ff8c00%22),c.textContent=%22\uD83D\uDCCB%22}finally{f()}}),a.insertAdjacentElement(%22afterend%22,c)}const%20q=%22__aceCapturedUrlsV6%22,r=%22ace-dl-btn%22,s=200,t=%22https://cdnjs.cloudflare.com/ajax/libs/lamejs/1.2.1/lame.min.js%22;if(!window.__aceHooked){window.__aceHooked=!0;const%20a=window.fetch;window.fetch=function(b){try{f(%22string%22==typeof%20b%3Fb:b%3F.url)}catch(a){}return%20a.apply(this,arguments)};const%20b=window.XMLHttpRequest;window.XMLHttpRequest=function(){const%20a=new%20b,c=a.open.bind(a);return%20a.open=function(a,b,...d){try{f(b)}catch(a){}return%20c(a,b,...d)},a},window.XMLHttpRequest.prototype=b.prototype}if(p(),!window.__aceObserver){let%20a;window.__aceObserver=new%20MutationObserver(()=%3E{clearTimeout(a),a=setTimeout(p,120)}),window.__aceObserver.observe(document.body,{childList:!0,subtree:!0})}}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment