Indexxx quick links

Creates quick links to search other sites from indexxx.com

Version au 25/07/2024. Voir la dernière version.

Vous devrez installer une extension telle que Tampermonkey, Greasemonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Userscripts pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension de gestionnaire de script utilisateur pour installer ce script.

(J'ai déjà un gestionnaire de scripts utilisateur, laissez-moi l'installer !)

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

(J'ai déjà un gestionnaire de style utilisateur, laissez-moi l'installer!)

// ==UserScript==
// @name        Indexxx quick links
// @description Creates quick links to search other sites from indexxx.com
// @license     WTFPL
// @match       https://www.indexxx.com/*
// @match       https://vipergirls.to/*
// @match       https://kitty-kats.net/*
// @grant       GM_addStyle
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_addValueChangeListener
// @run-at      document-end
// @noframes
// @version     0.1
// @namespace https://greasyfork.org/users/1339655
// ==/UserScript==

const { hostname, pathname } = window.location;

console.log("HOST", hostname);

const HOME_CSS = `
/* RESET */

html {
  box-sizing: border-box;
}

*, *:before, *:after {
  box-sizing: inherit;
}

body, h1, h2, h3, h4, h5, h6, p, ol, ul {
  margin: 0;
  padding: 0;
  font-weight: normal;
}

ol, ul {
  list-style: none;
}

img {
  max-width: 100%;
  height: auto;
}

/* GLOBAL */

body {
  font-size: 16px;
  font-family: sans-serif;
  margin: 20px;
}

a {
  color: #444;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* HIDE CRAP */

#navCol,
#sidebar,
#header,
.d-flex:has(#googleSearch) {
  display: none;
}

/* RE-STYLE */

.d-flex:has(.pset) {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-end;
}

.pset {
  width: 320px;
  flex-grow: 1;
}

.pset img {
  display: block;
  margin: 0 auto;
  pointer-events: none;
}

.psetInfo {
  text-align: center;
}
`;

if (hostname === "www.indexxx.com") {
  if (pathname === "/home" || pathname.startsWith("/m/")) {
    const button = document.querySelector("h1").insertAdjacentElement("beforeend", document.createElement("button"));

    button.innerText = "📷";

    button.onclick = () => {
      document.querySelector("link[href^='/static/v2/css/joined.css']").remove();

      GM_addStyle(HOME_CSS);

      document.querySelectorAll(".photoSection img").forEach(img => {
        img.src = img.src.replace(/thumbs\/\d+x\d+\//, "");
      });

      document.querySelectorAll("#model-header > :not(:has([itemtype='http://schema.org/Photograph']))").forEach(el => {
        el.remove();
      });

      button.remove();
    }
  }

  function createLink(keywords) {
    const link = document.createElement("span");
    link.innerText = `🔍`;
    link.style.cursor = "pointer";;
    link.onclick = () => {
      GM_setValue("search", keywords);
      openTab("https://kitty-kats.net/");
    };
    return link;
  }

  [...document.querySelectorAll("[itemtype='http://schema.org/Photograph']")].forEach(card => {
    const names = [...card.querySelectorAll("[itemprop='name']")];

    names.forEach(el => {
      const keywords = el.innerText;
      el.parentElement.insertAdjacentElement("afterend", createLink(keywords));
    });

    const allNames = names.map(el => el.innerText).join(" ");
    const link = card.querySelector("[itemprop='url']");
    const fullTitle = card.querySelector("img").alt;
    const keywords = cleanQuery(allNames + " " + (/(.*)\sin\s(?<title>.*),\s\sat\s/gm.exec(fullTitle)?.groups?.title || ''));

    link.insertAdjacentElement("afterend", createLink(keywords));
  })
}

if (hostname === "kitty-kats.net") {
  let lastKeywords = sessionStorage.getItem("search");

  const search = () => {
    const keywords = GM_getValue("search");

    if (keywords === lastKeywords) {
      return;
    }

    sessionStorage.setItem("search", keywords);

    console.log("SEARCH")

    if (keywords) {
      console.log("KEYWORDS", keywords)
      document.querySelector("a[aria-label='Search']").click();
      document.querySelector("input[name='c[title_only]']").checked = true;
      document.querySelector("input[name='keywords']").value = keywords;
      document.querySelector("button.button--icon--search").click();
    }
  };

  GM_addValueChangeListener("search", search);

  search();
}

const openTabs = {};

function openTab(url) {
  if (!openTabs[url] || openTabs[url].closed) {
    openTabs[url] = window.open(url, "_blank");
  }
}

function cleanQuery(str) {
  const stopWords = "\\b(?:a|an|and|the|but|or|on|in|with|is|it|that|this|to|of|for|as|at|by|from|up|down|out|if|about|which|who|what|where|when|why|how)\\b";
  const regex = new RegExp(`\\b\\w*'\\w*\\b|${stopWords}`, 'gi');

  return str
    .replace(regex, '')
    .replace(/[^a-zA-Z0-9 ']/g, '')
    .replace(/\s+/g, ' ')
    .trim();
}