ViewOnYPMemoryHole

An add-on for ViewOnYP that adds support for Memory Hole.

Versión del día 15/07/2022. Echa un vistazo a la versión más reciente.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT
/* eslint-env browser, greasemonkey */
/* jshint asi: true, esversion: 11 */

// ==UserScript==
// @name               ViewOnYPMemoryHole
// @name:de            ViewOnYPMemoryHole
// @name:en            ViewOnYPMemoryHole
// @namespace          TheLastZombie/userscripts
// @version            1.0.6
// @description        An add-on for ViewOnYP that adds support for Memory Hole.
// @description:de     Ein Add-on für ViewOnYP, das Unterstützung für Memory Hole hinzufügt.
// @description:en     An add-on for ViewOnYP that adds support for Memory Hole.
// @compatible         chrome
// @compatible         edge
// @compatible         firefox
// @compatible         opera
// @compatible         safari
// @homepageURL        https://codeberg.org/sun/userscripts
// @supportURL         https://codeberg.org/sun/userscripts/issues/new
// @contributionURL    https://ko-fi.com/rcrsch
// @contributionAmount €1.00
// @author             TheLastZombie <[email protected]>
// @include            *://www.patreon.com/*
// @match              *://www.patreon.com/*
// @connect            api.memoryhole.cc
// @run-at             document-end
// @inject-into        auto
// @grant              GM.deleteValue
// @grant              GM_deleteValue
// @grant              GM.getValue
// @grant              GM_getValue
// @grant              GM.registerMenuCommand
// @grant              GM_registerMenuCommand
// @grant              GM.setValue
// @grant              GM_setValue
// @grant              GM.xmlHttpRequest
// @grant              GM_xmlhttpRequest
// @noframes
// @require            https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @icon               https://codeberg.org/sun/userscripts/raw/branch/main/icons/ViewOnYPMemoryHole.png
// @copyright          2022, TheLastZombie (https://eric.jetzt/)
// @license            MIT; https://codeberg.org/sun/userscripts/src/branch/main/LICENSE
// ==/UserScript==

// ==OpenUserJS==
// @author             TheLastZombie
// ==/OpenUserJS==

(async function () {
  "use strict";

  if (!(await GM.getValue("cache2"))) await GM.setValue("cache2", {});
  const cache = await GM.getValue("cache2");

  GM.registerMenuCommand("Clear cache", () => {
    GM.deleteValue("cache2").then(alert("Cache cleared successfully."));
  });

  const campaign = document.head.innerHTML
    .match(/"id": "\d+?"/)[0]
    .slice(7, -1);

  if (cache[campaign]) return show(cache[campaign]);

  GM.xmlHttpRequest({
    url: "https://api.memoryhole.cc/graphql",
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    data: JSON.stringify({
      query:
        "query { getPatreonByCampaignId (campaignId: " +
        campaign +
        ") { creator { id } } }",
    }),
    onload: (response) => {
      const id = JSON.parse(response.responseText).data?.getPatreonByCampaignId
        ?.creator?.id;

      if (id) show(id);
    },
  });

  function show(id) {
    if (document.getElementById("voyp")) {
      insert(id);
    } else {
      const observer = new MutationObserver(() => {
        if (document.getElementById("voyp")) insert(id);
      });
      observer.observe(document.body, { childList: true });
    }

    if (!cache[campaign]) cache[campaign] = id;
    GM.setValue("cache2", cache);
  }

  function insert(id) {
    document
      .getElementById("voyp")
      .insertAdjacentHTML(
        "beforeend",
        '<br>Memory Hole: <a href="https://memoryhole.cc/creator/' +
          id +
          '">https://memoryhole.cc/creator/' +
          id +
          "</a>"
      );

    // eslint-disable-next-line no-func-assign
    insert = () => {}; // jshint ignore:line
  }
})();

// @license-end