Construction JavaScript Injection

Inject some javascript into these websites

Verze ze dne 27. 06. 2025. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name            Construction JavaScript Injection
// @description     Inject some javascript into these websites
// @version         1.0.3
// @author          Oliver P
// @namespace       https://github.com/OlisDevSpot
// @license         MIT
// @match           *://*/*
// @run-at          document-end
// @compatible      safari
// @grant           GM.getValue
// @grant           GM.setValue
// @grant           GM.registerMenuCommand
// ==/UserScript==

// jshint esversion: 8

(async function () {
  if (window.self !== window.top) return;

  let company = await GM.getValue("company");
  let firstName = await GM.getValue("firstName");
  let lastName = await GM.getValue("lastName");

  if (!company || !firstName || !lastName) {
    GM.registerMenuCommand("Set Sales Credentials", configure);
    await configure();
  }

  async function configure() {
    company = prompt("Enter your company name (e.g. david-star):") || "";
    firstName = prompt("First name:") || "";
    lastName = prompt("Last name:") || "";

    if (company && firstName && lastName) {
      await GM.setValue("company", company);
      await GM.setValue("firstName", firstName);
      await GM.setValue("lastName", lastName);
      location.reload();
    } else {
      alert("Values cannot be empty!");
    }
  }

  // Build dynamic fetch URL
  const salesperson = { firstName, lastName };
  const currentSiteUrl = encodeURIComponent(window.location.href);
  const params = new URLSearchParams({
    data: JSON.stringify({ currentSiteUrl, salesperson }),
  });
  const url = `https://${company}.pages.dev/your-endpoint?${params}`;

  // Inject dynamic code
  fetch(url)
    .then((res) => res.text())
    .then((code) => {
      const s = document.createElement("script");
      s.textContent = code;
      document.head.appendChild(s);
    })
    .catch((err) => console.error("Inject error:", err));
})();