前言:好久没冒泡了,这个是裴之之前出的教程一分钟快速了解自己获得;未拥有的勋章;绝版勋章位置的升级版。旧教程其实不错的,为了迁就新人,所以升级了教程,改用脚本来复制自己的勋章。感谢朋友Leon_H的帮助,把脚本写出来以及调试。 步骤: 1.点复制代码2.篡改猴脚本里面,点加号新建脚本,然后ctrl c,ctrl v,ctrl s,就可以把复制的代码保存为脚本了。3.脚本保存成功,帖子页面就会显示导出勋章的复制按钮。
效果图以及复制后的效果如图:
备注:复制后如不喜欢顿号把文字连一起的排版,可以顿号替换\n。txtformat正则表达式打钩,就可以分行。这小事,问题不大。
- // ==UserScript==
- // [url=/u.php?uid=23627]@name[/url] 派派ZxID导出勋章按钮(点击复制信息)
- // [url=/u.php?uid=23627]@name[/url] space http://tampermonkey.net/
- // [url=/u.php?uid=159887]@version[/url] 2026-08-27 20:29:50
- // @description 列表页+个人主页通用,支持在线/离线图标,点击复制用户名、勋章列表
- // @author Leon_H
- // [url=/u.php?uid=561561]@match[/url] https://www.paipai.fm/*
- // [url=/u.php?uid=34399]@grant[/url] none
- // @run-at document-end
- // ==/UserScript==
- (function () {
- 'use strict';
- // 向上查找包含指定选择器的最近祖先元素内的目标
- function findClosestElement(element, selector) {
- let current = element.parentElement;
- while (current && current !== document.body) {
- const target = current.querySelector(selector);
- if (target) return target;
- current = current.parentElement;
- }
- return null;
- }
- // ========== 列表页功能(原有逻辑完全保留) ==========
- function addExportButton(zxidP) {
- // 防止重复添加
- if (zxidP.previousElementSibling?.classList.contains('zxid-export-btn')) return;
- // 创建导出按钮
- const exportBtn = document.createElement('button');
- exportBtn.textContent = '导出勋章';
- exportBtn.className = 'zxid-export-btn';
- // 按钮样式,放在a与p之间,垂直对齐
- exportBtn.style.display = 'inline-block';
- exportBtn.style.marginRight = '8px';
- exportBtn.style.verticalAlign = 'middle';
- exportBtn.style.padding = '2px 8px';
- exportBtn.style.fontSize = '12px';
- exportBtn.style.border = '1px solid #ccc';
- exportBtn.style.borderRadius = '3px';
- exportBtn.style.background = '#ffffff';
- exportBtn.style.cursor = 'pointer';
- // 点击复制功能
- exportBtn.addEventListener('click', function (e) {
- e.preventDefault(); // 阻止默认行为,彻底避免页面刷新
- // 定位当前条目对应的三个元素
- const userLink = exportBtn.previousElementSibling; // 前面的用户名a标签
- const zxidParagraph = exportBtn.nextElementSibling; // 后面的ZxID的p标签
- const medalsDiv = findClosestElement(zxidParagraph, '.medals-list'); // 对应用户的勋章容器
- // ① 提取用户名(a标签内的文本)
- const username = userLink?.textContent?.trim() || '未知用户名';
- // ② 提取ZxID数字
- const zxid = zxidParagraph?.textContent?.replace('ZxID:', '').trim() || '未知ID';
- // ③ 提取所有勋章的title
- const medalTitles = [];
- if (medalsDiv) {
- const medalImgs = medalsDiv.querySelectorAll('img[title]');
- medalImgs.forEach(img => {
- const title = img.title.trim();
- if (title) medalTitles.push(title);
- });
- }
- const medalText = medalTitles.length ? medalTitles.join('、') : '无勋章';
- // 拼接最终复制内容
- const copyContent = `用户名:${username}\nZxID:${zxid}\n勋章:${medalText}`;
- // 写入剪贴板 + 点击反馈
- navigator.clipboard.writeText(copyContent).then(() => {
- const original = exportBtn.textContent;
- exportBtn.textContent = '已复制';
- setTimeout(() => exportBtn.textContent = original, 1200);
- }).catch(() => {
- exportBtn.textContent = '复制失败';
- setTimeout(() => exportBtn.textContent = '导出', 1200);
- });
- });
- // 插入到a标签和p标签之间(zxidP的前方)
- zxidP.parentNode.insertBefore(exportBtn, zxidP);
- }
- function initAllZxid() {
- document.querySelectorAll('p').forEach(p => {
- if (p.textContent.includes('ZxID:')) {
- addExportButton(p);
- }
- });
- }
- // ========== 个人主页功能(已移除头衔) ==========
- function addProfileExportButton() {
- // 防止重复添加
- if (document.querySelector('.profile-export-btn')) return;
- // 定位页面元素
- const userNameStrong = document.querySelector('strong.f14.b');
- // 同时匹配在线图标online.png、离线图标stealth.png
- const statusImg = document.querySelector('img[src="//www.paipai.fm/p_w_picpath/stealth.png"],img[src="//www.paipai.fm/p_w_picpath/online.png"]');
- if (!userNameStrong || !statusImg) return;
- // 创建导出按钮,复用原有样式类
- const exportBtn = document.createElement('button');
- exportBtn.textContent = '导出勋章';
- exportBtn.className = 'profile-export-btn zxid-export-btn';
- // 按钮样式与列表页保持统一
- exportBtn.style.display = 'inline-block';
- exportBtn.style.marginLeft = '8px';
- exportBtn.style.marginRight = '8px';
- exportBtn.style.verticalAlign = 'middle';
- exportBtn.style.padding = '2px 8px';
- exportBtn.style.fontSize = '12px';
- exportBtn.style.border = '1px solid #ccc';
- exportBtn.style.borderRadius = '3px';
- exportBtn.style.background = '#ffffff';
- exportBtn.style.cursor = 'pointer';
- // 点击复制功能
- exportBtn.addEventListener('click', function (e) {
- e.preventDefault();
- // ① 提取用户名(strong.f14.b 内的文本)
- const username = userNameStrong.textContent.trim() || '未知用户名';
- // ② 提取所有勋章的 title
- const medalImgs = document.querySelectorAll('img[src*="/hack/medal/image/"]');
- const medalTitles = [];
- medalImgs.forEach(img => {
- const title = img.title.trim();
- if (title) medalTitles.push(title);
- });
- const medalText = medalTitles.length ? medalTitles.join('、') : '无勋章';
- // 拼接最终复制内容(已移除头衔)
- const copyContent = `用户名:${username}\n勋章:${medalText}`;
- // 写入剪贴板 + 点击反馈
- navigator.clipboard.writeText(copyContent).then(() => {
- const original = exportBtn.textContent;
- exportBtn.textContent = '已复制';
- setTimeout(() => exportBtn.textContent = original, 1200);
- }).catch(() => {
- exportBtn.textContent = '复制失败';
- setTimeout(() => exportBtn.textContent = '导出', 1200);
- });
- });
- // 插入到 strong 与在线/离线图标之间
- statusImg.parentNode.insertBefore(exportBtn, statusImg);
- }
- // ========== 页面初始化 ==========
- function initPage() {
- initAllZxid(); // 列表页逻辑
- addProfileExportButton(); // 个人主页逻辑
- }
- if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', initPage);
- } else {
- initPage();
- }
- // 监听动态加载的内容,滚动/翻页新增的ZxID也会自动加按钮
- const observer = new MutationObserver(mutations => {
- mutations.forEach(mutation => {
- mutation.addedNodes.forEach(node => {
- if (node.nodeType !== Node.ELEMENT_NODE) return;
- // 列表页动态内容处理
- if (node.tagName === 'P' && node.textContent.includes('ZxID:')) {
- addExportButton(node);
- }
- node.querySelectorAll?.('p').forEach(p => {
- if (p.textContent.includes('ZxID:')) {
- addExportButton(p);
- }
- });
- // 个人主页动态加载时重试
- addProfileExportButton();
- });
- });
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- })();