Warframe Wiki Enhanced Market Navigator

Adds Market buttons to Warframe Wiki pages: below the title and next to mod links.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Warframe Wiki Enhanced Market Navigator
// @namespace    http://tampermonkey.net/
// @version      1.9
// @description  Adds Market buttons to Warframe Wiki pages: below the title and next to mod links.
// @author       PixDie
// @match        https://warframe.fandom.com/wiki/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to create a common Market button
    function createMarketButton(targetUrl) {
        const button = document.createElement('button');
        button.textContent = 'Market';
        button.style.padding = '2px 5px';
        button.style.fontSize = '12px';
        button.style.backgroundColor = '#0078d7';
        button.style.color = 'white';
        button.style.border = 'none';
        button.style.borderRadius = '3px';
        button.style.cursor = 'pointer';

        button.addEventListener('click', (event) => {
             event.preventDefault();
            window.open(targetUrl, '_blank');
        });

        return button;
    }


     // Function to add a button below the specified element
     function addMarketButtonBelow(targetElement, targetUrl) {
         const buttonContainer = document.createElement('div');
         buttonContainer.style.display = 'flex';
         buttonContainer.style.justifyContent = 'center';
         buttonContainer.style.marginTop = '5px';


        const button = createMarketButton(targetUrl);
        buttonContainer.appendChild(button);
        targetElement.insertAdjacentElement('beforeend', buttonContainer);
    }

    // Function to add a button next to the link element
    function addMarketButtonNextTo(linkElement, targetUrl) {
         const button = createMarketButton(targetUrl);
        button.style.marginLeft = '5px';

        //Insert button after the text span
         const textSpan = linkElement.nextElementSibling;
        if(textSpan){
         textSpan.parentNode.insertBefore(button, textSpan.nextSibling);
        } else{
         linkElement.parentNode.insertBefore(button, linkElement.nextSibling)
        }

    }

    // --- Title Button Logic ---
    const titleElement = document.querySelector('h2.pi-item.pi-item-spacing.pi-title.pi-secondary-background');
     if (titleElement) {
         const titleText = titleElement.textContent.trim().toLowerCase().replace(/\s+/g, '_');
         const targetUrl = `https://warframe.market/items/${titleText}`;
         addMarketButtonBelow(titleElement, targetUrl);
     }


    // --- Mod Link Button Logic ---
    const spans = document.querySelectorAll('span[data-param2="Mods"]');

    spans.forEach(span => {
       const innerSpan = span.querySelector('span[style*="border-bottom: 2px dotted"]');
       if(innerSpan){
            const link = span.querySelector('a[href^="/wiki/"]');
            if (link) {
                const variable = link.getAttribute('href').split('/wiki/')[1].toLowerCase();
                const targetUrl = `https://warframe.market/items/${variable}`;
                addMarketButtonNextTo(link, targetUrl);
            }
        }
    });
})();