继续操作前请注册或者登录。

你正在訪問的內容是外部程式的映像位址,僅用於使用者加速訪問,本站無法保證其可靠性。當前的連結位址(單點即可複製)為 https://greasyfork.org.cn/zh-CN/scripts/465609-youtube-playlist-calculator/discussions/181972,源站連結 點此以跳轉

YouTube Playlist Calculator

Get the total length/duration of a YouTube playlist.

< 脚本 YouTube Playlist Calculator 的反馈

提问 / 留言

§
发布于:2023-05-06

You can obtain the DOM data directly as you don't have any GM grant.

  • document.querySelector('ytd-watch-flexy').__data.playlist is a boolean. true for playlist is there.
  • document.querySelector('ytd-watch-flexy').__data.playlistData are all the data for the playlist in the current page.

For duration, YouTube backend just give the displayable text to front end. Therefore there is only lengthText.

You need to do conversion in JavaScript to obtain the integer values of minutes and seconds.

§
发布于:2023-05-06
编辑于:2023-05-06

If you want to do the network stuff, you might use ajax-hook ajax-hook-min-js. Here is a quick example.

YouTube mostly uses XMLHttpRequest to do the content fetching. btw fetch might be possible.

You can hook the network response to get the token etc. Store it locally. Then you might use the same set of API or token to obtain other information.

§
发布于:2023-05-06

Thanks for the feedback. Being new to JS, all I know is the basics and It's hard for me to understand what you're trying to say anyway thank you again.

§
发布于:2023-05-06
编辑于:2023-05-06

Could you please explain the origin of the property __data? And how did you discover that the element document.querySelector('ytd-watch-flexy') has playlist information? thanks

§
发布于:2023-05-06
编辑于:2023-05-06

Could you please explain the origin of the property __data? And how did you discover that the element document.querySelector('ytd-watch-flexy') has playlist information? thanks

By experience. I have been developing a UserScript called Tabview Youtube for a long time.

Different websites use different ways to develop their UI and UX.

For YouTube, its use custom YT components. When you inspect the elements, you can see there are many elements with tagName yt-xxx or ytd-xxx (This should be standard but still sometimes yt- sometimes ytd-)

The data is binded to these DOMs via __data, and then it render the UI according to their predefined YT components.

Also it utilizes the DOM events for page loading and data changing, etc. For example, yt-page-data-updated or data-changed can detect the playlist has been changed.

ytd-watch-flexy is the watch page main container. YouTube engineers binded almost all "states" as attributes to that element, such as whether playlist exists or not. You can also use MutationObserver to detect the attribute changes.

In Edge / Chrome's inspect, you see the element trees, applied css rules, computed css properties, event attached. You can guess their functions from the naming the YouTube engineers used.

§
发布于:2023-05-06

Thanks so much! I learned something new today 😄

§
发布于:2023-05-07

Is it possible to replace the existing calcElementsPerRow function in the destop_polymer.js file with a new one?

§
发布于:2023-05-07

Is it possible to replace the existing calcElementsPerRow function in the destop_polymer.js file with a new one?



Yes. This is a method from a yt custom element.

You can use debugger to find out what is "this" in that function.
then you can know the element tagName.
then you can override the function in its prototype.

§
发布于:2023-05-07

OMG Thank you I can have 8 videos per row instead of 3. You're GOAT 💖

发布留言

登录以发布留言。