Javtrailers_HD

javtrailers.com 加载高清预告片

  1. // ==UserScript==
  2. // @name Javtrailers_HD
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-12-31
  5. // @description javtrailers.com 加载高清预告片
  6. // @author You
  7. // @match https://javtrailers.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=javtrailers.com
  9. // @grant GM_addStyle
  10. // @grant GM_xmlhttpRequest
  11. // @require https://fastly.jsdelivr.net/npm/video.js@7.10.2/dist/video.min.js
  12. // @require https://fastly.jsdelivr.net/npm/videojs-vr@1.10.1/dist/videojs-vr.min.js
  13. // @resource video-js-css https://fastly.jsdelivr.net/npm/video.js@7.10.2/dist/video-js.min.css
  14. // @resource video-vr-js-css https://fastly.jsdelivr.net/npm/videojs-vr@1.10.1/dist/videojs-vr.css
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20. // 观察目标节点
  21. const targetNode = document.body;
  22.  
  23. // 观察配置
  24. const config = { childList: true, subtree: true };
  25.  
  26. // 当观察到变动时执行的回调函数
  27. const callback = function (mutationsList, observer) {
  28. for (let mutation of mutationsList) {
  29. if (mutation.type === 'childList') {
  30. const div = document.getElementById('videoPlayerContainer');
  31. if (div) {
  32. const parent=div.parentNode;
  33. parent.removeChild(div);
  34. // 获取目标元素
  35. var elements = document.getElementsByClassName('col-md-8');
  36. // 修改 CSS 属性
  37. elements[0].style.width = '100%';
  38. console.log('remove videoPlayerContainer');
  39. findURL().then(videoURL => {
  40. addArt(parent, videoURL)
  41. });
  42. }
  43. }
  44. }
  45. };
  46.  
  47. // 创建一个观察器实例并传入回调函数
  48. const observer = new MutationObserver(callback);
  49.  
  50. // 以上述配置开始观察目标节点
  51. observer.observe(targetNode, config);
  52. const artStyle = `
  53. #preview-video-player {
  54. width: 100%;
  55. height: 630px;
  56. }
  57. `
  58. GM_addStyle(artStyle);
  59.  
  60. async function findURL() {
  61. const nuxt = document.getElementById('__NUXT_DATA__');
  62. const text = nuxt.innerText;
  63. const regex = /https:\/\/media\.javtrailers\.com.*?\.(m3u8|mp4)/g;
  64. const matches = text.match(regex);
  65. var videoURL = null;
  66. const contentId = findContentId();
  67. if (matches && matches[0].includes(contentId)) {
  68. videoURL = matches[0];
  69. } else {
  70. const data = await doGet(`https://javtrailers.com/api/video/${contentId}`)
  71. videoURL = JSON.parse(data)['video']['trailerG']
  72. }
  73. console.log(videoURL);
  74. if (videoURL.indexOf('playlist') != -1) {
  75. const data = await doGet(videoURL)
  76. const playlist = data.split('\n')
  77. const hd = playlist[playlist.length - 1]
  78. videoURL = videoURL.replace('playlist.m3u8', hd);
  79. }
  80. return videoURL;
  81. }
  82.  
  83. async function doGet(url) {
  84. return new Promise(resolve => {
  85. GM.xmlHttpRequest({
  86. method: "GET",
  87. headers: { "authorization": "AELAbPQCh_fifd93wMvf_kxMD_fqkUAVf@BVgb2!md@TNW8bUEopFExyGCoKRcZX" },
  88. url,
  89. onload: response => resolve(response.responseText),
  90. });
  91. })
  92. }
  93.  
  94. function addArt(parent, videoURL) {
  95. const poster = findPoster();
  96. const artHTML = `
  97. <video id="preview-video-player" class="video-js" playsinline controls preload="none"
  98. poster="${poster}" >
  99. </video>
  100. `;
  101. // 插入新的div到现有div的后边
  102. parent.insertAdjacentHTML('afterend', artHTML);
  103.  
  104. const srcData = {
  105. type: "video/mp4",
  106. src: videoURL,
  107. };
  108. if (videoURL.includes('m3u8')) {
  109. srcData.type = "application/x-mpegURL";
  110. }
  111. const player = videojs(document.querySelector('#preview-video-player'), {
  112. playbackRates: [0.5, 1, 1.5, 2],
  113. });
  114. player.src(srcData);
  115. }
  116.  
  117. function findPoster() {
  118. // 使用类名获取 img 标签
  119. const imgElement = document.querySelector('.img-fluid.mt-4');
  120. // 获取 src 属性
  121. if (imgElement) {
  122. const src = imgElement.getAttribute('data-src');
  123. return src;
  124. } else {
  125. console.log('Image element not found');
  126. }
  127. }
  128.  
  129. function findContentId() {
  130. // 获取当前 URL
  131. const currentURL = window.location.href;
  132. // 分割 URL 并获取最后一项
  133. const urlParts = currentURL.split('/');
  134. return urlParts[urlParts.length - 1];
  135. }
  136. })();