回复
83
查看
1513
收藏
31

4

赠楼

1%

赠楼率

73

蒸汽

11

主题

241

帖子

741

积分
发表于 前天 22:26 · 云南 | 显示全部楼层 |阅读模式
本文为 其乐用户(UID:1757671) 发布的原创文章,转摘前请联系该用户获得许可
本帖最后由 1757671 于 2025-6-23 00:23 编辑





自动转换网页价格,另外右上角悬浮窗可以自定义查询汇率。
有需要的就自己改改汇率就好了。我用的是饿区汇率。
汇率有手动和自动。
如果要改的话可以把货币锁写改下,然后货币代号改下就行。
实在不会的就回帖我改吧。 主要是自动获取太容易错误了。
那个锁是悬浮窗移动位置的锁定和解锁。
输入框就是手动输入的

回复自取吧
第一次发帖,应该没搞错格式。


2025.6.23 0:23
抱歉各位,插入代码时候,被自动改了网址项
重新更新了代码 有问题留言。

  1. // ==UserScript==
  2. // @name         STEAM页面价格转换(周洋自用)
  3. // @namespace    http://tampermonkey.net/
  4. // @version      3.0
  5. // @description  Convert RUB prices to CNY on Steam pages
  6. // @author       You
  7. // // @match        *://store.steampowered.com/*
  8. // @match        *://help.steampowered.com/*
  9. // @match        https://checkout.steampowered.com/checkout/*

  10. // @grant        GM_getValue
  11. // @grant        GM_setValue
  12. // @grant        GM_xmlhttpRequest
  13. // @grant        GM_registerMenuCommand
  14. // ==/UserScript==

  15. (function() {
  16.     'use strict';

  17.     console.log("脚本已加载");

  18.     let currentRateDisplay = null;
  19.     const defaultRate = 10;

  20.     function createCurrentRateDisplay() {
  21.         currentRateDisplay = document.createElement('div');
  22.         currentRateDisplay.style.position = 'fixed';
  23.         currentRateDisplay.style.top = '10px';
  24.         currentRateDisplay.style.right = '10px';
  25.         currentRateDisplay.style.zIndex = '1000';
  26.         currentRateDisplay.style.color = 'white';
  27.         currentRateDisplay.style.fontSize = '12px';
  28.         currentRateDisplay.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
  29.         currentRateDisplay.style.padding = '5px';
  30.         currentRateDisplay.style.borderRadius = '5px';
  31.         document.body.appendChild(currentRateDisplay);
  32.         updateCurrentRateDisplay();
  33.     }

  34.     function getExchangeMode() {
  35.         return GM_getValue('exchangeMode', 'auto');
  36.     }

  37.     function setExchangeMode(mode) {
  38.         GM_setValue('exchangeMode', mode);
  39.     }

  40.     function getExchangeRate() {
  41.         return GM_getValue('exchangeRate', defaultRate);
  42.     }

  43.     function setExchangeRate(rate) {
  44.         GM_setValue('exchangeRate', rate);
  45.     }

  46.     async function fetchExchangeRate() {
  47.         return new Promise((resolve, reject) => {
  48.             GM_xmlhttpRequest({
  49.                 method: "GET",
  50.                 url: 'https://api.exchangerate-api.com/v4/latest/CNY',
  51.                 onload: function(response) {
  52.                     if (response.status === 200) {
  53.                         const data = JSON.parse(response.responseText);
  54.                         resolve(data.rates.RUB);
  55.                     } else {
  56.                         reject('无法获取汇率');
  57.                     }
  58.                 },
  59.                 onerror: function() {
  60.                     reject('请求错误');
  61.                 }
  62.             });
  63.         });
  64.     }

  65.     async function convertPrices() {
  66.         console.log("开始转换价格");
  67.         let exchangeRate;
  68.         const mode = getExchangeMode();

  69.         if (mode === 'auto') {
  70.             exchangeRate = await fetchExchangeRate();
  71.             setExchangeRate(exchangeRate);
  72.         } else {
  73.             exchangeRate = getExchangeRate();
  74.         }

  75.         // 获取页面中所有含有 "руб" 的元素
  76.         const priceElements = document.querySelectorAll('*:not(script):not(style)'); // 获取所有元素

  77.         priceElements.forEach(element => {
  78.             if (element.childNodes.length > 0) {
  79.                 element.childNodes.forEach(node => {
  80.                     if (node.nodeType === Node.TEXT_NODE && node.nodeValue.includes('руб')) {
  81.                         const rubPriceMatch = node.nodeValue.match(/(\d+([.,]\d+)?)\s*руб/);
  82.                         if (rubPriceMatch) {
  83.                             // 检查是否已经转换过
  84.                             const existingCnyElement = element.querySelector('.converted-price');
  85.                             if (!existingCnyElement) {
  86.                                 const rubPrice = parseFloat(rubPriceMatch[1].replace(',', '.'));
  87.                                 const cnyPrice = (rubPrice / exchangeRate).toFixed(2);

  88.                                 // 创建新的转换价格文本
  89.                                 const convertedText = ` (¥${cnyPrice})`;
  90.                                 const newNode = document.createTextNode(convertedText);

  91.                                 // 在原文本后插入新的价格
  92.                                 const span = document.createElement('span');
  93.                                 span.className = 'converted-price';
  94.                                 span.style.marginLeft = '5px';
  95.                                 span.style.fontSize = '12px';
  96.                                 span.style.color = 'red';
  97.                                 span.appendChild(newNode);
  98.                                 element.appendChild(span);
  99.                             }
  100.                         }
  101.                     }
  102.                 });
  103.             }
  104.         });
  105.     }

  106.     function updateCurrentRateDisplay() {
  107.         const exchangeRate = getExchangeRate();
  108.         const mode = getExchangeMode();
  109.         currentRateDisplay.textContent = `${exchangeRate} RUB (${mode === 'auto' ? '自动' : '手动'})`;
  110.     }

  111.     function toggleExchangeMode() {
  112.         const currentMode = getExchangeMode();
  113.         const newMode = currentMode === 'auto' ? 'manual' : 'auto';
  114.         setExchangeMode(newMode);
  115.         alert(`汇率模式已切换为: ${newMode === 'auto' ? '自动获取' : '手动设置'}`);
  116.         updateCurrentRateDisplay();
  117.         convertPrices();
  118.     }

  119.     function setManualExchangeRate() {
  120.         const userRate = prompt("请输入手动汇率 (1 CNY = ? RUB):", getExchangeRate());
  121.         if (userRate !== null) {
  122.             const rate = parseFloat(userRate);
  123.             if (!isNaN(rate) && rate > 0) {
  124.                 setExchangeRate(rate);
  125.                 alert(`手动汇率已设置为: ${rate} RUB`);
  126.                 updateCurrentRateDisplay();
  127.                 convertPrices();
  128.             } else {
  129.                 alert('请输入一个有效的数字汇率!');
  130.             }
  131.         }
  132.     }

  133.     GM_registerMenuCommand("切换汇率模式", toggleExchangeMode);
  134.     GM_registerMenuCommand("设置手动汇率", setManualExchangeRate);

  135.     function init() {
  136.         console.log("初始化脚本");
  137.         createCurrentRateDisplay();
  138.         const mode = getExchangeMode();
  139.         if (mode === 'auto') {
  140.             fetchExchangeRate().then(rate => {
  141.                 setExchangeRate(rate);
  142.                 updateCurrentRateDisplay();
  143.                 convertPrices();
  144.             }).catch(console.error);
  145.         } else {
  146.             updateCurrentRateDisplay();
  147.             convertPrices();
  148.         }
  149.     }

  150.     const observer = new MutationObserver(() => {
  151.         convertPrices();
  152.     });

  153.     observer.observe(document.body, {
  154.         childList: true,
  155.         subtree: true
  156.     });

  157.     window.addEventListener('load', init);
  158. })();

