|
动机
勋章商城的价格、库存余量信息,需要在鼠标悬停后显示的.mytip框中才能看到,勋章的内部编号更是要审查元素。个人感觉不够一目了然,就顺手写了这个脚本。DeepSeek真的很强,花了5分钟写提示词、等了2分钟生成、花了5分钟调试,脚本就搞定了。
功能
如图所示吧,感觉没啥可解释的。
代码
@Name @Match
- // ==UserScript==
- // @name 勋章:商城编号价格库存量显示
- // @namespace http://tampermonkey.net/
- // @version 0.3
- // @description 从mytip提取信息并显示在指定位置
- // @author You
- // @match https://www.gamemale.com/plugin.php?id=wodexunzhang%3Ashowxunzhang&fid=*
- // @match https://www.gamemale.com/wodexunzhang-showxunzhang.html
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // 创建信息显示样式
- const style = document.createElement('style');
- style.textContent = `
- .badge-info {
- font-family: Noto Sans SC, Microsoft Yahei, Arial, sans-serif;
- color: #333;
- }
- `;
- document.head.appendChild(style);
- // 处理每个勋章块
- document.querySelectorAll('.myblok').forEach(blok => {
- blok.style.height = '140px';
- const mytip = blok.querySelector('.mytip');
- if (!mytip) return;
- // 提取编号
- const tipId = mytip.id.replace('my', '');
- // 提取价格
- const priceElement = Array.from(mytip.querySelectorAll('p.jiage')).find(p =>
- p.textContent.includes('购买价格')
- );
- const price = priceElement?.querySelector('b')?.textContent || '无价格';
- // 提取库存
- const stockElement = Array.from(mytip.querySelectorAll('p.jiage')).find(p =>
- p.textContent.includes('剩余库存')
- );
- const stock = stockElement?.querySelector('b')?.textContent || '无库存';
- // 创建信息显示元素
- const infoDiv = document.createElement('p');
- infoDiv.className = 'badge-info';
- infoDiv.innerHTML = `
- ${tipId} / ${price} / ${stock}
- `;
- // 定位插入位置
- const myimg = blok.querySelector('.myimg');
- const targetP = myimg.querySelector('p:nth-of-type(2)');
- if (targetP) {
- targetP.insertAdjacentElement('afterend', infoDiv);
- } else {
- myimg.appendChild(infoDiv);
- }
- });
- })();
复制代码
来自群组: 星象占卜 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
查看全部评分
|