ViewOnYP

Links various membership platforms to Kemono and Coomer.

Versione datata 05/06/2023. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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

// ==UserScript==
// @name               ViewOnYP
// @name:de            ViewOnYP
// @name:en            ViewOnYP
// @namespace          sun/userscripts
// @version            2.14.0
// @description        Links various membership platforms to Kemono and Coomer.
// @description:de     Vernetzt verschiedene Mitgliedschaftsplattformen mit Kemono und Coomer.
// @description:en     Links various membership platforms to Kemono and Coomer.
// @compatible         chrome
// @compatible         edge
// @compatible         firefox
// @compatible         opera
// @compatible         safari
// @homepageURL        https://forgejo.sny.sh/sun/userscripts
// @supportURL         https://forgejo.sny.sh/sun/userscripts/issues/new
// @contributionURL    https://liberapay.com/sun
// @contributionAmount €1.00
// @author             Sunny <[email protected]>
// @include            *://afdian.net/a/*
// @include            *://boosty.to/*
// @include            *://discord.com/channels/*
// @include            *://discord.com/invite/*
// @include            *://www.dlsite.com/*/circle/profile/=/maker_id/*
// @include            *://*.fanbox.cc/
// @include            *://www.fanbox.cc/@*
// @include            *://fansly.com/*
// @include            *://fantia.jp/*
// @include            *://*.gumroad.com/
// @include            *://onlyfans.com/*
// @include            *://www.patreon.com/*
// @include            *://www.subscribestar.com/*
// @include            *://subscribestar.adult/*
// @match              *://afdian.net/a/*
// @match              *://boosty.to/*
// @match              *://discord.com/channels/*
// @match              *://discord.com/invite/*
// @match              *://www.dlsite.com/*/circle/profile/=/maker_id/*
// @match              *://*.fanbox.cc/
// @match              *://www.fanbox.cc/@*
// @match              *://fansly.com/*
// @match              *://fantia.jp/*
// @match              *://*.gumroad.com/
// @match              *://onlyfans.com/*
// @match              *://www.patreon.com/*
// @match              *://www.subscribestar.com/*
// @match              *://subscribestar.adult/*
// @connect            coomer.party
// @connect            kemono.party
// @connect            api.fanbox.cc
// @connect            discord.com
// @run-at             document-end
// @inject-into        auto
// @grant              GM.addStyle
// @grant              GM_addStyle
// @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://forgejo.sny.sh/sun/userscripts/raw/branch/main/icons/ViewOnYP.ico
// @copyright          2020-present, Sunny
// @license            MIT; https://forgejo.sny.sh/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");

  if (await GM.getValue("cache")) {
    cache.Kemono = await GM.getValue("cache");
    await GM.deleteValue("cache");
  }

  if (!(await GM.getValue("style")))
    await GM.setValue(
      "style",
      `
    #voyp {
      background: white;
      position: fixed;
      top: calc(100vh - 25px);
      left: 50%;
      transform: translateX(-50%);
      border-radius: 5px 5px 0 0;
      padding: 25px;
      box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.302), 0 1px 3px 1px rgba(60, 64, 67, 0.149);
      text-align: center;
      z-index: 9999;
    }
    #voyp:hover {
      top: initial;
      bottom: 0;
    }
    #voyp div {
      font-size: small;
      text-transform: uppercase;
      opacity: 0.5;
      text-align: center;
    }
  `
    );

  const sites = [
    {
      name: "Coomer",
      check: "https://coomer.party/api/creators",
      cache: (response, x) => {
        JSON.parse(response.responseText).forEach((y) => {
          if (!cache[x.name]) cache[x.name] = {};
          if (!cache[x.name][y.service]) cache[x.name][y.service] = [];
          cache[x.name][y.service].push(y.id);
        });
        return cache;
      },
      get: (response, host, user) => {
        return Boolean(
          JSON.parse(response.responseText)
            .filter((x) => x.service === host)
            .filter((x) => x.id === user).length
        );
      },
      profile: "https://coomer.party/$HOST/user/$USER",
    },
    {
      name: "Coomer (.su)",
      check: "https://coomer.su/api/creators",
      cache: (response, x) => {
        JSON.parse(response.responseText).forEach((y) => {
          if (!cache[x.name]) cache[x.name] = {};
          if (!cache[x.name][y.service]) cache[x.name][y.service] = [];
          cache[x.name][y.service].push(y.id);
        });
        return cache;
      },
      get: (response, host, user) => {
        return Boolean(
          JSON.parse(response.responseText)
            .filter((x) => x.service === host)
            .filter((x) => x.id === user).length
        );
      },
      profile: "https://coomer.su/$HOST/user/$USER",
    },
    {
      name: "Kemono",
      check: "https://kemono.party/api/creators",
      cache: (response, x) => {
        JSON.parse(response.responseText).forEach((y) => {
          if (!cache[x.name]) cache[x.name] = {};
          if (!cache[x.name][y.service]) cache[x.name][y.service] = [];
          cache[x.name][y.service].push(y.id);
        });
        return cache;
      },
      get: (response, host, user) => {
        return Boolean(
          JSON.parse(response.responseText)
            .filter((x) => x.service === host)
            .filter((x) => x.id === user).length
        );
      },
      profile: "https://kemono.party/$HOST/user/$USER",
    },
    {
      name: "Kemono (.su)",
      check: "https://kemono.su/api/creators",
      cache: (response, x) => {
        JSON.parse(response.responseText).forEach((y) => {
          if (!cache[x.name]) cache[x.name] = {};
          if (!cache[x.name][y.service]) cache[x.name][y.service] = [];
          cache[x.name][y.service].push(y.id);
        });
        return cache;
      },
      get: (response, host, user) => {
        return Boolean(
          JSON.parse(response.responseText)
            .filter((x) => x.service === host)
            .filter((x) => x.id === user).length
        );
      },
      profile: "https://kemono.su/$HOST/user/$USER",
    },
  ];

  GM.registerMenuCommand("Populate cache", () => {
    sites.forEach((x) => {
      GM.xmlHttpRequest({
        url: x.check,
        method: "GET",
        onload: async (response) => {
          const cache = x.cache(response, x);
          await GM.setValue("cache2", cache);
          alert("Populated cache for " + x.name + ".");
        },
      });
    });
  });

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

  GM.addStyle(await GM.getValue("style"));

  document
    .getElementsByTagName("body")[0]
    .insertAdjacentHTML(
      "beforeend",
      '<div id="voyp"><div>ViewOnYP</div></div>'
    );

  const host = window.location.hostname.split(".").slice(-2, -1)[0];
  if (!host) return;

  const p = new Promise((resolve, reject) => {
    switch (host) {
      case "afdian":
        GM.xmlHttpRequest({
          url:
            "https://afdian.net/api/user/get-profile-by-slug?url_slug=" +
            document.location.pathname.split("/")[2],
          onload: (response) =>
            resolve(JSON.parse(response.responseText).data.user.user_id),
        });
        break;
      case "discord":
        switch (document.location.pathname.split("/")[1]) {
          case "channels":
            resolve(document.location.pathname.split("/")[2]);
            break;
          case "invite":
            GM.xmlHttpRequest({
              url:
                "https://discord.com/api/v10/invites/" +
                document.location.pathname.split("/")[2],
              onload: (response) => {
                resolve(JSON.parse(response.responseText).guild.id);
              },
            });
            break;
        }
        break;
      case "dlsite":
        resolve(document.location.pathname.split("/")[6]);
        break;
      case "fanbox": {
        let creatorId = document.location.hostname.split(".").slice(-3, -2)[0];
        if (creatorId === "www")
          creatorId = window.location.pathname.split("/")[1].slice(1);
        GM.xmlHttpRequest({
          url: "https://api.fanbox.cc/creator.get?creatorId=" + creatorId,
          headers: { Origin: "https://fanbox.cc" },
          onload: (response) =>
            resolve(JSON.parse(response.responseText).body.user.userId),
        });
        break;
      }
      case "fansly": {
        GM.xmlHttpRequest({
          url:
            "https://apiv3.fansly.com/api/v1/account?usernames=" +
            document.location.pathname.split("/")[1],
          onload: (response) =>
            resolve(JSON.parse(response.responseText).response[0].id),
        });
        break;
      }
      case "fantia":
        if (document.location.pathname.split("/")[1] === "fanclubs") {
          resolve(document.location.pathname.split("/")[2]);
        } else {
          resolve(
            document
              .querySelector(".fanclub-header a")
              .getAttribute("href")
              .split("/")[2]
          );
        }
        break;
      case "gumroad":
        resolve([
          document.location.hostname.split(".")[0],
          JSON.parse(
            document.getElementsByClassName("js-react-on-rails-component")[0]
              .textContent
          ).creator_profile.external_id,
        ]);
        break;
      case "patreon":
        resolve(
          document.head.innerHTML
            .match(/https:\/\/www\.patreon\.com\/api\/user\/\d+/)[0]
            .slice(33)
        );
        break;
      case "boosty":
      case "onlyfans":
      case "subscribestar":
        resolve(document.location.pathname.split("/")[1]);
        break;
    }
  });

  p.then((users) => {
    if (!Array.isArray(users)) users = [users];

    users.forEach((user) => {
      sites.forEach((x) => {
        if (
          cache[x.name] &&
          cache[x.name][host] &&
          cache[x.name][host].includes(user)
        )
          return show(x, host, user);
        GM.xmlHttpRequest({
          url: x.check,
          method: "GET",
          onload: (response) => {
            if (x.get(response, host, user)) show(x, host, user);
          },
        });
      });
    });
  });

  function show(site, host, user) {
    const name = site.name;
    const url = site.profile.replace("$HOST", host).replace("$USER", user);

    document
      .getElementById("voyp")
      .insertAdjacentHTML(
        "beforeend",
        "<br>" + name + ': <a href="' + url + '">' + url + "</a>"
      );

    if (!cache[site.name]) cache[site.name] = {};
    if (!cache[site.name][host]) cache[site.name][host] = [];
    if (!cache[site.name][host].includes(user))
      cache[site.name][host].push(user);
    GM.setValue("cache2", cache);
  }
})();

// @license-end