复制代码









本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

×
[发帖际遇]: 1757671 入侵其乐数据库给自己添加 65536 点体力,因为内存溢出只加了体力 1 点 幸运榜 / 衰神榜

本帖被以下淘专辑推荐:

回复

使用道具 举报

浏览本版块需要:
1. 初阶会员或更高等级;
2. (点击此处)绑定Steam账号
您需要登录后才可以回帖 登录 | 注册

本版积分规则

欢迎发帖参与讨论 o(*≧▽≦)ツ,请注意
1. 寻求帮助或答案的帖子请发到问题互助版块,悬赏有助于问题解决的速度。发错可能失去在该板块发布主题的权限(了解更多
2. 表达观点可以,也请务必注意语气和用词,以免影响他人浏览,特别是针对其他会员的内容。如觉得违规可使用举报功能 交由管理人员处理,请勿引用对方的内容。
3. 开箱晒物交易中心游戏互鉴福利放送版块请注意额外的置顶版规。
4. 除了提问帖和交易帖以外,不确认发在哪个版块的帖子可以先发在谈天说地

  作为民间站点,自 2004 年起为广大中文 Steam 用户提供技术支持与讨论空间。历经二十余载风雨,如今已发展为国内最大的正版玩家据点。

列表模式 · · 微博 · Bilibili频道 · Steam 群组 · 贴吧 · QQ群 
Keylol 其乐 ©2004-2025 Chinese Steam User Fan Site.
Designed by Lee in Balestier, Powered by Discuz!
推荐使用 ChromeMicrosoft Edge 来浏览本站
广告投放|手机版|广州数趣信息科技有限公司 版权所有|其乐 Keylol ( 粤ICP备17068105号 )
GMT+8, 2025-6-24 09:00
快速回复 返回顶部 返回列表