SWCombine - Link to Rules Page for Entity from Inventory Table

Adds another link to the Options Column to take you directly to that entity's rules page, rather than having to chain to it via 'Show Stats'

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         SWCombine - Link to Rules Page for Entity from Inventory Table
// @namespace    http://tampermonkey.net/
// @version      2025-01-03
// @description  Adds another link to the Options Column to take you directly to that entity's rules page, rather than having to chain to it via 'Show Stats'
// @author       You
// @match        https://www.swcombine.com/members/inventory2/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=swcombine.com
// @grant        none
// ==/UserScript==

function createElementFromHTML(htmlString) {
    var div = document.createElement('div');
    div.innerHTML = htmlString.trim();

    // Change this to div.childNodes to support multiple top-level nodes.
    return div.firstChild;
}

var entityTypeLookup = {};
entityTypeLookup["2"] = "Ships";
entityTypeLookup["3"] = "Vehicles";
entityTypeLookup["5"] = "Space_Stations";
entityTypeLookup["7"] = "Cities";
entityTypeLookup["4"] = "Facilities";
entityTypeLookup["8"] = "Planets";
entityTypeLookup["12"] = "Items";
entityTypeLookup["10"] = "NPCS";
entityTypeLookup["13"] = "Droids";
entityTypeLookup["11"] = "Creatures";
entityTypeLookup["16"] = "Raw_Materials";

(function() {
    'use strict';

    let table = document.querySelector('.inventory_list_table');

    for (let row of table.children) {
        if(row.querySelector('.inventory_entity_row')) {
            let entityType = document.location.href.split('entityType=')[1].match(/^\d*/);

            let entityID = -1;
            if(row.querySelector('a[href*="images.swcombine"]')) {
                entityID = row.querySelector('a[href*="images.swcombine"]').href.split('/')[5];
            }
            if(row.querySelector('a[href*="custom.swcombine"]')) {
                entityID = row.querySelector('a[href*="custom.swcombine"]').href.split('/')[5];
            }

            if(entityID != -1) {
                let newLink = "/rules/?" + entityTypeLookup[entityType] + "&ID=" + entityID;
                let newElement = createElementFromHTML("<a href='"+newLink+"'>Show Rules Page</a><br />");

                let optionsCol = row.querySelector('.inventoryStatusIcons+td');
                optionsCol.append(newElement);
            }
        }
    }
})();