GC Gallery Links

Adds a gallery quicklink. Modeled after the wiki quicklink script

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==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();
})();