Guest User

Untitled

a guest
Apr 7th, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. function load_sponsorblock(){
  2. const info_elem = Q('#skip_n');
  3. if (info_elem.innerText.length) return; // already fetched
  4. const hash = sha256(data.video_id).substr(0,4);
  5. const video_obj = Q("video");
  6. let url = `/https://sponsor.ajay.app/api/skipSegments/${hash}?service=YouTube&categories=%5B%22sponsor%22,%22selfpromo%22%5D`;
  7. fetch(url)
  8. .then(response => response.json())
  9. .then(r => {
  10. for (const video of r) {
  11. if (video.videoID != data.video_id) continue;
  12. info_elem.innerText = `(${video.segments.length} segments)`;
  13. const cat_n = video.segments.map(e=>e.category).sort()
  14. .reduce((acc,e) => (acc[e]=(acc[e]||0)+1, acc), {});
  15. info_elem.title = Object.entries(cat_n).map(e=>e.join(': ')).join(', ');
  16. for (const segment of video.segments) {
  17. const [start, stop] = segment.segment;
  18. if (segment.category != "sponsor" && segment.category != "selfpromo") continue;
  19. video_obj.addEventListener("timeupdate", function() {
  20. if (Q("#skip_sponsors").checked &&
  21. this.currentTime >= start &&
  22. this.currentTime < stop-1) {
  23. this.currentTime = stop;
  24. }
  25. });
  26. }
  27. }
  28. });
  29. }
Advertisement
Add Comment
Please, Sign In to add comment