Roo Checkout Fix

Makes Deliveroo think you're on the app

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

Advertisement:

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

Advertisement:

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Roo Checkout Fix
// @description  Makes Deliveroo think you're on the app
// @match        https://deliveroo.co.uk/*
// @match        https://www.deliveroo.co.uk/*
// @run-at       document-start
// @version 0.0.1.20260609222641
// @namespace https://greasyfork.org/users/1611219
// ==/UserScript==

(() => {
  "use strict";

  const HEADER_NAME = "x-roo-client";
  const HEADER_VALUE = "consumer-app";

  const TARGET_METHODS = ["*"];

  const TARGET_URL_PATTERN = /deliveroo\.co\.uk/;

  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 || {});
    headers.set(HEADER_NAME, HEADER_VALUE);
    headers.set("x-roo-device", "ios");
    headers.set("x-roo-app-version", "3.0.0");
    return headers;
  }

  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);
    }

    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);
  };

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

  XMLHttpRequest.prototype.open = function patchedOpen(method, url, ...rest) {
    this.__headerEditorUrl = url;
    this.__headerEditorMethod = method;
    this.__headerEditorShouldModify = shouldModify(url, method);
    return originalOpen.call(this, method, url, ...rest);
  };

  XMLHttpRequest.prototype.setRequestHeader = function patchedSetRequestHeader(name, value) {
    if (
      this.__headerEditorShouldModify &&
      String(name).toLowerCase() === HEADER_NAME.toLowerCase()
    ) {
      return;
    }
    return originalSetRequestHeader.call(this, name, value);
  };

  XMLHttpRequest.prototype.send = function patchedSend(body) {
    if (this.__headerEditorShouldModify) {
      originalSetRequestHeader.call(this, HEADER_NAME, HEADER_VALUE);
      originalSetRequestHeader.call(this, "x-roo-device", "ios");
      originalSetRequestHeader.call(this, "x-roo-app-version", "3.0.0");
    }
    return originalSend.call(this, body);
  };
})();