lrkmusic-ytpro 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/script.js +46 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lrkmusic-ytpro",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "you can find the source code at",
5
5
  "main": "script.js",
6
6
  "scripts": {
package/script.js CHANGED
@@ -338,42 +338,62 @@ compactDisplay: "short",
338
338
 
339
339
 
340
340
 
341
- /*Auto-play Next Video - YouTube style*/
341
+ /*Auto-play Next Video - YouTube / playlist / Mix: video end hone par next auto play, pause nahi*/
342
342
  function setupAutoPlayNext() {
343
343
  try {
344
344
  var player = document.getElementsByClassName('video-stream')[0];
345
345
  if (player && !player.hasAttribute('data-autoplay-setup')) {
346
346
  player.setAttribute('data-autoplay-setup', 'true');
347
-
348
- player.addEventListener('ended', function() {
349
- setTimeout(function() {
350
- try {
351
- // Try to find and click the next video button
352
- var nextButton = document.querySelector('ytm-pivot-bar-item-renderer[tab-id="NEXT"]') ||
353
- document.querySelector('[aria-label*="Next"]') ||
347
+
348
+ function tryPlayNext() {
349
+ try {
350
+ var nextButton = document.querySelector('.ytp-next-button') ||
354
351
  document.querySelector('button[aria-label*="Next"]') ||
355
- document.querySelector('.ytp-next-button');
356
-
357
- if (nextButton) {
358
- nextButton.click();
359
- } else {
360
- // Try to find next video in recommendations
361
- var nextVideo = document.querySelector('ytm-compact-video-renderer a[href*="/watch"]') ||
362
- document.querySelector('ytm-video-with-context-renderer a[href*="/watch"]') ||
363
- document.querySelector('a[href*="/watch"]');
364
- if (nextVideo && nextVideo.href) {
365
- window.location.href = nextVideo.href;
352
+ document.querySelector('button[aria-label*="next"]') ||
353
+ document.querySelector('[aria-label*="Next"]') ||
354
+ document.querySelector('ytm-pivot-bar-item-renderer[tab-id="NEXT"]') ||
355
+ document.querySelector('tp-yt-paper-icon-button[aria-label*="Next"]');
356
+ if (nextButton) {
357
+ nextButton.click();
358
+ return true;
359
+ }
360
+ var playlistRows = document.querySelectorAll('ytm-playlist-panel-video-renderer, ytm-compact-video-renderer');
361
+ for (var i = 0; i < playlistRows.length; i++) {
362
+ var row = playlistRows[i];
363
+ var isCurrent = row.hasAttribute && (row.hasAttribute('playing') || row.hasAttribute('aria-current') || (row.classList && row.classList.contains('playing')));
364
+ if (!isCurrent) continue;
365
+ var nextRow = row.nextElementSibling;
366
+ while (nextRow) {
367
+ var nextA = nextRow.querySelector && nextRow.querySelector('a[href*="/watch"]');
368
+ if (nextA && nextA.href) {
369
+ window.location.href = nextA.href;
370
+ return true;
366
371
  }
372
+ nextRow = nextRow.nextElementSibling;
367
373
  }
368
- } catch (e) {
369
- console.log("Auto-play next error:", e);
374
+ break;
370
375
  }
371
- }, 500);
376
+ var upNext = document.querySelector('ytm-compact-video-renderer a[href*="/watch"]') ||
377
+ document.querySelector('ytm-video-with-context-renderer a[href*="/watch"]') ||
378
+ document.querySelector('a[href*="/watch"].ytm-compact-video-renderer');
379
+ if (upNext && upNext.href) {
380
+ window.location.href = upNext.href;
381
+ return true;
382
+ }
383
+ } catch (e) {}
384
+ return false;
385
+ }
386
+
387
+ player.addEventListener('ended', function() {
388
+ var attempts = [400, 900, 1600];
389
+ attempts.forEach(function(delay) {
390
+ setTimeout(function() {
391
+ if (tryPlayNext()) return;
392
+ }, delay);
393
+ });
372
394
  });
373
395
  }
374
- } catch (e) {
375
- // Silently fail
376
- }
396
+ } catch (e) {}
377
397
  }
378
398
 
379
399
  /* Shorts: when user does NOT scroll, auto-scroll to next short when current video ends */
@@ -2376,7 +2396,7 @@ window.fetch = async function(input, init) {
2376
2396
  try {
2377
2397
  const url = (typeof input === 'string') ? input : (input&&input.url) || "";
2378
2398
  if(isAdUrl(url)){
2379
- return new Response("", {status:200, headers:{"Content-Type":"text/plain"}});
2399
+ return new Response(JSON.stringify({}), {status:200, headers:{"Content-Type":"application/json"}});
2380
2400
  }
2381
2401
  const response = await _origFetch.apply(this, arguments);
2382
2402
  try {