// ==UserScript==
// @name 访问米游社七圣召唤卡牌广场的评论区时在页面底部打印评论发出用户的主页URL
// @namespace http://tampermonkey.net/
// @version 0.2.5
// @description 访问米游社七圣召唤卡牌广场的评论区时在页面底部打印评论发出用户的主页URL。自用。
// @author aspen138
// @match https://webstatic.mihoyo.com/ys/event/bbs-lineup-qskp/*
// @grant none
// @run-at document-start
// @icon https://www.miyoushe.com/favicon.ico
// @license GPL-3.0 License
// @downloadURL none
// ==/UserScript==
function myCopeWtih(item) {
var user_account_uid = item.user.account_uid;
var user_nickname = item.user.nickname;
var user_comment = item.content.text;
var user_comment_reply_id = item.reply_id;
// 创建一个新的 div 元素来显示信息
var infoDiv = document.createElement("div");
infoDiv.style.margin = "10px";
infoDiv.style.padding = "5px";
infoDiv.style.border = "1px solid #ddd";
infoDiv.style.backgroundColor = "#f9f9f9";
// 设置 div 的内容
infoDiv.innerHTML = "用户昵称: " + user_nickname + "
" +
"评论: " + user_comment + "
" +
"用户主页URL: " +
"" +
"https://webstatic.mihoyo.com/ys/event/bbs-lineup-qskp/index.html#/pc/author/" + user_account_uid + "";
// 找到评论区的容器元素,或者你可以创建一个新的容器元素
var commentsContainer = document.querySelector("#your-comments-container-selector");
if (commentsContainer) {
// 将 div 添加到评论区的容器中
commentsContainer.appendChild(infoDiv);
} else {
// 如果没有找到评论区容器,就直接添加到 body 中
document.body.appendChild(infoDiv);
}
// 查找所有 img 元素,并将其链接到相应的 user_account_uid 主页
var imgElements = document.querySelectorAll('img.hyl-comment-avatar__img');
imgElements.forEach(function(img) {
var imgSrc = img.getAttribute('src');
if ((imgSrc && imgSrc.includes(String(user_account_uid)))) {
//console.log("imgSrc does include user_account_uid.");
var userProfileUrl = "https://webstatic.mihoyo.com/ys/event/bbs-lineup-qskp/index.html#/pc/author/" + user_account_uid;
// Check if the image is inside an anchor tag
var parentElement = img.parentElement;
if (parentElement.tagName.toLowerCase() === 'a') {
// If the parent is an anchor, set its href and target
parentElement.href = userProfileUrl;
parentElement.target = "_blank"; // Open in a new tab
} else {
// If not, create an anchor and wrap the image inside it
var anchor = document.createElement('a');
anchor.href = userProfileUrl;
anchor.target = "_blank"; // Open in a new tab
// Insert the anchor before the img and then move the img inside it
parentElement.insertBefore(anchor, img);
anchor.appendChild(img);
}
}
});
}
(function() {
'use strict';
// 重写 XMLHttpRequest 的 open 方法
const originalXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
this.addEventListener('readystatechange', function() {
if (this.readyState === 4 && this.status === 200 &&
(url.includes('api-takumi.mihoyo.com/bouleuterion_v2/v1/account/reply/list') || url.includes('api-takumi.mihoyo.com/bouleuterion_v2/v1/account/reply/floor/list'))
) {
try {
// 解析响应的 JSON 数据
const responseJSON = JSON.parse(this.responseText);
console.log(responseJSON);
// 检查数据结构并提取 account_uid
if (responseJSON && responseJSON.data && responseJSON.data.list) {
console.log('提取的account_uid列表:');
console.log("responseJSON.data.list=",responseJSON.data.list);
// 遍历list数组
responseJSON.data.list.forEach(item => {
myCopeWtih(item);
item.sub_reply_list.forEach(subItem => {
myCopeWtih(subItem);
});
});
}
} catch (e) {
console.error('Error parsing JSON:', e);
}
}
}, false);
originalXHROpen.call(this, method, url, async, user, pass);
};
})();