Screwfix Web Master

Bypass Screwfix

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Screwfix Web Master
// @description  Bypass Screwfix
// @match        http://*/*
// @match        https://*/*
// @run-at       document-start
// @version 0.0.1.20260611193143
// @namespace https://greasyfork.org/users/1611219
// ==/UserScript==

(() => {
  "use strict";

  const code = `
    (() => {
      "use strict";

      const DEBUG = true;

      const HEADERS_TO_SET = {
        "x-screwfix-client": "consumer-app",
        "x-screwfix-platform": "ios"
      };

      const TARGET_METHODS = ["*"];

      const TARGET_URL_PATTERN = /.*/;

      function log(...args) {
        if (DEBUG) {
          console.log("[Screwfix headers]", ...args);
        }
      }

      function normaliseUrl(url) {
        try {
          return new URL(String(url), location.href).href;
        } catch {
          return String(url);
        }
      }

      function shouldModify(url, method) {
        const fullUrl = normaliseUrl(url);
        const upperMethod = String(method || "GET").toUpperCase();

        const methodMatches =
          TARGET_METHODS.includes("*") ||
          TARGET_METHODS.map(m => m.toUpperCase()).includes(upperMethod);

        return methodMatches && TARGET_URL_PATTERN.test(fullUrl);
      }

      function editHeaders(headersLike) {
        const headers = new Headers(headersLike || {});

        for (const [name, value] of Object.entries(HEADERS_TO_SET)) {
          headers.set(name, value);
        }

        return headers;
      }

      function isManagedHeader(name) {
        const lowerName = String(name).toLowerCase();

        return Object.keys(HEADERS_TO_SET).some(
          headerName => headerName.toLowerCase() === lowerName
        );
      }

      /*
        Patch fetch()
      */
      const originalFetch = window.fetch;

      window.fetch = function patchedFetch(input, init = {}) {
        let url;
        let method;
        let originalHeaders;

        if (input instanceof Request) {
          url = input.url;
          method = init.method || input.method || "GET";
          originalHeaders = init.headers || input.headers;
        } else {
          url = input;
          method = init.method || "GET";
          originalHeaders = init.headers;
        }

        if (!shouldModify(url, method)) {
          return originalFetch.call(this, input, init);
        }

        log("patching fetch", method, normaliseUrl(url), HEADERS_TO_SET);

        const newInit = {
          ...init,
          method,
          headers: editHeaders(originalHeaders)
        };

        if (input instanceof Request) {
          return originalFetch.call(this, new Request(input, newInit));
        }

        return originalFetch.call(this, input, newInit);
      };

      /*
        Patch XMLHttpRequest
      */
      const originalOpen = XMLHttpRequest.prototype.open;
      const originalSend = XMLHttpRequest.prototype.send;
      const originalSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;

      XMLHttpRequest.prototype.open = function patchedOpen(method, url, ...rest) {
        this.__screwfixHeaderUrl = url;
        this.__screwfixHeaderMethod = method;
        this.__screwfixHeaderShouldModify = shouldModify(url, method);

        return originalOpen.call(this, method, url, ...rest);
      };

      XMLHttpRequest.prototype.setRequestHeader = function patchedSetRequestHeader(name, value) {
        if (this.__screwfixHeaderShouldModify && isManagedHeader(name)) {
          return;
        }

        return originalSetRequestHeader.call(this, name, value);
      };

      XMLHttpRequest.prototype.send = function patchedSend(body) {
        if (this.__screwfixHeaderShouldModify) {
          log("patching xhr", this.__screwfixHeaderMethod, normaliseUrl(this.__screwfixHeaderUrl), HEADERS_TO_SET);

          for (const [name, value] of Object.entries(HEADERS_TO_SET)) {
            originalSetRequestHeader.call(this, name, value);
          }
        }

        return originalSend.call(this, body);
      };

      log("installed");
    })();
  `;

  const script = document.createElement("script");
  script.textContent = code;

  const target = document.documentElement || document.head || document.body;

  if (target) {
    target.appendChild(script);
    script.remove();
  } else {
    document.addEventListener("DOMContentLoaded", () => {
      document.documentElement.appendChild(script);
      script.remove();
    }, { once: true });
  }
})();