YouTube

YouTube Daha Kolay Kullan

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

Advertisement:

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

Advertisement:

// ==UserScript==
// @name         YouTube
// @namespace    http://tampermonkey.net
// @version      6
// @description  YouTube Daha Kolay Kullan
// @author       Atilla
// @match        https://www.youtube.com/*
// @icon         https://www.gstatic.com/youtube/img/branding/favicon/favicon_192x192_v2.png
// @grant        GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @noframes
// @require https://cdnjs.cloudflare.com/ajax/libs/arrive/2.5.2/arrive.min.js
// @require https://cdn.jsdelivr.net/npm/[email protected]/notyf.min.js
// @license      MIT
// ==/UserScript==
(async () => {
  if (window.trustedTypes && !window.trustedTypes.defaultPolicy) {
    window.trustedTypes.createPolicy("default", {
      createHTML: (string) => string,
    });
  }

  window.addEventListener("keydown", async (ev) => {
    if (
      ev.ctrlKey &&
      ev.key.toLowerCase() === "f" &&
      location.href.includes("live_chat")
    ) {
      ev.preventDefault();
      let targetName = "";
      try {
        targetName = ytInitialData.contents.liveChatRenderer.viewerName;
      } catch (e) {
        console.error("❌ Kullanıcı adı ytInitialData içinden alınamadı!");
        return;
      }
      if (!targetName) {
        console.error("❌ Kullanıcı adı boş döndü.");
        return;
      }
      console.log(`🔍 Aranan isim: "${targetName}"`);
      const chatItems = document.querySelectorAll(
        "yt-live-chat-text-message-renderer",
      );
      let processedCount = 0;
      for (const item of chatItems) {
        const authorNameEl = item.querySelector("#author-name");
        if (authorNameEl && authorNameEl.textContent.trim() === targetName) {
          const menuButton = item.querySelector("#menu button");
          if (menuButton) {
            menuButton.click();
            await new Promise((resolve) => setTimeout(resolve, 150));
            const menuItems = document.querySelectorAll(
              "ytd-menu-navigation-item-renderer, ytd-menu-service-item-renderer",
            );
            for (const menuItem of menuItems) {
              const stringEl = menuItem.querySelector("yt-formatted-string");
              if (stringEl && stringEl.textContent.trim() === "Kaldır") {
                menuItem.click();
                processedCount++;
                await new Promise((resolve) => setTimeout(resolve, 150));
                break;
              }
            }
          }
        }
      }
      console.log(
        `✅ İşlem tamamlandı! Toplam ${processedCount} adet element için "Kaldır" tıklandı.`,
      );
      if (processedCount > 0) {
        new Notyf({
          duration: 15000,
          position: { x: "right", y: "top" },
          dismissible: true,
        }).success(
          `✅ İşlem tamamlandı! Toplam ${processedCount} adet element için "Kaldır" tıklandı.`,
        );
      } else {
        new Notyf({
          duration: 3000,
          position: { x: "left", y: "top" },
          dismissible: true,
        }).error("Kaldırılacak element bulunamadı");
      }
    }
  });

  let notyfCSS = document.createElement("link");
  notyfCSS.href = "https://cdn.jsdelivr.net/npm/[email protected]/notyf.min.css";
  notyfCSS.rel = "stylesheet";
  document.head.prepend(notyfCSS);

  // Depolama
  let DATA_addTimestampToUrl = GM_getValue("addTimestampToUrl", true);
  //==Depolama==

  GM_registerMenuCommand("Ayarlar: Video Süresini URL'Ye Kaydet", () => {
    let newData = !GM_getValue("addTimestampToUrl", true);
    GM_setValue("addTimestampToUrl", newData);
    console.log(
      "%c 'addTimestampToUrl' Veri Başarıyla Kaydedildi",
      "color: green;",
    );
    new Notyf({
      duration: 3000,
      dismissible: true,
      position: { x: "right", y: "top" },
    }).success(
      `${GM_getValue("addTimestampToUrl", true)} 'addTimestampToUrl' Veri Başarıyla Kaydedildi`,
    );
  });

  // Video Süresini URL'ye Kaydet
  if (DATA_addTimestampToUrl === true) {
    const addTimestampToUrl = () => {
      window.addEventListener("keydown", (e) => {
        if (
          (e.ctrlKey || e.metaKey) &&
          e.key.toLowerCase() === "s" &&
          location.href.includes("watch?v")
        ) {
          e.preventDefault();

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

          const seconds = Math.floor(video.currentTime);
          const url = new URL(window.location.href);

          url.searchParams.set("t", seconds);
          window.history.pushState(null, "", url.toString());
        }
      });
    };

    addTimestampToUrl();
  }

  // Video ön izlemesini kaldır
  document.querySelectorAll("#video-preview").forEach((value) => {
    if (!location.href.includes("shorts") || !location.href.includes("watch")) {
      value.remove();
      console.log(value);
    }
  });

  document.arrive("#video-preview", (newElem) => {
    if (!location.href.includes("shorts") || !location.href.includes("watch")) {
      newElem.remove();
      console.log(newElem);
    }
  });

  document.querySelectorAll("*").forEach((value) => {
    if (value.tagName.startsWith("ANIMATED-THUMBNAIL")) {
      value.remove();
      console.log(value);
    }
  });
  document.arrive("*", (newElem) => {
    if (newElem.tagName.startsWith("ANIMATED-THUMBNAIL")) {
      newElem.remove();
      console.log(newElem);
    }
  });
  //==Video ön izlemesini kaldır==
})();