Skip to content

Instantly share code, notes, and snippets.

@ArjixWasTaken
Last active June 15, 2025 16:36
Show Gist options
  • Save ArjixWasTaken/8d8492be077003e8dd983c0a11714e69 to your computer and use it in GitHub Desktop.
Save ArjixWasTaken/8d8492be077003e8dd983c0a11714e69 to your computer and use it in GitHub Desktop.
A spotify userscript to retrieve username/accessToken by patching webpack.
// ==UserScript==
// @name webpack-patcher spotify
// @namespace http://tampermonkey.net/
// @version 2025-05-22
// @description Patches webpack modules
// @author Vendicated, Arjix
// @match https://open.spotify.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=spotify.com
// @grant none
// @run-at document-start
// ==/UserScript==
let done = false;
window._submit = () => {
if (done) return;
if (!window._user || !window._auth) return;
done = true;
console.log('Ayoo', { username: window._user, authorization: window._auth });
}
const patches = [
{
find: /this\.namespace=(\w+)/, replacement: [
{ match: /this\.namespace=(\w+)/, replace: (m, username) => `this.namespace=(()=>{ window._user = ${m}; _submit(); return window.username; })()` },
]
},
{
find: "this._shouldSendAuthorization", replacement: [
{ match: "this._shouldSendAuthorization&&", replace: "this._shouldSendAuthorization&&(()=>{ window._auth = this._accessToken; _submit(); return 1; })()&&" }
]
}
];
/// ======== Do not touch the below! ========
function patchPush(e){function t(n){try{patchFactories(n[1])}catch(e){console.error("Error in handlePush",e)}return t.$$vencordOriginal.call(e,n)}t.$$vencordOriginal=e.push,t.toString=t.$$vencordOriginal.toString.bind(t.$$vencordOriginal),t.bind=(...e)=>t.$$vencordOriginal.bind(...e),Object.defineProperty(e,"push",{configurable:!0,get:()=>t,set(e){t.$$vencordOriginal=e}})}function patchFactories(e){for(const t in e){let n=e[t];const r=n,i=e[t]=function(e,t,i){try{n(e,t,i)}catch(o){if(n===r)throw o;return console.error("Error in patched module",o),void r(e,t,i)}t=e.exports};i.toString=r.toString.bind(r),i.original=r;let o="0,"+n.toString();for(let e=0;e<patches.length;e++){const t=patches[e];if(!("string"==typeof t.find?o.includes(t.find):t.find.test(o)))continue;for(const e of t.replacement){const t=n,r=o;try{o=o.replace(e.match,e.replace),n=(0,eval)(o)}catch(e){console.error("patch failed",o),o=r,n=t}}patches.splice(e--,1)}}}Object.defineProperty(Function.prototype,"m",{set(e){const t=this.toString();t.includes("exports")&&(t.includes("false")||t.includes("!1"))?(Object.defineProperty(this,"m",{value:e,configurable:!0,enumerable:!0,writable:!0}),patchFactories(e),delete Function.prototype.m,this.m=e):Object.defineProperty(this,"m",{value:e,configurable:!0,writable:!0,enumerable:!0})},configurable:!0});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment