Return YouTube Comment Username

This script replaces the "handle" in the YouTube comments section to user name

Від 13.10.2023. Дивіться остання версія.

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

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

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

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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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!)

// ==UserScript==
// @name Return YouTube Comment Username
// @name:ja YouTubeコメント欄の名前を元に戻す
// @name:zh-CN 恢復 YouTube 评论用户名
// @name:zh-TW 恢復 YouTube 評論名稱
// @version 0.3.14
// @author yakisova41
// @license MIT
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAADL1JREFUeJztnXtsVFUexz93mAJtsFChtTy1UgRBqlhqgqihPggBCbtmfbCuCoi7fxglRhYwyvpK3OAbHzHiYmQTVoEFdtWIPFUUUXC7vJt1eSlQYctTKGVaOr/942x3pnPvPO+r7ZxPcpLOnDPn/ub+vvM7555XDREhbQzDAAYDlcAtwBXpV+I4Apz02wiPOQ2sB9YBXyPSmG4FRsoCMIwgMBq4B7gZ6JHuxTSu8jOwGlgK/DVVMSQXgHL8b4EngJ72bNR4xA/ADEQWJyuYWACG0Q/4CzDSMdM0XvIxcB8ix+MViC8Aw7gcWIv+1bd19gO/QGSrVaa1AAxjMMr5xW5apvGMk8B4RL6KzQiYihrGEFSvUju//dANWIlh3Bib0TICGMZFQBXQyzPTNF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+DuwApGfU/2gF03AR0AGh9dogK6YR2tPoSZyDgM/ATsROZXpBQyBI0BRxiYm5iRQisgxl+rX2MTtoeBntfNbN4ZADWDvn89ZsxcYjIjF4b+a1oKbTwEztPNbP24JYCOwzIV6NQ7jhgAEmI5ksmVY4zVudAI/QORrh+vUuITTEaABmO1gfRqXcVoAryAS90AaTevDEPW4VuJAXbWo8eeMR6U03uNkBHhKO7/t4VQn8F/AOw7Uo/EYpyLAdEQaHahH4zFOCOBzRBL8Ww9Na8auAMLAdIds0fiAXQH8GZF/OGWMxnvsCKAe+IODtmh8wM5TwAuItJPjPbOXTCPAEdRyY00bJ1MBPG61yUDT9shEANuA95w3ReMHmQjg94g48F+LNa2BdDuBKxBZ5ZYxGu9JJwI0ATNctEXjA+lEgD8hssNNYzTek+oZQaeBp1y0Q+MTqTYBf0TksNvGaLwnlSbgIDDXA1s0PpBKBJgV73ABTdsnmQD+CbzvkS0aH0gmgOmxhwpp2heJBLAckXVeGqPxnnidwEZglse2aHwgXgR4C5HvvTZG4z1WAjgJPOODLRofsBKAPtUji4gVwD7gTZ9s0fhAbCdQn+qRZURHgG+ApT7aovGBZgHoUz2ylGYBLEJEH+aYhQRQZ8s+4bchGn8wBCoR+cxvQzT+8F/HY9h040De8wAAAABJRU5ErkJggg==
// @namespace https://yt-returnname-api.pages.dev/extension/
// @description This script replaces the "handle" in the YouTube comments section to user name
// @description:ja YouTubeのコメント欄の名前をハンドル(@...)からユーザー名に書き換えます。
// @description:zh-TW 此腳本將 YouTube 評論部分中的“handle”替換為用戶名
// @description:zh-CN 此脚本将 YouTube 评论部分中的“handle”替换为用户名
// @match https://www.youtube.com/*
// @grant unsafeWindow
// @run-at document-end
// ==/UserScript==

