Guest User

Android external player on Ultimatum

a guest
Jan 12th, 2026
169
0
Never
7
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. // ==UserScript==
  2. // @name External Video Player for Android Chromium
  3. // @description 1 tap - Player 1, 2 taps - Player 2, Long press - Reset. Support for VLC, MX, JustPlayer, mpvEx, Custom.
  4. // @version 2
  5. // @author Kamik
  6. // @match *://*/*
  7. // @grant none
  8. // @run-at document-idle
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. "use strict";
  13.  
  14. // Constants for storage and IDs
  15. const KEY_SINGLE = "extVideo_p1";
  16. const KEY_DOUBLE = "extVideo_p2";
  17. const BTN_ID = "ext-video-main-btn";
  18.  
  19. const PLAYERS = [
  20. { name: "VLC", pkg: "org.videolan.vlc" },
  21. { name: "MX Player Free", pkg: "com.mxtech.videoplayer.ad" },
  22. { name: "MX Player Pro", pkg: "com.mxtech.videoplayer.pro" },
  23. { name: "Just Player", pkg: "com.brouken.player" },
  24. { name: "mpvEx", pkg: "app.marlboroadvance.mpvex" },
  25. { name: "Other…", pkg: "__other__" },
  26. ];
  27.  
  28. let lastVideoUrl = null;
  29. let hideTimer = null;
  30. let tapCount = 0;
  31. let tapTimer = null;
  32.  
  33. const vibrate = (ms) => navigator.vibrate && navigator.vibrate(ms);
  34.  
  35. /* ===== Core Video Detection ===== */
  36. function findVideoUrl() {
  37. const v = document.querySelector("video");
  38. if (v && v.currentSrc && !v.currentSrc.startsWith("blob:"))
  39. return v.currentSrc;
  40. const s = document.querySelector("source[src]");
  41. if (s && s.src) return s.src;
  42. try {
  43. const html = document.documentElement.innerHTML;
  44. const m = html.match(
  45. /https?:\/\/[^"'\\\s]+?\.(mp4|m3u8|webm|mkv)(\?[^"'\\\s]*)?/i
  46. );
  47. return m ? m[0] : null;
  48. } catch {
  49. return null;
  50. }
  51. }
  52.  
  53. /* ===== Cross-Frame Communication (Top Window Logic) ===== */
  54. if (window.self !== window.top) {
  55. // Limited check in frames to save battery
  56. let frameCheckCount = 0;
  57. const frameInterval = setInterval(() => {
  58. const url = findVideoUrl();
  59. if (url) {
  60. window.top.postMessage({ type: "VIDEO_FOUND", url: url }, "*");
  61. clearInterval(frameInterval); // Stop interval once video found
  62. }
  63. if (++frameCheckCount > 20) clearInterval(frameInterval); // Stop after 40s
  64. }, 2000);
  65. return;
  66. }
  67.  
  68. /* ===== Cleanup & Lifecycle ===== */
  69. function removeButton() {
  70. const btn = document.getElementById(BTN_ID);
  71. if (btn) btn.remove();
  72. lastVideoUrl = null;
  73. }
  74.  
  75. // Check on navigation (Back/Forward)
  76. window.addEventListener("popstate", () => {
  77. setTimeout(() => {
  78. if (!findVideoUrl()) removeButton();
  79. }, 500);
  80. });
  81.  
  82. window.addEventListener("message", (e) => {
  83. if (e.data && e.data.type === "VIDEO_FOUND") {
  84. lastVideoUrl = e.data.url;
  85. createButton();
  86. }
  87. });
  88.  
  89. /* ===== UI: Player Selection Menu ===== */
  90. function showMenu(storageKey) {
  91. vibrate(30);
  92. return new Promise((resolve) => {
  93. const overlay = document.createElement("div");
  94. Object.assign(overlay.style, {
  95. position: "fixed",
  96. inset: 0,
  97. background: "rgba(0,0,0,0.8)",
  98. zIndex: 2147483647,
  99. display: "flex",
  100. alignItems: "center",
  101. justifyContent: "center",
  102. backdropFilter: "blur(4px)",
  103. });
  104.  
  105. const box = document.createElement("div");
  106. Object.assign(box.style, {
  107. background: "#121212",
  108. borderRadius: "20px",
  109. padding: "15px",
  110. width: "80%",
  111. maxWidth: "300px",
  112. border: "2px solid #2ecc71",
  113. color: "#fff",
  114. });
  115.  
  116. const title = document.createElement("div");
  117. title.textContent =
  118. storageKey === KEY_SINGLE ? "Slot 1: Single Tap" : "Slot 2: Double Tap";
  119. title.style.cssText =
  120. "text-align:center; padding-bottom:12px; color:#2ecc71; font-weight:bold; border-bottom:1px solid #333; margin-bottom:10px;";
  121. box.appendChild(title);
  122.  
  123. PLAYERS.forEach((p) => {
  124. const row = document.createElement("div");
  125. row.textContent = p.name;
  126. row.style.cssText =
  127. "padding:14px; text-align:center; border-radius:10px; margin:4px 0; background:#1e1e1e; font-family:sans-serif;";
  128. row.onclick = (e) => {
  129. e.stopPropagation();
  130. let pkg = p.pkg;
  131. if (pkg === "__other__") {
  132. pkg = prompt("Enter Package Name:");
  133. if (!pkg) {
  134. overlay.remove();
  135. resolve(null);
  136. return;
  137. }
  138. }
  139. localStorage.setItem(storageKey, pkg);
  140. overlay.remove();
  141. resolve(pkg);
  142. };
  143. box.appendChild(row);
  144. });
  145.  
  146. overlay.onclick = () => {
  147. overlay.remove();
  148. resolve(null);
  149. };
  150. overlay.appendChild(box);
  151. document.body.appendChild(overlay);
  152. });
  153. }
  154.  
  155. /* ===== UI: Main Button (Fixed Viewport) ===== */
  156. function createButton() {
  157. if (document.getElementById(BTN_ID)) return;
  158.  
  159. const btn = document.createElement("div");
  160. btn.id = BTN_ID;
  161. Object.assign(btn.style, {
  162. position: "fixed",
  163. left: "15px",
  164. bottom: "30px",
  165. width: "48px",
  166. height: "48px",
  167. borderRadius: "50%",
  168. background: "rgba(0, 0, 0, 0.9)",
  169. border: "2.5px solid #2ecc71",
  170. display: "flex",
  171. alignItems: "center",
  172. justifyContent: "center",
  173. zIndex: 2147483646,
  174. transition: "opacity 0.4s ease, transform 0.3s ease",
  175. });
  176.  
  177. btn.innerHTML = `<div style="width:0; height:0; border-left:16px solid #2ecc71; border-top:10px solid transparent; border-bottom:10px solid transparent; margin-left:4px;"></div>`;
  178.  
  179. let pressTimer;
  180.  
  181. btn.addEventListener(
  182. "touchstart",
  183. (e) => {
  184. e.preventDefault();
  185. pressTimer = setTimeout(() => {
  186. vibrate(200);
  187. localStorage.removeItem(KEY_SINGLE);
  188. localStorage.removeItem(KEY_DOUBLE);
  189. alert("All player assignments cleared.");
  190. tapCount = 0;
  191. }, 700);
  192. },
  193. { passive: false }
  194. );
  195.  
  196. btn.addEventListener("touchend", () => {
  197. clearTimeout(pressTimer);
  198. tapCount++;
  199. if (tapCount === 1) {
  200. tapTimer = setTimeout(async () => {
  201. const url = findVideoUrl() || lastVideoUrl;
  202. if (tapCount === 1) {
  203. vibrate(35);
  204. let pkg = localStorage.getItem(KEY_SINGLE);
  205. if (!pkg) pkg = await showMenu(KEY_SINGLE);
  206. if (pkg) openIntent(url, pkg);
  207. } else {
  208. vibrate([35, 50, 35]);
  209. let pkg = localStorage.getItem(KEY_DOUBLE);
  210. if (!pkg) pkg = await showMenu(KEY_DOUBLE);
  211. if (pkg) openIntent(url, pkg);
  212. }
  213. tapCount = 0;
  214. }, 300);
  215. }
  216. });
  217.  
  218. document.body.appendChild(btn);
  219. }
  220.  
  221. /* ===== Smooth Scrolling Logic ===== */
  222. window.addEventListener(
  223. "scroll",
  224. () => {
  225. const btn = document.getElementById(BTN_ID);
  226. if (!btn) return;
  227. btn.style.opacity = "0";
  228. btn.style.transform = "scale(0.7)";
  229. clearTimeout(hideTimer);
  230. hideTimer = setTimeout(() => {
  231. btn.style.opacity = "1";
  232. btn.style.transform = "scale(1)";
  233. }, 600);
  234. },
  235. { passive: true }
  236. );
  237.  
  238. /* ===== Observer Engine (High Performance) ===== */
  239. const observer = new MutationObserver(() => {
  240. const url = findVideoUrl();
  241. if (url) {
  242. lastVideoUrl = url;
  243. createButton();
  244. }
  245. });
  246.  
  247. observer.observe(document.documentElement, {
  248. childList: true,
  249. subtree: true,
  250. });
  251.  
  252. function openIntent(url, pkg) {
  253. if (!url) return;
  254. const intent = `intent:${url}#Intent;package=${pkg};type=video/*;end;`;
  255. window.location.href = intent;
  256. }
  257. })();
  258.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment