☰

javbus_preview

perview video and links

目前為 2019-08-22 提交的版本,檢視 最新版本。

您需要先安裝使用者腳本管理器擴展,如 Tampermonkey、Greasemonkey 或 Violentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 Tampermonkey或 Violentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 Tampermonkey或 Userscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         javbus_preview
// @version      0.0.2
// @include      http*://*javbus.com/*
// @description  perview video and links
// @grant        GM_xmlhttpRequest
// @namespace    https://greasyfork.org/users/232476
// ==/UserScript==
// insert position, no need to wait
const $position = document.querySelector('#mag-submit-show')
if (!$position) return

// change to avoid robot test .jp .sg
const google_domain = 'https://www.google.com'
// request with customer headers
function request(url) {
        return new Promise(resolve => {
            GM_xmlhttpRequest({
                url,
                method: 'GET',
                headers:  {
                    "Cache-Control": "no-cache",
                    "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Mobile Safari/537.36",
                },
                timeout: 30000,
                onload: response => { //console.log(url + " reqTime:" + (new Date() - time1));
                    resolve(response);
                },
                onabort: (e) =>{
                    console.log(url + " abort");
                    resolve("wrong");
                },
                onerror: (e) =>{
                    console.log(url + " error");
                    console.log(e);
                    resolve("wrong");
                },
                ontimeout: (e) =>{
                    console.log(url + " timeout");
                    resolve("wrong");
                },
            });
        });
    }

// GM_xmlhttpRequest promise wrapper
const gmFetch = url =>
  new Promise((resolve, reject) => {
    GM_xmlhttpRequest({
      url: url,
      method: 'GET',
      onload: resolve,
      onerror: reject
    })
  })
const parseHTML = str => {
  const tmp = document.implementation.createHTMLDocument()
  tmp.body.innerHTML = str
  return tmp
}
const avid = document.title.replace(/([^-]+)-([^ ]+) .*/, '$1-$2')
const preview = async () => {
  const srcs = src =>
    ['dmb', 'dm', 'sm']
      .map(i => src.replace(/_(dmb|dm|sm)_/, `_${i}_`))
      .map(i => `<source src=${i}></source>`)
      .join('')

  const r18 = async () => {
    const res = await gmFetch(
      `https://www.r18.com/common/search/order=match/searchword=${avid}`
    )
    const video_tag = parseHTML(res.responseText).querySelector('.js-view-sample')
    const src = ['high', 'med', 'low']
      .map(i => video_tag.getAttribute('data-video-' + i))
      .find(i => i)
    console.log('r18', src)
    return src
  }
  const dmm = async () => {
    const res = await request(
      `https://www.dmm.co.jp/search/=/searchstr=${avid}`
    )
    //const url = res.finalUrl
    if (res.finalUrl == "http://www.dmm.co.jp/top/-/error/area/"){
       console.log('获取dmm视频链接失败,可能需要日本代理ip')
       const src = ""
       return src
    }
    const video_tag = parseHTML(res.responseText).querySelector('.play-btn')
    const src = video_tag.getAttribute('href')
    console.log('dmm', src)
    return src
  }
  let src
  const dmmsrc = await dmm()
  if (dmmsrc == ""){
      console.log("dmm预览视频获取失败,尝试更换r18源")
      src = srcs(await r18())
  }else{
      console.log("dmm预览视频获取成功")
      src = srcs(dmmsrc)
  }
  const html = src
    ? `<video id=jav_preview style='postiton:absolute;z-order:1' controls>${src}</video>`
    : '<div id=jav_preview class=header style="text-align:center;padding-top:1rem;">preview not found</div>'
  $position.insertAdjacentHTML('beforebegin', html)
}
preview()