Bricklink Links for Lego.com

Adds a link to Bricklink for each product on Lego.com

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Bricklink Links for Lego.com
// @license      MIT
// @version      0.1
// @description  Adds a link to Bricklink for each product on Lego.com
// @author       azuravian
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @match        https://www.lego.com/*
// @match        http://www.lego.com/*
// @grant        none
// @run-at       document-end
// @namespace https://greasyfork.org/users/1025348
// ==/UserScript==

document.body.addEventListener('DOMNodeInserted', function(event) {
	bricklink(event.target);
}, false);

function bricklink() {
    const itemSpan = document.querySelector('[data-test*="item-value"]');
    const itemValue = itemSpan.innerText;
    const bcWrapper = document.querySelector('ol[data-test*="breadcrumbs"]');
    const blUrl = "https://www.bricklink.com/v2/catalog/catalogitem.page?S=";
    const finalUrl = blUrl + itemValue;
    itemSpan.children[0].children[0].innerHTML = '<a href="' + finalUrl + '" target="_blank">' + itemValue + '</a>';
}