jav_r18

详情页添加r18.com预览

当前为 2018-02-03 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         jav_r18
// @version      0.0.4
// @include      http*://*javlibrary.com/*/?v=*
// @description  详情页添加r18.com预览
// @supportURL   https://github.com/tkkcc/jav_r18/issues
// @grant        GM_xmlhttpRequest
// @grant        GM_download
// @namespace    https://greasyfork.org/users/164996a
// ==/UserScript==
(function () {
    'use strict';
    const parseHTML = str => {
        const tmp = document.implementation.createHTMLDocument();
        tmp.body.innerHTML = str;
        return tmp;
    };
    const avid = document.title.split(' ')[0];
    const add_to_doc = video_url => {
        const text = video_url ? `<video id='jav_r18' style='postiton:absolute;z-order:1' src=${video_url} controls autoplay></video>`
            : '<div class="header" style="text-align:center;padding-top:1rem;">preview not found</div>';
        document.querySelector('#video_favorite_edit').insertAdjacentHTML('afterend', text);
    };
    const get_video_url = (avid, callback) => {
        GM_xmlhttpRequest({
            url: `http://www.r18.com/common/search/searchword=${avid}`,
            method: 'GET',
            onload: res => {
                try {
                    const video_tag = parseHTML(res.responseText).querySelector('.js-view-sample');
                    const video_url = video_tag.getAttribute('data-video-high') || video_tag.getAttribute('data-video-med') || video_tag.getAttribute('data-video-low');
                    callback(video_url);
                } catch (err) { callback(''); }
            }
        });
    };
    if (document.querySelector('#video_jacket_img')) get_video_url(avid, add_to_doc);
})();