Created
August 3, 2026 13:36
-
-
Save hoangong/3e890614dd671e1ff5e27dcfd42c4c8b to your computer and use it in GitHub Desktop.
HypurrScan Auto Wallet in Market URL
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
| // ==UserScript== | |
| // @name HypurrScan Auto Wallet in Market URL | |
| // @namespace hypurrscan-wallet-url | |
| // @version 3.0 | |
| // @description Remembers the address from /address/0x... pages and appends it to /market/TICKER pages | |
| // @match https://hypurrscan.io/* | |
| // @grant GM_setValue | |
| // @grant GM_getValue | |
| // @run-at document-idle | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| const DEBUG = true; // set to false once it's working | |
| const log = (...args) => DEBUG && console.log('[hypurrscan-wallet]', ...args); | |
| const ADDR_KEY = 'hypurrscan_last_address'; | |
| const ADDR_REGEX = /^0x[a-fA-F0-9]{40}$/; | |
| function extractAddressFromPath(pathname) { | |
| const parts = pathname.split('/').filter(Boolean); | |
| if (parts.length >= 2 && parts[0] === 'address' && ADDR_REGEX.test(parts[1])) { | |
| return parts[1]; | |
| } | |
| return null; | |
| } | |
| function isBareMarketPath(pathname) { | |
| const parts = pathname.split('/').filter(Boolean); | |
| return parts.length === 2 && parts[0] === 'market' ? parts[1] : null; | |
| } | |
| async function handleUrlChange() { | |
| const pathname = window.location.pathname; | |
| log('checking path:', pathname); | |
| const addr = extractAddressFromPath(pathname); | |
| if (addr) { | |
| await GM_setValue(ADDR_KEY, addr); | |
| log('stored address:', addr); | |
| return; | |
| } | |
| const token = isBareMarketPath(pathname); | |
| if (token) { | |
| const savedAddr = await GM_getValue(ADDR_KEY, null); | |
| log('bare market path for', token, '- saved address is', savedAddr); | |
| if (savedAddr) { | |
| const newUrl = `${window.location.origin}/market/${token}/${savedAddr}${window.location.hash || ''}`; | |
| log('redirecting to', newUrl); | |
| window.location.replace(newUrl); | |
| } else { | |
| log('no saved address yet — visit an /address/0x... page first'); | |
| } | |
| } | |
| } | |
| // Run once immediately | |
| handleUrlChange(); | |
| // Method 1: patch history API (works for most SPA routers) | |
| function patch(fn) { | |
| return function (...args) { | |
| const result = fn.apply(this, args); | |
| window.dispatchEvent(new Event('hypurrscan-locationchange')); | |
| return result; | |
| }; | |
| } | |
| history.pushState = patch(history.pushState); | |
| history.replaceState = patch(history.replaceState); | |
| window.addEventListener('popstate', handleUrlChange); | |
| window.addEventListener('hypurrscan-locationchange', handleUrlChange); | |
| // Method 2: polling fallback (catches routers our patch might miss) | |
| let lastPath = window.location.pathname; | |
| setInterval(() => { | |
| if (window.location.pathname !== lastPath) { | |
| lastPath = window.location.pathname; | |
| log('poll detected path change ->', lastPath); | |
| handleUrlChange(); | |
| } | |
| }, 400); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment