YouTube

YouTube Daha Kolay Kullan

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Advertisement:

// ==UserScript==
// @name         YouTube
// @namespace    http://tampermonkey.net
// @version      8
// @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
// @require https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/js/all.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==

  // Ögeleri kaldır
  const ogeleriKaldir = () => {
    let end = document.getElementById("end");
    let endId = "gizleme-butonu";
    let data = GM_getValue("hideElem", []);

    if (end && document.getElementById(endId) === null) {
      let buttonA = document.createElement("button");
      buttonA.id = endId;
      buttonA.textContent = "Ögeleri Kaldır ";
      buttonA.style.height = "36px";
      buttonA.style.background = "#717171";
      buttonA.style.border = "none";
      buttonA.style.borderRadius = "8px";
      buttonA.style.color = "white";
      buttonA.style.cursor = "pointer";
      end.prepend(buttonA);
      let iA = document.createElement("i");
      iA.setAttribute("class", "fa-solid fa-trash");
      buttonA.append(iA);
      buttonA.addEventListener("click", () => {
        let windowA = window.open("about:blank", "_blank");
        let docA = windowA.document;
        docA.open();
        docA.write(
          "<ul style='list-style: none; padding: 0; margin: 0;'></ul> <script>document.title = 'Çıkınca YT Sayfasını Yenile!'</script>",
        );
        let inputA = document.createElement("input");
        inputA.type = "text";
        inputA.placeholder = "Seçiciyi Yazın";
        let buttonB = document.createElement("button");
        buttonB.type = "submit";
        buttonB.textContent = "Ekle ve Kaydet";
        docA.querySelector("ul").after(inputA);
        docA.querySelector("input").after(buttonB);

        buttonB.addEventListener("click", async () => {
          if (inputA.value !== "") {
            data.push(inputA.value);
            let li = document.createElement("li");
            li.textContent = inputA.value;
            docA.querySelector("ul").append(li);
            GM_setValue("hideElem", data);
            buttonB.textContent = "Kaydedildi (YouTube Sayfasını Yenileyin!)";
            await new Promise((resolve) => setTimeout(resolve, 500));
            buttonB.textContent = "Ekle ve Kaydet";
          }
        });

        if (data.length > 0) {
          data.forEach((value) => {
            let li = document.createElement("li");
            li.textContent = value;
            docA.querySelector("ul").append(li);
          });
        }
      });
      if (data.length > 0) {
        data.forEach((value) => {
          document.querySelectorAll(value).forEach((valueR) => valueR.remove());
        });

        data.forEach((value) => {
          document.arrive(value, (newElem) => {
            newElem.remove();
          });
        });
      }
    }
  };

  ogeleriKaldir();
  //==Ögeleri kaldır==
})();