CrazyGames+

CrazyGames Sitesi Eğer Türkçe Değilse Otomatik Türkçeye Geçer ve Bazı Gereksiz Görülen Ögeleri Gizler

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         CrazyGames+
// @namespace    http://tampermonkey.net/
// @version      7
// @description  CrazyGames Sitesi Eğer Türkçe Değilse Otomatik Türkçeye Geçer ve Bazı Gereksiz Görülen Ögeleri Gizler
// @author       Atilla
// @match        https://www.crazygames.com/*
// @icon         https://www.crazygames.com/images/logo/logo-ziggy.svg
// @grant        GM_addStyle
// @grant        GM.xmlHttpRequest
// @grant        window.onurlchange
// @require      https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.6/js.cookie.min.js
// @require      https://update.greasyfork.org/scripts/586910/1875145/simple-notify.js
// @license      MIT
// ==/UserScript==

(async () => {
  "use strict";

  // Sabit Seçiciler ve Sınıflar
  const THEME_CSS = `
    [class^='GamePageDesktop_rightSidebar__'] { overflow-y: scroll !important; height: var(--yukseklik) !important; }
    [class^=GamePageDesktop_rightMpuContainer__],
    [class^=GamePageDesktop_leaderboardContainer__],
    [class^=GameInfo_rightColumn__],
    [class*=ThumbVideo],
    [class*=hovered] { display: none !important; }
  `;

  // 1. CSS Kurallarını Tek Seferde Ekle ve Dinamik Yüksekliği Hesapla
  GM_addStyle(THEME_CSS);

  const updateHeight = () => {
    document.documentElement.style.setProperty(
      "--yukseklik",
      `${window.innerHeight * 0.7}px`,
    );
  };
  updateHeight();
  window.addEventListener("resize", updateHeight);

  // Simple-Notify CSS Ekleme
  let css = document.createElement("link");
  css.rel = "stylesheet";
  css.href =
    "https://cdn.jsdelivr.net/npm/simple-notify/dist/simple-notify.css";
  document.head.appendChild(css);

  // 2. Dil Kontrol ve Bildirim Fonksiyonu
  const checkAndSetLanguage = async () => {
    if (window.Cookies.get("czy_locale") === "tr-TR") return;

    window.Cookies.set("czy_locale", "tr-TR", { secure: true, path: "/" });

    new Notify({
      status: "warning",
      title: "Türkçeye Çevrildi",
      text: "Sayfa 3 Saniye İçinde Yenilenecek",
      effect: "slide",
      speed: 300,
      showIcon: false,
      showCloseButton: true,
      autoclose: false,
      type: "filled",
      position: "right top",
    });

    await new Promise((resolve) => setTimeout(resolve, 3000));
    location.reload();
  };

  // 3. Güvenilir Tipler (Trusted Types) Güvenlik Politikası
  if (window.trustedTypes?.createPolicy) {
    window.trustedTypes.createPolicy("default", {
      createHTML: (string) => string,
    });
  }

  // 4. Oyun Beğeni Verilerini Çekme Fonksiyonu
  const fetchAndDisplayRatings = () => {
    if (!location.href.includes("/game/")) return;

    const selector = document.querySelector("h1");
    if (!selector) return;

    const sonuc = location.href.split("/game/")[1]?.split(/[?#]/)[0];
    if (!sonuc) return;

    GM.xmlHttpRequest({
      method: "GET",
      url: `https://api.crazygames.com/v4/en_US/game/${sonuc}/rating`,
      onload: function (response) {
        try {
          const data = JSON.parse(response.responseText);
          let oldText = selector.textContent;

          if (oldText.includes(" / ") && oldText.includes(" | ")) {
            oldText = oldText.split(" | ").slice(1).join(" | ");
          }

          const up = data.upVotes ? data.upVotes.toLocaleString("tr-TR") : "0";
          const down = data.downVotes
            ? data.downVotes.toLocaleString("tr-TR")
            : "0";

          selector.textContent = `${up} / ${down} | ${oldText}`;
        } catch (e) {
          console.error("JSON ayrıştırılamadı:", e);
        }
      },
      onerror: function (error) {
        console.error("İstek sırasında hata oluştu:", error);
      },
    });
  };

  // 5. İlk Çalıştırma ve URL Değişim Takibi
  await checkAndSetLanguage();
  fetchAndDisplayRatings();

  if (window.onurlchange === null) {
    window.addEventListener("urlchange", async () => {
      await checkAndSetLanguage();
      setTimeout(fetchAndDisplayRatings, 500);
    });
  }
})();