Construction JavaScript Injection

Inject some javaScript into these websites

Verze ze dne 29. 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.12
// @author          Oliver P
// @namespace       https://github.com/OlisDevSpot
// @license         MIT
// @match           *://*/*
// @run-at          document-end
// @grant           GM.getValue
// @grant           GM.setValue
// @grant           GM.registerMenuCommand
// ==/UserScript==

// jshint esversion: 8

function createRegexFromPattern(pattern) {
  const escaped = pattern.replace(/([.+?^${}()|[\]\\])/g, "\\$1");
  const wildcarded = escaped.replace(/\*/g, ".*");
  const withOptionalSlash = wildcarded.replace(/\/?$/, "/?");
  return new RegExp(`^${withOptionalSlash}$`);
}

const approvedMatchers = [
  // GOOGLE SEARCH
  "https://www.google.com/search?q=*",

  //   ARTICLES
  "https://abc7.com/how-do-i-get-help-with-my-utility-bill-much-power-costs-increase-during-heat-waves-many-people-are-struggling-to-pay-their-electric-bills/12272588/",
  "https://abc7.com/post/la-council-approves-54-million-proposal-modernize-expand/15024448",
  "https://ktla.com/news/local-news/local-businesses-come-together-to-help-fire-victims/",
  "https://www.multihousingnews.com/new-affordable-housing-comes-on-line-in-irvine-calif-3/",
  "https://ktla.com/news/local-news/behind-on-your-ladwp-bills-here-are-the-utility-debt-relief-funding-options-available/",
  "https://www.certisaec.com/largest-construction-companies-in-the-golden-state/",
  "https://www.nbclosangeles.com/news/local/costco-with-apartments-south-la-baldwin-hills/3514264/",
  "https://www.yahoo.com/news/local-organizations-collect-donations-fire-144336071.html*",

  //   GLOBAL
  "https://www.sce.com/mysce/billsnpayments*",
  "https://www.sce.com/save-money/*",

  //   REVIEW PLATFORMS
  "https://www.bbb.org/us/*",
  "https://www.yelp.com/biz/*",

  //   GOVERNMENT
  "https://www.energy.ca.gov/rules-and-regulations/energy-suppliers-reporting/clean-energy-and-pollution-reduction-act-sb-350",
  "https://www.cslb.ca.gov/OnlineServices/CheckLicenseII/LicenseDetail.aspx?LicNum=*",
];

function isApprovedMatcher(url) {
  return approvedMatchers.some((matcher) =>
    createRegexFromPattern(matcher).test(url)
  );
}

(async function () {
  if (window.self !== window.top) return;
  GM.registerMenuCommand("Set Sales Credentials", configure);
  if (!isApprovedMatcher(window.location.href)) return;

  let company = await GM.getValue("company");
  let firstName = await GM.getValue("firstName");
  let lastName = await GM.getValue("lastName");
  
  console.log("changed. Will this update?");

  if (!company || !firstName || !lastName) {
    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!");
    }
  }

  // SYSTEM VARS
  const CDN_URL = "https://construction-js-injections.pages.dev";

  // PERSONAL VARS
  const salesperson = {
    firstName,
    lastName,
    get fullName() {
      return this.firstName + " " + this.lastName;
    },
    get key() {
      return this.firstName.toLowerCase() + "-" + this.lastName.toLowerCase();
    },
  };

  // QUERY STRING
  const currentSiteUrl = encodeURIComponent(window.location.href);
  const params = {
    data: JSON.stringify({ currentSiteUrl, salesperson }),
  };
  const urlSearchParams = new URLSearchParams(params).toString();

  // Inject dynamic code
  const response = await fetch(`${CDN_URL}/${company}?${urlSearchParams}`);
  const code = await response.text();
  console.log(code);
  const script = document.createElement("script");
  script.textContent = code;
  document.head.appendChild(script);
})();