jav_preview

perview video and links

Verze ze dne 22. 08. 2019. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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