DflixFTP CDS & WEB- Player Buttons

Add IINA, Infuse, VLC, PotPlayer buttons beside Preview or replace Preview button based on URL patterns

  1. // ==UserScript==
  2. // @name DflixFTP CDS & WEB- Player Buttons
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.6
  5. // @description Add IINA, Infuse, VLC, PotPlayer buttons beside Preview or replace Preview button based on URL patterns
  6. // @author slxls
  7. // @match https://dflix.discoveryftp.net/s/view/*
  8. // @match https://*.discoveryftp.net/*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. // Function to create buttons with the same style as the preview button
  17. const createStyledButton = (label, handler) => {
  18. const btn = document.createElement('div');
  19. btn.innerText = label;
  20. btn.className = 'badge badge-fill'; // Same class as the preview button
  21. btn.style.cssText = 'font-size: 15px; background: darkgray; color: black; margin-left: 5px; cursor: pointer;';
  22. btn.onclick = handler;
  23. return btn;
  24. };
  25.  
  26. // Function to handle opening the video with different players
  27. const openWithPlayer = (playerCommand, videoUrl) => {
  28. return () => {
  29. const commandUrl = `${playerCommand}${encodeURIComponent(videoUrl)}`;
  30. window.open(commandUrl, '_blank');
  31. };
  32. };
  33.  
  34. // Logic for dflix.discoveryftp.net/s/view/*
  35. const handleDflixView = () => {
  36. const previewAnchors = document.querySelectorAll('a[href*="/secure/"]');
  37. previewAnchors.forEach((previewAnchor) => {
  38. const videoUrl = previewAnchor.href;
  39.  
  40. const iinaButton = createStyledButton('IINA', openWithPlayer('iina://open?url=', videoUrl));
  41. const infuseButton = createStyledButton('Infuse', openWithPlayer('infuse://x-callback-url/play?url=', videoUrl));
  42. const vlcButton = createStyledButton('VLC', openWithPlayer('vlc://', videoUrl));
  43. const potPlayerButton = createStyledButton('PotPlayer', openWithPlayer('potplayer://', videoUrl));
  44.  
  45. previewAnchor.parentNode.appendChild(iinaButton);
  46. previewAnchor.parentNode.appendChild(infuseButton);
  47. previewAnchor.parentNode.appendChild(vlcButton);
  48. previewAnchor.parentNode.appendChild(potPlayerButton);
  49. });
  50.  
  51. const viewButtons = document.querySelectorAll('.test3[onclick*="view("]');
  52. viewButtons.forEach((viewButton) => {
  53. const onclickAttr = viewButton.getAttribute('onclick');
  54. const videoUrlMatch = onclickAttr.match(/view\('(.+?)'\)/);
  55. if (!videoUrlMatch || videoUrlMatch.length < 2) return;
  56. const videoUrl = videoUrlMatch[1];
  57.  
  58. const iinaButton = createStyledButton('Open in IINA', openWithPlayer('iina://open?url=', videoUrl));
  59. const infuseButton = createStyledButton('Open in Infuse', openWithPlayer('infuse://x-callback-url/play?url=', videoUrl));
  60. const vlcButton = createStyledButton('Open in VLC', openWithPlayer('vlc://', videoUrl));
  61. const potPlayerButton = createStyledButton('Open in PotPlayer', openWithPlayer('potplayer://', videoUrl));
  62.  
  63. const parent = viewButton.parentNode;
  64. viewButton.remove();
  65.  
  66. parent.appendChild(iinaButton);
  67. parent.appendChild(infuseButton);
  68. parent.appendChild(vlcButton);
  69. parent.appendChild(potPlayerButton);
  70. });
  71. };
  72.  
  73. // Logic for cds*.discoveryftp.net/*
  74. const handleCDSView = () => {
  75. const viewButtons = document.querySelectorAll('.test3[onclick*="view("]');
  76. viewButtons.forEach((viewButton) => {
  77. const onclickAttr = viewButton.getAttribute('onclick');
  78. const videoUrlMatch = onclickAttr.match(/view\('(.+?)'\)/);
  79. if (!videoUrlMatch || videoUrlMatch.length < 2) return;
  80. const videoUrl = videoUrlMatch[1];
  81.  
  82. const createStyledButton = (label, handler) => {
  83. const btn = viewButton.cloneNode(true);
  84. btn.innerText = label;
  85. btn.removeAttribute('onclick');
  86. btn.setAttribute('title', label);
  87. btn.onclick = handler;
  88. return btn;
  89. };
  90.  
  91. const openWithPlayer = (playerCommand) => {
  92. return () => {
  93. const commandUrl = `${playerCommand}${encodeURIComponent(videoUrl)}`;
  94. window.open(commandUrl, '_blank');
  95. };
  96. };
  97.  
  98. const iinaButton = createStyledButton('Open in IINA', openWithPlayer('iina://open?url='));
  99. const infuseButton = createStyledButton('Open in Infuse', openWithPlayer('infuse://x-callback-url/play?url='));
  100. const vlcButton = createStyledButton('Open in VLC', openWithPlayer('vlc://'));
  101. const potPlayerButton = createStyledButton('Open in PotPlayer', openWithPlayer('potplayer://'));
  102.  
  103. const parent = viewButton.parentNode;
  104. viewButton.remove();
  105.  
  106. parent.appendChild(iinaButton);
  107. parent.appendChild(infuseButton);
  108. parent.appendChild(vlcButton);
  109. parent.appendChild(potPlayerButton);
  110. });
  111. };
  112.  
  113. // Determine which logic to run based on URL
  114. if (window.location.href.startsWith('https://dflix.discoveryftp.net/s/view/')) {
  115. handleDflixView();
  116. } else if (window.location.href.includes('.discoveryftp.net') && window.location.href.startsWith('https://cds')) {
  117. handleCDSView();
  118. }
  119. })();