javlibrary_preview

preview from r18.com

目前為 2018-09-20 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         javlibrary_preview
// @version      0.0.12
// @include      http*://*javlibrary.com/*/?v=*
// @description  preview from r18.com
// @grant        GM_xmlhttpRequest
// @grant        GM_download
// @namespace    https://greasyfork.org/users/164996a
// ==/UserScript==
// r18.com
// insert position, no need to wait
const $position = document.querySelector('#video_favorite_edit')
if (!$position) return
// 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 addToDoc = video_url => {
	const text = video_url
		? `<video id=jav_r18 style='postiton:absolute;z-order:1' src=${video_url} controls autoplay></video>`
		: '<div id=jav_r18 class=header style="text-align:center;padding-top:1rem;">preview not found</div>'
	$position.insertAdjacentHTML('afterend', text)
}

const r18 = async () => {
	const res = await gmFetch(`http://www.r18.com/common/search/order=match/searchword=${avid}`)
	let video_url = ''
	try {
		const video_tag = parseHTML(res.responseText).querySelector('.js-view-sample')
		video_url = ['high', 'med', 'low'].map(i => video_tag.getAttribute('data-video-' + i)).find(i => i)
	} catch (err) { } finally {
		addToDoc(video_url)
	}
}
r18()
// google
const num=6
const baseUrl = `https://www.google.com/search?tbm=vid&num=${num}&safe=images&pws=0&lr=lang_en\
&as_eq=youtube.com+javlibrary.com+pron.tv&q=`
const fetchList = async () => {
	const parser = new DOMParser()
	const res = await gmFetch(baseUrl + avid)
	const doc = parseHTML(res.responseText)
	const url = [...doc.querySelectorAll('.g .r a')].map(i => i.href)
	url.forEach(src => {
		requestAnimationFrame(() => {
			(document.getElementById('jav_r18')||$position).insertAdjacentHTML('afterend', `
			<div style='display:flex'>
			<a href='${src}' target='_blank' style='display:block;width:40em;text-overflow:ellipsis;overflow: hidden;white-space: nowrap'>${src}</a>
			</div>`)
		})
	})
}
fetchList()