const inject = ()=>{// src/utils/isCommentRenderer.ts
function isCommentRenderer(continuationItems) {
  if (continuationItems.length > 0) {
    if ("commentThreadRenderer" in continuationItems[0]) {
      return false;
    }
    if ("commentRenderer" in continuationItems[0]) {
      return true;
    }
  }
  return false;
}

// src/utils/debugLog.ts
function debugLog(message, value = "") {
  console.log(`[rycu] ${message} %c${value}`, "color:cyan;");
}
function debugErr(message) {
  console.error(`[rycu] ${message}`);
}

// src/utils/findElementByTrackingParams.ts
function findElementByTrackingParams(trackingParams, elementSelector) {
  let returnElement = null;
  let errorAlerted = false;
  const elems = document.querySelectorAll(elementSelector);
  for (let i = 0; i < elems.length; i++) {
    if (elems[i]?.trackedParams === void 0 && elems[i]?.controllerProxy?.trackedParams === void 0) {
      debugErr("TrackdParams property is not found");
    }
    if (elems[i].trackedParams === trackingParams) {
      returnElement = elems[i];
      break;
    } else if (elems[i]?.controllerProxy?.trackedParams === trackingParams) {
      returnElement = elems[i];
      break;
    } else {
      if (!errorAlerted) {
        void searchTrackedParamsByObject(trackingParams, elems[i]);
        errorAlerted = true;
      }
    }
  }
  return returnElement;
}
async function reSearchElement(trackingParams, selector) {
  return await new Promise((resolve) => {
    let isFinding = true;
    const search = () => {
      const el = findElementByTrackingParams(trackingParams, selector);
      if (el !== null) {
        resolve(el);
        isFinding = false;
      }
      if (isFinding) {
        setTimeout(() => {
          search();
        }, 100);
      }
    };
    search();
  });
}
function findElementAllByCommentId(commnetId, elementSelector) {
  const returnElements = [];
  const elems = document.querySelectorAll(elementSelector);
  for (let i = 0; i < elems.length; i++) {
    if (elems[i] !== void 0) {
      if (elems[i]?.__data?.data?.commentId === void 0 && elems[i]?.controllerProxy?.__data?.data?.commentId === void 0) {
        debugErr("Reply CommentId is not found");
        console.log(elems[i]);
      } else if (elems[i]?.__data?.data?.commentId !== void 0 && elems[i].__data.data.commentId === commnetId) {
        returnElements.push(elems[i]);
      } else if (elems[i]?.controllerProxy?.__data?.data?.commentId !== void 0 && elems[i].controllerProxy.__data.data.commentId === commnetId) {
        returnElements.push(elems[i]);
      }
    }
  }
  return returnElements;
}
async function reSearchElementAllByCommentId(commnetId, selector) {
  return await new Promise((resolve) => {
    let isFinding = true;
    const search = () => {
      const el = findElementAllByCommentId(commnetId, selector);
      if (el !== null) {
        resolve(el);
        isFinding = false;
      }
      if (isFinding) {
        setTimeout(() => {
          search();
        }, 100);
      }
    };
    search();
  });
}
async function searchTrackedParamsByObject(param, elem) {
  const elemObj = Object(elem);
  const search = (obj, history) => {
    Object.keys(obj).forEach((k) => {
      if (typeof obj[k] === "object") {
        search(obj[k], [...history, k]);
      } else if (obj[k] === param) {
        history.push(k);
        alert(
          `[Return YouTube Comment Username] Unknown Object format!
"${history.join(
            ">"
          )}"`
        );
      }
    });
  };
  search(elemObj, []);
}

// src/utils/getShadyChildren.ts
function getShadyChildren(parentElement, index, id) {
  let returnElem;
  const child = parentElement.__shady_native_children[index];
  if (child === null || child.id !== id) {
    returnElem = parentElement.querySelector(`#${id}`);
    console.log(
      `%cReturn YouTube Comment Username Warning%c %cChildren Cannot Get by Index!%c
%cid of element attempting to retrieve: ${id}
If you find this debug log, please report it to the github issue%c`,
      "background:#f0e68c; color:#000;font-size:20px;",
      "",
      "color:#00c72e;font-size:16px;",
      "",
      "color: #13ebdc;",
      "",
      "\nhttps://github.com/yakisova41/return-youtube-comment-username/issues/new?assignees=&labels=bug&projects=&template=bug_report.yaml&title=%5BBug%5D%3A+Children%20Cannot%20Get%20by%20Index"
    );
  } else {
    returnElem = child;
  }
  return returnElem;
}

// src/utils/escapeString.ts
function escapeString(text) {
  return text.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, `&quot;`).replace(/'/g, `&#39;`).replace(/&/g, `&amp;`);
}
function decodeString(text) {
  return text.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, `"`).replace(/&#39;/g, `'`).replace(/&amp;/g, `&`);
}

// src/utils/getUserName.ts
async function getUserName(id) {
  debugLog("Get name");
  const data = await fetch(
    `https://www.youtube.com/feeds/videos.xml?channel_id=${id}`,
    {
      method: "GET",
      cache: "default",
      keepalive: true
    }
  ).then(async (res) => {
    if (res.status !== 200)
      throw new Error(`API Status is ${res.status}`);
    return await res.text();
  }).then((text) => {
    const match = text.match("<title>([^<].*)</title>");
    if (match !== null) {
      return decodeString(match[1]);
    } else {
      debugErr("XML title not found");
      return "";
    }
  });
  return data;
}

// src/rewrites/rewriteOfCommentRenderer/nameRewriteOfCommentRenderer.ts
function nameRewriteOfCommentRenderer(commentRenderer, isNameContainerRender, userId) {
  const commentRendererBody = getShadyChildren(
    commentRenderer,
    2,
    "body"
  );
  if (commentRendererBody === null) {
    throw new Error("[rycu] comment renderer body is null");
  }
  let nameElem = commentRendererBody.querySelector(
    "#main > #header > #header-author > h3 > a > span"
  );
  if (isNameContainerRender) {
    const containerMain = getShadyChildren(commentRendererBody, 1, "main");
    if (containerMain !== null) {
      nameElem = containerMain.querySelector(
        "#header > #header-author > #author-comment-badge > ytd-author-comment-badge-renderer > a > #channel-name > #container > #text-container > yt-formatted-string"
      );
    }
  }
  void getUserName(userId).then((name) => {
    if (nameElem !== null) {
      if (isNameContainerRender) {
        nameElem.__shady_native_innerHTML = escapeString(name);
      } else {
        nameElem.textContent = name;
      }
    } else {
      debugErr("Name element is null");
    }
  }).catch((e) => {
    debugErr(e);
  });
}

// src/rewrites/rewriteOfCommentRenderer/mentionRewriteOfCommentRenderer.ts
function mentionRewriteOfCommentRenderer(commentRenderer) {
  const commentRendererBody = getShadyChildren(commentRenderer, 2, "body");
  const main2 = commentRendererBody?.querySelector("#main");
  if (main2 !== void 0 && main2 !== null) {
    const aTags = main2.querySelectorAll(
      "#comment-content > ytd-expander > #content > #content-text > a"
    );
    for (let i = 0; i < aTags.length; i++) {
      if (aTags[i].textContent?.match("@.*") !== null) {
        const href = aTags[i].getAttribute("href");
        if (href !== null) {
          void getUserName(href.split("/")[2]).then((name) => {
            aTags[i].textContent = `@${name} `;
          }).catch((e) => {
            debugErr(e);
          });
        } else {
          debugErr("Mention Atag is have not Href attr");
        }
      }
    }
  }
}

// src/rewrites/reply.ts
function rewriteReplytNameFromContinuationItems(continuationItems) {
  debugLog("Reply Rewrite");
  for (let i = 0; i < continuationItems.length; i++) {
    const { commentRenderer } = continuationItems[i];
    if (commentRenderer !== void 0) {
      void getReplyElem(commentRenderer.trackingParams).then((replyElem) => {
        reWriteReplyElem(replyElem, commentRenderer);
      });
    }
  }
}
function reWriteReplyElem(replyElem, rendererData) {
  let isContainer = rendererData.authorIsChannelOwner;
  if (rendererData.authorCommentBadge !== void 0) {
    isContainer = true;
  }
  nameRewriteOfCommentRenderer(
    replyElem,
    isContainer,
    rendererData.authorEndpoint.browseEndpoint.browseId
  );
  mentionRewriteOfCommentRenderer(replyElem);
  replyInputRewrite(replyElem);
}
async function getReplyElem(trackedParams) {
  return await new Promise((resolve) => {
    const selector = "#replies > ytd-comment-replies-renderer > #expander > #expander-contents > #contents > ytd-comment-renderer";
    const commentRenderer = findElementByTrackingParams(
      trackedParams,
      selector
    );
    if (commentRenderer !== null) {
      resolve(commentRenderer);
    } else {
      void reSearchElement(trackedParams, selector).then((commentRenderer2) => {
        resolve(commentRenderer2);
      });
    }
  });
}
function rewriteTeaserReplytNameFromContinuationItems(continuationItems) {
  debugLog("Teaser Reply Rewrite");
  for (let i = 0; i < continuationItems.length; i++) {
    const { commentRenderer } = continuationItems[i];
    if (commentRenderer !== void 0) {
      void reSearchElementAllByCommentId(
        commentRenderer.commentId,
        "ytd-comment-replies-renderer > #teaser-replies > ytd-comment-renderer"
      ).then((replyElems) => {
        replyElems.forEach((replyElem) => {
          reWriteReplyElem(replyElem, commentRenderer);
        });
      });
      void reSearchElementAllByCommentId(
        commentRenderer.commentId,
        "ytd-comment-replies-renderer > #expander > #expander-contents > #contents > ytd-comment-renderer"
      ).then((replyElems) => {
        replyElems.forEach((replyElem) => {
          reWriteReplyElem(replyElem, commentRenderer);
        });
      });
    }
  }
}
function replyInputRewrite(replyElem) {
  const replyToReplyBtn = replyElem.querySelector(
    "#reply-button-end > ytd-button-renderer"
  );
  const replyToReplyHander = () => {
    const replyLink = replyElem.querySelector("#contenteditable-root > a");
    const href = replyLink?.getAttribute("href");
    const channelId = href?.split("/")[2];
    if (channelId !== void 0 && replyLink !== null) {
      void getUserName(channelId).then((name) => {
        replyLink.textContent = ` @${name}`;
      });
    }
    replyToReplyBtn?.removeEventListener("click", replyToReplyHander);
  };
  replyToReplyBtn?.addEventListener("click", replyToReplyHander);
  document.addEventListener("rycu-pagechange", () => {
    replyToReplyBtn?.removeEventListener("click", replyToReplyHander);
  });
}

// src/rewrites/comment.ts
function rewriteCommentNameFromContinuationItems(continuationItems) {
  debugLog("Comment Rewrite");
  for (let i = 0; i < continuationItems.length; i++) {
    if (continuationItems[i].commentThreadRenderer !== void 0) {
      void getCommentElem(
        continuationItems[i].commentThreadRenderer.trackingParams
      ).then((commentElem) => {
        reWriteCommentElem(
          commentElem,
          continuationItems[i].commentThreadRenderer
        );
      });
      const teaserContents = continuationItems[i].commentThreadRenderer.replies?.commentRepliesRenderer.teaserContents;
      if (teaserContents !== void 0) {
        rewriteTeaserReplytNameFromContinuationItems(teaserContents);
      }
    }
  }
}
function reWriteCommentElem(commentElem, commentThreadRenderer) {
  const commentRenderer = getShadyChildren(commentElem, 0, "comment");
  if (commentRenderer !== null && commentRenderer !== void 0) {
    let isContainer = commentThreadRenderer.comment.commentRenderer.authorIsChannelOwner;
    if (commentThreadRenderer.comment.commentRenderer.authorCommentBadge !== void 0) {
      isContainer = true;
    }
    nameRewriteOfCommentRenderer(
      commentRenderer,
      isContainer,
      commentThreadRenderer.comment.commentRenderer.authorEndpoint.browseEndpoint.browseId
    );
  }
}
async function getCommentElem(trackingParams) {
  return await new Promise((resolve) => {
    const commentElem = findElementByTrackingParams(
      trackingParams,
      "#comments > #sections > #contents > ytd-comment-thread-renderer"
    );
    if (commentElem !== null) {
      resolve(commentElem);
    } else {
      void reSearchElement(trackingParams, "ytd-comment-thread-renderer").then((commentElem2) => {
        resolve(commentElem2);
      }).catch((e) => {
        debugErr(e);
      });
    }
  });
}

// src/handlers/handleYtAppendContinuationItemsAction.ts
function handleYtAppendContinuationItemsAction(detail) {
  const continuationItems = detail.args[0].appendContinuationItemsAction.continuationItems;
  if (isCommentRenderer(continuationItems)) {
    const replyDetail = detail;
    setTimeout(() => {
      rewriteReplytNameFromContinuationItems(
        replyDetail.args[0].appendContinuationItemsAction.continuationItems
      );
    }, 100);
  } else {
    const commentDetail = detail;
    setTimeout(() => {
      rewriteCommentNameFromContinuationItems(
        commentDetail.args[0].appendContinuationItemsAction.continuationItems
      );
    }, 400);
  }
}

// src/handlers/handleYtCreateCommentAction.ts
function handleYtCreateCommentAction(detail) {
  const createCommentDetail = detail;
  const continuationItems = [
    {
      commentThreadRenderer: createCommentDetail.args[0].createCommentAction.contents.commentThreadRenderer
    }
  ];
  setTimeout(() => {
    rewriteCommentNameFromContinuationItems(continuationItems);
  }, 100);
}

// src/handlers/handleYtCreateCommentReplyAction.ts
function handleYtCreateCommentReplyAction(detail) {
  const createReplyDetail = detail;
  const continuationItems = [
    {
      commentRenderer: createReplyDetail.args[0].createCommentReplyAction.contents.commentRenderer
    }
  ];
  setTimeout(() => {
    rewriteTeaserReplytNameFromContinuationItems(continuationItems);
  }, 100);
}

// src/rewrites/highlightedReply.ts
function rewriteHighlightedReply(trackedParams, isContainer, userId) {
  const elem = findElementByTrackingParams(
    trackedParams,
    "ytd-comment-renderer"
  );
  const rewriteHighlightedReplyElem = (elem2) => {
    nameRewriteOfCommentRenderer(elem2, isContainer, userId);
    replyInputRewrite(elem2);
  };
  if (elem === null) {
    void reSearchElement(trackedParams, "ytd-comment-renderer").then((elem2) => {
      rewriteHighlightedReplyElem(elem2);
    });
  } else {
    rewriteHighlightedReplyElem(elem);
  }
}

// src/handlers/handleYtGetMultiPageMenuAction.ts
function handleYtGetMultiPageMenuAction(detail) {
  const getMultiPageMenuDetail = detail;
  const continuationItems = getMultiPageMenuDetail.args[0].getMultiPageMenuAction.menu.multiPageMenuRenderer.sections[1].itemSectionRenderer?.contents;
  const highLightedTeaserContents = getMultiPageMenuDetail.args[0]?.getMultiPageMenuAction?.menu?.multiPageMenuRenderer.sections[1].itemSectionRenderer?.contents[0]?.commentThreadRenderer.replies?.commentRepliesRenderer?.teaserContents;
  if (continuationItems !== void 0) {
    setTimeout(() => {
      rewriteCommentNameFromContinuationItems(continuationItems);
      if (highLightedTeaserContents !== void 0) {
        const highLightedReplyRenderer = highLightedTeaserContents[0]?.commentRenderer;
        let isContainer = highLightedReplyRenderer.authorIsChannelOwner;
        if (highLightedReplyRenderer.authorCommentBadge !== void 0) {
          isContainer = true;
        }
        rewriteHighlightedReply(
          highLightedReplyRenderer.trackingParams,
          isContainer,
          highLightedReplyRenderer.authorEndpoint.browseEndpoint.browseId
        );
      }
    }, 100);
  }
}

// src/handlers/handleYtHistory.ts
function handleYtHistory(detail) {
  const historyDetail = detail;
  const continuationItems = historyDetail.args[1].historyEntry?.rootData.response.contents.twoColumnWatchNextResults?.results?.results?.contents[3]?.itemSectionRenderer?.contents;
  if (continuationItems !== void 0) {
    setTimeout(() => {
      rewriteCommentNameFromContinuationItems(continuationItems);
    }, 100);
  }
}

// src/handlers/handleYtReloadContinuationItemsCommand.ts
function handleYtReloadContinuationItemsCommand(detail) {
  const reloadDetail = detail;
  const { slot } = reloadDetail.args[0].reloadContinuationItemsCommand;
  if (slot === "RELOAD_CONTINUATION_SLOT_BODY") {
    const continuationItems = reloadDetail.args[0].reloadContinuationItemsCommand.continuationItems;
    if (continuationItems !== void 0) {
      setTimeout(() => {
        rewriteCommentNameFromContinuationItems(continuationItems);
      }, 100);
    }
  }
}

// src/index.ts
function main() {
  debugLog("Script start");
  const handleYtAction = (e) => {
    switch (e.detail.actionName) {
      case "yt-append-continuation-items-action":
        handleYtAppendContinuationItemsAction(e.detail);
        break;
      case "yt-reload-continuation-items-command":
        handleYtReloadContinuationItemsCommand(e.detail);
        break;
      case "yt-history-load":
        handleYtHistory(e.detail);
        break;
      case "yt-get-multi-page-menu-action":
        handleYtGetMultiPageMenuAction(e.detail);
        break;
      case "yt-create-comment-action":
        handleYtCreateCommentAction(e.detail);
        break;
      case "yt-create-comment-reply-action":
        handleYtCreateCommentReplyAction(e.detail);
        break;
    }
  };
  document.addEventListener("yt-action", handleYtAction);
  document.addEventListener("yt-navigate-finish", () => {
    document.dispatchEvent(new Event("rycu-pagechange"));
  });
}

// node_modules/ts-extension-builder/tmp/entry.ts
var args = {};
if (typeof GM_info !== "undefined" && GM_info.script.grant !== void 0) {
  GM_info.script.grant.forEach((propatyName) => {
    let keyName = propatyName.split("GM_")[1];
    if (keyName === "xmlhttpRequest") {
      keyName = "xmlHttpRequest";
    }
    args[propatyName] = GM[keyName];
  });
}
main(args);
}
const script = document.createElement("script");
script.innerHTML = `(${inject.toString()})()`
unsafeWindow.document.body.appendChild(script)