|
本帖最后由 风岚 于 2025-2-12 21:20 编辑
基于 @星之子 的脚本进行了优化和美化
原帖指路:【油猴脚本】勋章商城展示内部编号、价格、库存余量[/url]
界面美化: - // ==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;
- }
- .myimg p:nth-of-type(1) {
- height: 23px !important;
- }
- .gold {
- color: #c7a800;
- }
- .blood {
- color: #ff4343;
- }
- .spells {
- color: #4b0082;
- }
- .info {
- position: absolute;
- left: 2px;
- bottom: -1px;
- }
- .infoR{
- position: absolute;
- right: 2px;
- bottom: -1px;
- }
- `;
- document.head.appendChild(style);
- // 处理每个勋章块
- document.querySelectorAll('.myblok').forEach(blok => {
- blok.style.height = '150px';
- 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('购买价格')
- );
- console.log(priceElement?.querySelector('b')?.textContent);
- const [currency, price] = priceElement?.querySelector('b')?.textContent.split(/\s+/);
- // 提取库存
- 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 = `<span class="info">ID:${tipId}</span><span class="infoR">库存:${stock}</span>`;
- // 定位插入位置
- const myimg = blok.querySelector('.myimg');
- const targetP = myimg.querySelector('p:nth-of-type(2)');
- const priceDiv = document.createElement('span');
- priceDiv.classList.add({ 金币: 'gold', 血液: 'blood', 咒术: 'spells' }[currency]);
- priceDiv.textContent = `${price} ${currency}`;
- myimg.querySelector('p').insertAdjacentElement('afterend', priceDiv);
- if (targetP) {
- targetP.insertAdjacentElement('afterend', infoDiv);
- } else {
- myimg.appendChild(infoDiv);
- }
- });
- })();
复制代码 如果喜欢请去原贴点个追随吧
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
查看全部评分
|