jav_preview

添加jav官方预览影片

Pada tanggal 22 Agustus 2019. Lihat %(latest_version_link).

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         jav_preview
// @version      0.0.5
// @include      http*://*javbus.com/*
// @include      http*://*javlibrary.com/*/?v=*
// @description  添加jav官方预览影片
// @grant        GM_xmlhttpRequest
// @namespace    https://greasyfork.org/users/232476
// ==/UserScript==
// 根据网站域名判断视频插入位置
const domain = document.domain
var $position
if (domain == "www.javbus.com"){
    $position = document.querySelector('#mag-submit-show')
}else if (domain == "www.javlibrary.com"){
    $position = document.querySelector('#video_favorite_edit')
}

if (!$position) return

// 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}`
    )
    try {
    const video_tag = parseHTML(res.responseText).querySelector('.js-view-sample')
    const src = ['low', 'med', 'high']
      .map(i => video_tag.getAttribute('data-video-' + i))
      .find(i => i)
    console.log('r18', src)
    return src
    }catch(err){
        console.log("获取r18视频地址出现错误", err)
        const src = ""
        return src
    }

  }
  const dmm = async () => {
    const res = await request(
      `https://www.dmm.co.jp/search/=/searchstr=${avid}`
    )
    if (res.finalUrl == "http://www.dmm.co.jp/top/-/error/area/"){
       const src = ""
       return src
    }
    try {
        const video_tag = parseHTML(res.responseText).querySelector('.play-btn')
        const src = video_tag.getAttribute('href')
        console.log('dmm', src)
        return src
    }catch (err){
        console.log('获取dmm视频出现错误:', err)
        const src = ""
        return src
    }
  }
  let src
  const r18src = await r18()
  if (r18src == ""){
      console.log("r18预览视频获取失败,尝试使用dmm源,请切换为日本IP")
      dmmsrc = await dmm()
      if (dmmsrc == ""){
          console.log("dmm预览视频获取失败,请检查IP是否为日本并确保番号正确")
      }else {
         src = srcs(await dmm())
      }
  }else{
      console.log("r18预览视频获取成功")
      src = srcs(r18src)
  }
  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()