API for CustomElements in YouTube

A JavaScript tool to modify CustomElements in YouTube

2023-05-09 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greasyforks.org/scripts/465819/1187810/API%20for%20CustomElements%20in%20YouTube.js을(를) 사용하여 포함하는 라이브러리입니다.

작성자
𝖢𝖸 𝖥𝗎𝗇𝗀
버전
1.0
생성일
2023-05-09
갱신일
2023-05-09
크기
6.42KB
라이선스
MIT
  • Once all registered callbacks are performed, the injector will be cleared.
  • Such feature currently we require the browser supporting WeakRef.
  • We offer both asynchronous and synchorized callback in customYtElements.whenRegistered, however, since _initializeProperties() and all other related layouting and rendering will be conducted immediately after component registration, synchorized callback is preferred.

Example 1:

// ==UserScript==
// @name         Testing
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// @run-at       document-start
// @require      https://greasyforks.org/scripts/465819-api-for-customelements-in-youtube/code/API%20for%20CustomElements%20in%20YouTube.js?version=1187694
// ==/UserScript==

(function () {
  'use strict';

  console.log('script started');
  customYtElements.whenRegistered('ytd-rich-grid-renderer', (proto) => {
    console.log('yt element is registered', proto.is);
    proto.calcElementsPerRow = () => 5;
  });

})();

Example 2

  • You might also check whether the injector function is garbage collected (GC) or not.

(function () {
  'use strict';

  console.log('script started');
  customYtElements.whenRegistered('ytd-rich-grid-renderer', (proto) => {
    console.log('yt element is registered', proto.is);
    proto.calcElementsPerRow = () => 5;
    if (typeof WeakRef === 'function') {
      console.debug('Is injector is cleared in memory? (#1)', proto._registered.__injector__.deref() === undefined);
      setTimeout(() => {
        console.debug('Is injector is cleared in memory? (#2)', proto._registered.__injector__.deref() === undefined);
      }, 5000);
    }
  });

})();

example-1-result

长期地址
遇到问题?请前往 GitHub 提 Issues。