Greasy Fork

Greasy Fork is available in English.

Gumroad Region Lock Bypass on free items

Disable gumroad.com Region Lock

当前为 2022-08-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Gumroad Region Lock Bypass on free items
// @namespace    DisableGumroadRegionLock
// @version      0.2
// @description  Disable gumroad.com Region Lock
// @author       Samu
// @match        https://*.gumroad.com/l/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
  'use strict';


  function init() {
    var container = document.querySelector(".i-want-this-container");
    var btn = container?.querySelector("button.primary");
    var priceInp = container?.querySelector("fieldset.pay-what-you-want-selection");
    var warningContainer = container?.querySelector(".warning[role='alert']");
    var productId = document.head.querySelector("meta[content][property='product:retailer_item_id']");
    var productPrice = document.head.querySelector("meta[content][property='product:price:amount']");

    // try restoring buttons
    if (btn != undefined && false) {

      // var interval = setInterval(() => {
      //   if (container?.querySelector(".warning[role='alert']")) {
      //     container.insertBefore(btn, container.firstChild);
      //     container.insertBefore(priceInp, container.firstChild);
      //     clearInterval(interval);
      //   }
      // }, 100);

    // try getting content url from request
    } else if (warningContainer != undefined && productId?.content && productPrice?.content === "0.0") {
      createCustomButton(productId.content, warningContainer);
    } else {
      setTimeout(init, 100);
    }

  }

  init();

  function createCustomButton(id, container) {

    var url = "https://" + window.location.host + "/purchases";
    var button = document.createElement("button");
    button.classList.add("primary");
    button.textContent = "View Content";

    var errorMsg = "UserScript (Gumroad Region Lock Bypass): Could not fetch contentUrl, script might need update";

    button.addEventListener("click", () => {
      fetchContentUrl(url, id)
        .then(contentUrl => {
          if (contentUrl) {
            window.open(contentUrl, '_blank');
          } else {
            alert(errorMsg);
          }
        })
        .catch(e => alert(errorMsg));
    });

    container.innerHTML = "";
    container.appendChild(button);
  }

  function fetchContentUrl(url, id) {
    var randomString = (Math.random() + 1).toString(36).substring(2);
    return fetch(url, {
      method: "POST",
      body: new URLSearchParams({
        'line_items[0][permalink]': id,
        'line_items[0][perceived_price_cents]': 0,
        'email': `${randomString}@${randomString}.com`,
      }),
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      }
    })
      .then(res => res.json())
      .then(res => {
        if (res?.success) {
          var content = res["line_items"][""];
          if (content?.success) {
            return content["content_url"];
          }
        }
        return null;
      });
  }

  //GM_addStyle(".i-want-this-container { display: block !important; }");
})();