jav_preview

perview video and links

Versione datata 22/08/2019. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         jav_preview
// @version      0.0.3
// @include      http*://*javbus.com/*
// @include      http*://*javlibrary.com/*/?v=*
// @description  perview video and links
// @grant        GM_xmlhttpRequest
// @namespace    https://greasyfork.org/users/232476
// ==/UserScript==
// insert position, no need to wait
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

// 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()