Last active
April 11, 2025 08:57
-
-
Save luchenqun/b3ea96cf5d07c36d1b7cbe6dd01b166f to your computer and use it in GitHub Desktop.
realm
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
| console.log("Realm=====================>"); | |
| window.__envs = { | |
| NEXT_PUBLIC_APP_PROTOCOL: "https", | |
| NEXT_PUBLIC_VISUALIZE_API_HOST: "https://visualize.mud.network", | |
| NEXT_PUBLIC_NETWORK_CURRENCY_DECIMALS: "18", | |
| NEXT_PUBLIC_STATS_API_HOST: "https://stats.mud.network", | |
| NEXT_PUBLIC_GIT_COMMIT_SHA: "7d7873d8", | |
| NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL: "wss", | |
| NEXT_PUBLIC_NETWORK_CURRENCY_NAME: "MUD", | |
| NEXT_PUBLIC_NETWORK_CURRENCY_SYMBOL: "MUD", | |
| NEXT_PUBLIC_HOMEPAGE_CHARTS: "['daily_txs']", | |
| NEXT_PUBLIC_API_HOST: "scan.mud.network", | |
| NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID: "3424ec81704e6eedca5cf63669aac2d4", | |
| NEXT_PUBLIC_APP_HOST: "scan.mud.network", | |
| NEXT_PUBLIC_API_BASE_PATH: "/", | |
| NEXT_PUBLIC_API_SPEC_URL: "https://raw.githubusercontent.com/blockscout/blockscout-api-v2-swagger/main/swagger.yaml", | |
| NEXT_PUBLIC_GIT_TAG: "v1.38.1", | |
| NEXT_PUBLIC_ICON_SPRITE_HASH: "33c5ff4f", | |
| NEXT_PUBLIC_NETWORK_ID: "168169", | |
| NEXT_PUBLIC_API_PROTOCOL: "https", | |
| NEXT_PUBLIC_NETWORK_NAME: "MUD Chain", | |
| NEXT_PUBLIC_NETWORK_RPC_URL: "https://rpc.mud.network", | |
| NEXT_PUBLIC_IS_TESTNET: "false", | |
| NEXT_PUBLIC_NETWORK_SHORT_NAME: "MUD Chain", | |
| } | |
| function replaceMetaMaskInShadow(root) { | |
| // 1. 搜索当前层级的按钮 | |
| root.querySelectorAll('button').forEach((button) => { | |
| try { | |
| // 2. 在按钮内查找目标元素 | |
| const textElement = button.querySelector('wui-text'); | |
| const imageElement = button.querySelector('wui-wallet-image'); | |
| if (textElement?.textContent?.trim() === 'OneKey') { | |
| console.log('找到目标按钮:', button); | |
| // 3. 执行替换操作 | |
| textElement.textContent = 'MUD Realm'; | |
| if (imageElement) { | |
| imageElement.setAttribute('name', 'MUD Realm'); | |
| imageElement.setAttribute('imagesrc', 'https://swap.mud.network/static/media/ethereum-logo.9a8efa99.png'); | |
| } | |
| const tagElement = button.querySelector('wui-tag'); | |
| if (tagElement) { | |
| tagElement.textContent = 'connected'; | |
| tagElement.setAttribute('variant', 'active'); | |
| } | |
| } | |
| } catch (error) { | |
| console.error('处理按钮时出错:', error); | |
| } | |
| }); | |
| root.querySelectorAll('wui-text').forEach((text) => { | |
| if (text.textContent?.trim() === 'OneKey') { | |
| text.textContent = 'MUD Realm'; | |
| } | |
| if (text.textContent?.trim() === 'Continue in OneKey') { | |
| text.textContent = 'Continue in MUD Realm'; | |
| root.querySelectorAll('wui-wallet-image').forEach((imageElement) => { | |
| if (imageElement) { | |
| imageElement.setAttribute('name', 'MUD Realm'); | |
| imageElement.setAttribute('imagesrc', 'https://swap.mud.network/static/media/ethereum-logo.9a8efa99.png'); | |
| } | |
| }); | |
| } | |
| }); | |
| // 4. 递归穿透所有 Shadow DOM | |
| root.querySelectorAll('*').forEach((element) => { | |
| try { | |
| if (element.shadowRoot) { | |
| replaceMetaMaskInShadow(element.shadowRoot); | |
| } | |
| } catch (error) { | |
| console.error('访问 Shadow DOM 时出错:', element, error); | |
| } | |
| }); | |
| } | |
| // 5. 启动搜索的完整流程 | |
| function initReplacement() { | |
| // 先处理普通 DOM | |
| replaceMetaMaskInShadow(document); | |
| // 处理可能延迟加载的模态框 | |
| const observer = new MutationObserver((mutations) => { | |
| mutations.forEach(() => { | |
| if (document.querySelector('w3m-modal')) { | |
| replaceMetaMaskInShadow(document); | |
| } | |
| }); | |
| }); | |
| observer.observe(document.body, { | |
| childList: true, | |
| subtree: true | |
| }); | |
| } | |
| // 6. 安全启动(处理动态加载) | |
| if (document.readyState === 'loading') { | |
| document.addEventListener('DOMContentLoaded', initReplacement); | |
| } else { | |
| initReplacement(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment