Bunkrr video show thumbnail

Include thumbnail in bunkrr video view page

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Bunkrr video show thumbnail
// @namespace    Violentmonkey Scripts
// @version      0.3
// @description  Include thumbnail in bunkrr video view page
// @author       walmart22
// @match        https://*.bunkrr.su/*
// @license      MIT
// @grant        none
// ==/UserScript==

// Run immediately if ready otherwise queue up
if (document.readyState !== 'loading') {
  insertThumbnail();
} else {
  document.addEventListener('DOMContentLoaded', insertThumbnail);
}

function insertThumbnail() {
  const videoExtension = ['mp4', 'm4v', 'mov', 'mkv'];
  const domain = 'bunkrr'
  const thumbDomain = 'bunkr'
  const url = window.location.href;

  let modifiedUrl = url;
  if (!videoExtension.some(ext => url.toLowerCase().includes(`.${ext}`))) {
    // If the url doesn't include the extension, build the url using the video src
    let video_url = document.querySelector('source').src.split('/').pop();
    modifiedUrl = url.split('/').slice(0, -1).join('/') + '/' + video_url;
  }

  let downloadLink = Array.from(document.querySelectorAll("a")).find(el => el.textContent.trim().startsWith('Download'));
  let prefix = new URL(downloadLink.href).host.split('.')[0];
  let thumbnailBase = modifiedUrl.replace(new RegExp(`\.(${videoExtension.join('|')})`, 'ig'), '.png')
  // Two options seen in the wild
  let thumbnail1 = thumbnailBase.replace(`//${domain}.su/v/`, `//i-${prefix}.${thumbDomain}.ru/thumbs/`);
  let thumbnail2 = thumbnailBase.replace(`//${domain}.su/v/`, `//${prefix}img.${thumbDomain}.ru/thumbs/`);

  if (thumbnail1.indexOf('i-media-files') !== -1) {
    thumbnail2 = thumbnail1.replace("i-media-files", "i");
  }
  // If the first thumbnail fails to load, try the second one
  let onError = `this.onerror=null;this.src='${thumbnail2}';src="${thumbnail2}"`
  let template = document.createElement('template');
  template.innerHTML = `<img src="${thumbnail1}" alt="img" loading="lazy" style="display: inline" onError="this.onerror=null;this.src='${thumbnail2}'">`

  let place = document.querySelector('#statsLink');
  if (!place) {
    place = document.querySelector('body > main > section:nth-child(2) > div > div > div > div:nth-child(2) > div > a');
  }
  place.parentElement.prepend(template.content);
}