YouTube

YouTube Daha Kolay Kullan

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

Advertisement:

// ==UserScript==
// @name         YouTube
// @namespace    http://tampermonkey.net
// @version      7
// @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
// @grant GM_addStyle
// @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==

  // Canlı sohbet hızlı yanıtlama
  const insertUserTag = (authorName) => {
    const inputContainer = document.querySelector(
      '#input.yt-live-chat-text-input-field-renderer, #textarea, [contenteditable="true"]',
    );
    if (!inputContainer) return;

    const tag = authorName.startsWith("@")
      ? authorName + "\u00A0"
      : "@" + authorName + "\u00A0";

    inputContainer.focus();

    if (inputContainer.firstChild) {
      inputContainer.firstChild.textContent =
        tag + inputContainer.firstChild.textContent;
    } else {
      inputContainer.textContent = tag;
    }

    try {
      const range = document.createRange();
      const sel = window.getSelection();

      const textNode = inputContainer.firstChild || inputContainer;

      range.setStart(textNode, tag.length);
      range.collapse(true);

      sel.removeAllRanges();
      sel.addRange(range);
    } catch (err) {
      console.error("İmleç hareketiyle ilgili hata:", err);
    }

    inputContainer.dispatchEvent(
      new InputEvent("input", {
        bubbles: true,
        cancelable: true,
        inputType: "insertText",
        data: tag,
      }),
    );
    inputContainer.dispatchEvent(new KeyboardEvent("keyup", { bubbles: true }));
  };

  document.addEventListener(
    "click",
    (e) => {
      const authorElement = e.target.closest(
        "#author-name, .yt-live-chat-author-chip",
      );

      if (authorElement) {
        const authorName = authorElement.textContent.trim();

        if (authorName) {
          e.preventDefault();
          e.stopPropagation();

          insertUserTag(authorName);
        }
      }
    },
    true,
  );
  //==Canlı sohbet hızlı yanıtlama==

  // Yorumlar sağ panelde
  GM_addStyle(`
#secondary{height:calc(100vh - 80px);overflow:scroll;overflow-x:hidden;overscroll-behavior:contain}#secondary::-webkit-scrollbar{display:block;width:16px}#secondary::-webkit-scrollbar-thumb{height:56px;border-radius:8px;border:4px solid transparent;background-clip:content-box;background-color:var(--yt-opalescence-dark-grey)}#secondary::-webkit-scrollbar-thumb:hover,#secondary::-webkit-scrollbar-thumb:active{background-color:var(--yt-spec-icon-disabled)}
    `);

  const getComments = () => document.getElementById("comments");
  const getWatchNext = () => document.getElementById("related");
  const getRightPanel = () => document.getElementById("secondary-inner");
  const getLeftPanel = () => document.getElementById("primary-inner");

  const panelsContainNodes = () => {
    const commentsNode = getComments();
    const watchNextNode = getWatchNext();
    return !!(
      commentsNode &&
      watchNextNode &&
      getLeftPanel()?.contains(commentsNode) &&
      getRightPanel()?.contains(watchNextNode)
    );
  };

  const swapCommentsAndWatchNext = () => {
    const commentsNode = getComments();
    const watchNextNode = getWatchNext();

    if (!commentsNode || !watchNextNode) return;

    const leftParent = commentsNode.parentElement;
    const rightParent = watchNextNode.parentElement;

    if (leftParent && rightParent && panelsContainNodes()) {
      try {
        const removedComments = leftParent.removeChild(commentsNode);
        const removedWatchNext = rightParent.removeChild(watchNextNode);

        leftParent.appendChild(removedWatchNext);
        rightParent.appendChild(removedComments);
      } catch (error) {
        console.error(`YouTube Yorum Taşıma Hatası: ${error.message}`);
      }
    }
  };

  let timeoutId = null;
  const observer = new MutationObserver(() => {
    if (panelsContainNodes()) {
      swapCommentsAndWatchNext();
    } else if (getComments() && getWatchNext() && !timeoutId) {
      timeoutId = setTimeout(() => {
        if (panelsContainNodes()) swapCommentsAndWatchNext();
        timeoutId = null;
      }, 300);
    }
  });

  const commentsInit = () => {
    const targetNode =
      document.querySelector("ytd-page-manager") || document.body;
    observer.observe(targetNode, { childList: true, subtree: true });

    if (panelsContainNodes()) {
      swapCommentsAndWatchNext();
    }
  };

  commentsInit();
  //==Yorumlar sağ panelde==
})();