我正在尝试编写一个用户脚本,该脚本应为Steam中的每个徽章添加到steamcardexchange(https://www.steamcardexchange.net/index.php)的链接:https://steamcommunity.com/id/ * / badges /
过去曾用Steam来做增强功能,但我不是很熟练,需要帮助我弄清楚为什么我的链接不可点击...每当我将鼠标悬停在列表中的徽章上时,它总是打开单个徽章页面,例如https://steamcommunity.com/id/ * / gamecards / 440 /并完全忽略带有链接的div。
这是我的代码:
// ==UserScript==
// @name SCE Badge Links
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add SteamCardExchange Links to Badges Page
// @author roughnecks
// @match https://steamcommunity.com/id/*/badges
// @match https://steamcommunity.com/id/*/badges/
// @grant none
// ==/UserScript==
const badgerows = document.querySelectorAll('.badge_row.is_link');
badgerows.forEach(badge => {
var splitted = badge.querySelector('a').href.split('/');
var id = splitted[6];
//console.log(id);
// The element to be prepended
var sce = document.createElement('DIV');
var a = document.createElement('a');
var linkText = document.createTextNode("SCE Badge");
a.appendChild(linkText);
a.href = "https://www.steamcardexchange.net/index.php?inventorygame-appid-" + id;
sce.appendChild(a);
badge.prepend(sce);
});
将我的代码更改为:
// ==UserScript==
// @name SCE Badge Links
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add SteamCardExchange Links to Badges Page
// @author roughnecks
// @match https://steamcommunity.com/id/*/badges
// @match https://steamcommunity.com/id/*/badges/
// @grant none
// ==/UserScript==
const badgerows = document.querySelectorAll('.badge_row.is_link');
badgerows.forEach(badge => {
var splitted = badge.querySelector('a').href.split('/');
var id = splitted[6];
//console.log(id);
var element = badge.querySelector('.whiteLink.how_to_get_card_drops');
// The element to be appended/prepended
var sce = document.createElement('div');
var a = document.createElement('a');
var linkText = document.createTextNode("SCE Badge");
a.appendChild(linkText);
a.target = '_blank';
a.href = "https://www.steamcardexchange.net/index.php?inventorygame-appid-" + id;
sce.appendChild(a);
element.append(sce);
});
即使有点难看,它看起来也能正常工作。 我仍然愿意提出建议和改进。谢谢