GC Gallery Links

Adds a gallery quicklink. Modeled after the wiki quicklink script

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         GC Gallery Links
// @namespace    https://greasyfork.org/en/users/1554948-oneguy
// @version      1.1
// @description  Adds a gallery quicklink. Modeled after the wiki quicklink script
// @author       oneguy
// @match        https://www.grundos.cafe/*
// @icon         https://grundoscafe.b-cdn.net/activities/wiz.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  "use strict";

  const ICON_URL = "https://grundoscafe.b-cdn.net/activities/wiz.png";

  function createShopWizardLink(itemName) {
    const newLink = document.createElement("a");

    newLink.href =
      `https://www.grundos.cafe/market/wizard/?submit=Search` +
      `&query=${encodeURIComponent(itemName)}` +
      `&area=1` +
      `&search_method=1` +
      `&min_price=` +
      `&max_price=`;

    newLink.title = `Search Shop Wizard for ${itemName}`;
    newLink.target = "_blank";
    newLink.rel = "noopener noreferrer";

    const img = document.createElement("img");
    img.src = ICON_URL;
    img.alt = "Shop Wizard";
    img.className = "shop-wizard-helper";

    newLink.appendChild(img);
    return newLink;
  }

  function addShopWizardLinkForItem(item, itemName) {
    let searchLinksDiv = item.querySelector(".searchhelp");

    if (!searchLinksDiv) {
      searchLinksDiv = document.createElement("div");
      searchLinksDiv.className = "searchhelp";
      item.appendChild(searchLinksDiv);
    }

    if (searchLinksDiv.querySelector(".shop-wizard-helper")) {
      return;
    }

    const newLink = createShopWizardLink(itemName);
    searchLinksDiv.appendChild(newLink);
  }

  function getItemNameFromSearchHelp(searchLinksDiv) {
    if (!searchLinksDiv) return "";

    if (searchLinksDiv.id && searchLinksDiv.id.endsWith("-links")) {
      return searchLinksDiv.id.replace(/-links$/, "").trim();
    }

    const existingWizardLink = searchLinksDiv.querySelector(
      'a[href*="/market/wizard/"][href*="query="]',
    );

    if (existingWizardLink) {
      const url = new URL(existingWizardLink.href, window.location.origin);
      return url.searchParams.get("query") || "";
    }

    return "";
  }

  function processInventoryItems() {
    document.querySelectorAll(".inv-item").forEach((item) => {
      const itemNameSpan = item.querySelector(".item-info span");

      if (itemNameSpan) {
        addShopWizardLinkForItem(item, itemNameSpan.textContent.trim());
      }
    });
  }

  function processSDBItems() {
    document
      .querySelectorAll('div[id^="sdb-item-"].data.flex-column.small-gap.break')
      .forEach((item) => {
        const itemNameStrong = item.querySelector("strong");

        if (itemNameStrong) {
          addShopWizardLinkForItem(item, itemNameStrong.textContent.trim());
        }
      });
  }

  function processItemList() {
    document.querySelectorAll(".itemList.margin-1 .inv-item").forEach((item) => {
      const itemNameStrong = item.querySelector("strong");

      if (itemNameStrong) {
        addShopWizardLinkForItem(item, itemNameStrong.textContent.trim());
      }
    });
  }

  function processTradingPostItems() {
    document.querySelectorAll(".trade-item").forEach((item) => {
      const itemNameSpan = item.querySelector(".item-info span");

      if (itemNameSpan) {
        addShopWizardLinkForItem(item, itemNameSpan.textContent.trim());
      }
    });
  }

  function processKadoateryItems() {
    document.querySelectorAll(".quest-item").forEach((item) => {
      const itemNameEl = item.querySelector("strong.block");

      if (itemNameEl) {
        addShopWizardLinkForItem(item, itemNameEl.textContent.trim());
      }
    });
  }

  function processJQuestItems() {
    document.querySelectorAll(".centered-item").forEach((item) => {
      const searchLinksDiv = item.querySelector(".searchhelp");
      const itemName = getItemNameFromSearchHelp(searchLinksDiv);

      if (itemName) {
        addShopWizardLinkForItem(item, itemName);
      }
    });
  }

  function processIQuestItems() {
    document.querySelectorAll(".itemList .centered-item").forEach((item) => {
      const searchLinksDiv = item.querySelector(".searchhelp");
      const itemName = getItemNameFromSearchHelp(searchLinksDiv);

      if (itemName) {
        addShopWizardLinkForItem(item, itemName);
      }
    });
  }
  
function processItemSearchPage() {
  document.querySelectorAll(".item-search-container").forEach((container) => {
    const searchLinksDiv = container.querySelector(".searchhelp");
    const itemName = getItemNameFromSearchHelp(searchLinksDiv);

    if (itemName) {
      addShopWizardLinkForItem(container, itemName);
    }
  });
}

  function addCustomStyles() {
    const style = document.createElement("style");
    style.textContent = `
      .searchhelp a {
        margin-right: 5px;
      }

      .shop-wizard-helper {
        width: 20px;
        height: 20px;
        vertical-align: middle;
      }
    `;
    document.head.appendChild(style);
  }

  addCustomStyles();
  processInventoryItems();
  processSDBItems();
  processItemList();
  processTradingPostItems();
  processKadoateryItems();
  processJQuestItems();
  processIQuestItems();
  processItemSearchPage();
})();