V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2EX  ›  Oah1zO  ›  全部回复第 4 页 / 共 7 页
回复总数  135
1  2  3  4  5  6  7  
唔,增加了几个节点和夜间模式的支持..
```
// ==UserScript==
// @name V2EX Solana Balance Checker 0.7
// @namespace http://tampermonkey.net/
// @version 0.7
// @description Uses JavaScript to read and apply V2EX's native theme colors for perfect integration. Includes auto RPC-node failover.
// @author Gemini
// @match https://www.v2ex.com/member/*
// @match https://v2ex.com/member/*
// @match https://*.v2ex.com/member/*
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @connect api.mainnet-beta.solana.com
// @connect rpc.ankr.com
// @connect solana-mainnet.rpc.extrnode.com
// ==/UserScript==

(function() {
'use strict';

// 1. Configuration
const v2exTokenMintAddress = '9raUVuzeWUk53co63M4WXLWPWE4Xc6Lpn7RS9dnkpump';
const RPC_ENDPOINTS = [ 'https://rpc.ankr.com/solana', 'https://api.mainnet-beta.solana.com', 'https://solana-mainnet.rpc.extrnode.com' ];

function findAddressOnPage() {
const scripts = document.querySelectorAll('script');
for (const script of scripts) {
if (script.textContent.includes('const address =')) {
const match = script.textContent.match(/const address = "([1-9A-HJ-NP-Za-km-z]{32,44})";/);
if (match && match[1]) { return match[1]; }
}
}
return null;
}

const userSolanaAddress = findAddressOnPage();
if (!userSolanaAddress) { return; }

// 2. Add base styles for LAYOUT ONLY.
GM_addStyle(`
.solana-balance-box { background-color: var(--box-background-color); border-bottom: 1px solid var(--box-border-color); margin-bottom: 20px; }
.solana-balance-table { width: 100%; border-collapse: collapse; table-layout: fixed; margin-bottom: -1px; }
.solana-balance-table th, .solana-balance-table td { padding: 12px; text-align: left; border-top: 1px solid var(--box-border-color); font-size: 14px; line-height: 1.6; }
.solana-balance-table th { background-color: var(--box-header-background-color); font-weight: bold; }
.solana-balance-table td { font-family: var(--mono-font); word-wrap: break-word; }
.solana-balance-table th:nth-child(1) { width: 60%; } .solana-balance-table th:nth-child(2) { width: 20%; } .solana-balance-table th:nth-child(3) { width: 20%; }
`);

// 3. Create and insert DOM elements
const container = document.createElement('div');
container.className = 'solana-balance-box';
const table = document.createElement('table');
table.className = 'solana-balance-table';
const headerRow = table.insertRow();
headerRow.innerHTML = '<th>Address</th><th>SOL</th><th>$V2EX</th>';
const dataRow = table.insertRow();
const addressCell = dataRow.insertCell();
const solBalanceCell = dataRow.insertCell();
const tokenBalanceCell = dataRow.insertCell();
addressCell.textContent = userSolanaAddress;
solBalanceCell.textContent = 'Loading...';
tokenBalanceCell.textContent = 'Loading...';
container.appendChild(table);
const mainInfoBox = document.querySelector('#Main .box');
if (mainInfoBox) {
mainInfoBox.parentNode.insertBefore(container, mainInfoBox.nextSibling);
}

// 4. JavaScript function to READ and APPLY native text colors for BOTH headers and data
function updateTextColorsForTheme() {
// Read the actual color values V2EX is currently using
const nativeHeaderTextColor = getComputedStyle(document.body).getPropertyValue('--box-header-text-color').trim();
const nativeTextColor = getComputedStyle(document.body).getPropertyValue('--box-foreground-color').trim();
const nativeFadeColor = getComputedStyle(document.body).getPropertyValue('--color-fade').trim();

// --- FIX: Apply color to table headers (th) ---
const headers = table.querySelectorAll('th');
for (const header of headers) {
// By changing this to nativeTextColor, the header color will match the data cell color.
header.style.setProperty('color', nativeTextColor, 'important');
}

// --- Apply color to table data (td) ---
const cells = [addressCell, solBalanceCell, tokenBalanceCell];
for (const cell of cells) {
if (cell.textContent === 'Loading...' || cell.textContent === 'Error') {
cell.style.setProperty('color', nativeFadeColor, 'important');
} else {
cell.style.setProperty('color', nativeTextColor, 'important');
}
}
}

// 5. Observer to detect theme changes in real-time
const themeObserver = new MutationObserver(() => updateTextColorsForTheme());
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
updateTextColorsForTheme();

// 6. Fetch data
function makeRpcRequest(requestPayload, onSuccess, onFailure) {
let endpointIndex = 0;
function tryNextEndpoint() {
if (endpointIndex >= RPC_ENDPOINTS.length) { if (onFailure) onFailure(); return; }
const currentEndpoint = RPC_ENDPOINTS[endpointIndex++];
GM_xmlhttpRequest({
method: 'POST', url: currentEndpoint, headers: { 'Content-Type': 'application/json' },
data: JSON.stringify(requestPayload), timeout: 8000,
onload: function(response) {
try { const data = JSON.parse(response.responseText); if (data.error) { tryNextEndpoint(); } else { onSuccess(data); } }
catch (e) { tryNextEndpoint(); }
},
onerror: tryNextEndpoint, ontimeout: tryNextEndpoint
});
}
tryNextEndpoint();
}

function getSolBalance() {
makeRpcRequest({ jsonrpc: '2.0', id: 1, method: 'getBalance', params: [userSolanaAddress] },
(data) => { solBalanceCell.textContent = `${(data.result.value / 1e9).toFixed(6)}`; updateTextColorsForTheme(); },
() => { solBalanceCell.textContent = 'Error'; updateTextColorsForTheme(); }
);
}
function getTokenBalance() {
makeRpcRequest({ jsonrpc: '2.0', id: 1, method: 'getTokenAccountsByOwner', params: [userSolanaAddress, { mint: v2exTokenMintAddress }, { encoding: 'jsonParsed' }] },
(data) => { tokenBalanceCell.textContent = data.result.value.length > 0 ? data.result.value[0].account.data.parsed.info.tokenAmount.uiAmountString : '0'; updateTextColorsForTheme(); },
() => { tokenBalanceCell.textContent = 'Error'; updateTextColorsForTheme(); }
);
}

getSolBalance();
getTokenBalance();

})();
```
2025 年 7 月 31 日
回复了 iFrey 创建的主题 分享创造 Vibe coding 了一个 V2EX.meme $V2EX 价格实时查询
https://www.geckoterminal.com/solana/pools/CtxHhwboVTtRf1kC4Zwfz8Zf8bNW78N2uuR3oZX5VFKb

如果你们玩币..就会知道..这种工具类型的网站有非常非常多了....
2025 年 7 月 29 日
回复了 Pantheonn 创建的主题 游戏 三天狂肝 160h ,这游戏比文明 6 还上瘾
科雷的游戏都很硬核...基本都是百小时入门的...
2025 年 7 月 25 日
回复了 jchencode 创建的主题 游戏 对明末感到失望
笑出声,怎么看待《明末:渊虚之羽》收回了标准版 key 中误发的豪华版武器,主角衣服也一并消失?

真是灾难级运营的典型 case.
2025 年 7 月 25 日
回复了 carson8899 创建的主题 Solana 我想给兄弟们空投一把!
不是..怎么楼这么高了,啥情况
2025 年 7 月 22 日
回复了 Livid 创建的主题 站点状态 20250721 - Solana 原生代币 SOL 打赏
https://v2ex.com/t/1146912

看到这个帖子临时写了这个..哈哈哈,求打赏♪٩(´ω`)و♪
害,坛友搁这冷嘲热讽,说不定他私信已经爆了。
不要小看下行市场,看不上的都是被 op 漏斗筛掉的人。😂
2025 年 7 月 17 日
回复了 kk1945615 创建的主题 生活 夫妻矛盾
@JIlIlIlIl 老哥感觉说到点子上了..我通篇看下来的感觉是真的 op 就是一个典型的学生思维..这种人沟通起来真的令人窒息..“我觉得我没错”“你说我错在哪”“我没有工作没有钱”“过来了总有办法的”“她说很有成就感”“我觉得工作不值”..他是真的不知道问题在哪..说实话,我不知道她媳妇为啥不同意离婚..OP 这种老公给人感觉像多养了一个儿子一样...
2025 年 7 月 16 日
回复了 Livid 创建的主题 Solana 在 Safari 里使用 Glow Wallet 登录 V2EX 的体验
@xujiahui chrome 我用的这个,功能类似,谷歌商店有 2200+评论..应该是安全的..
https://chromewebstore.google.com/detail/%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E5%99%A8/bhghoamapcdpbohphigoooaddinpkbai?hl=zh-cn
1  2  3  4  5  6  7  
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   975 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 27ms · UTC 19:30 · PVG 03:30 · LAX 12:30 · JFK 15:30
♥ Do have faith in what you're doing.