JavBus library trailer

JavBus 图书馆 预告片

As of 08.03.2022. See ბოლო ვერსია.

// ==UserScript==
// @name         JavBus library trailer
// @namespace    no
// @homepageURL  no
// @version      0.1.20220308
// @description  JavBus 图书馆 预告片
// @author       jywyf

// @include     /^.*(jav|bus|dmm|see|cdn|fan){2}\..*$/

// @include     *://*/cn/?v=jav*
// @include     *://*/en/?v=jav*
// @include     *://*/tw/?v=jav*
// @include     *://*/ja/?v=jav*

// @connect      btsow.club
// @license      MIT
// ==/UserScript==

/**
 *    脚本由 https://greasyfork.org/zh-CN/scripts/400267-javbus 二次修改以兼容老司机脚本
 *  - 只保留 预告片 功能,其它剔除
 *  - 可根据电脑分辨率自行调整播放器宽度,高度会自适应(搜索1120px修改合适值)
 *  - (脚本是在和老司机脚本做兼容,不保证兼容其它脚本,水平有限,仅作自用,不予公开)
 */


(function () {
    'use strict';
    function GM_addStyle(css) {
        const style = document.getElementById("GM_addStyleBy8626") || (function () {
            const style = document.createElement('style');
            style.type = 'text/css';
            style.id = "GM_addStyleBy8626";
            document.head.appendChild(style);
            return style;
        })();
        style.innerHTML = css;
    }
    /**
     * 左则补零
     * @param num
     * @param len
     * @returns {*}
     */
    function format_zero(num, len) {
        if (String(num).length > len) return num;
        return (Array(len).join(0) + num).slice(-len);
    }
    //瀑布流
    class Waterfull {
        //获取数据
        getData() {
            let url = $(this.config['next']).attr('href');
            let _this = this;
            if (url !== undefined) {
                this.done = false;
                fetch(url, {credentials: 'same-origin'})
                    .then(function (response) {
                        return response.text();
                    })
                    .then(function (html) {
                        let dom = new DOMParser().parseFromString(html, 'text/html');
                        dom = $(dom);
                        let avatarBox = dom.find(_this.config['items']).find('.avatar-box');
                        if (avatarBox.length > 0) {
                            avatarBox.parent().remove();
                        }
                        let elems = dom.find(_this.config['items']);
                        elems.each(function (i) {
                            $(this).attr('style', '');
                            $(this).find('a').attr('target', '_blank')
                            if (_this.config['selector'] === 'div#video_comments') {
                                let text = $(this).find('textarea').val();
                                text = text.replace(/\[url=([^\[\]]*?)\](.*?)\[\/url\]/g, '<a href="redirect.php?url=$1" target="_blank">$2</a>')
                                text = text.replace(/\[color=([^\[\]]*?)\](.*?)\[\/color\]/g, '<span style="color:$1">$2</span>')
                                text = text.replace(/\[b\](.*?)\[\/b\]/g, '<b>$1</b>')
                                $(this).find('.text').html(text).css('width', '442px');
                            }
                        });
                        $(_this.config['pagination']).html(dom.find(_this.config['pagination']).html());
                        $(_this.config['selector']).append(elems);
                        if (_this.config['useMasonry']) {
                            _this.masonryObj.masonry('appended', elems).masonry();
                        }
                        _this.done = true;
                    })
            }
        }
    }
    class Request {
        constructor() {
            this.lock = [];
        }
        send(url, successCallback) {
            let _this = this;
            return new Promise(function (resolve, reject) {
                let index = _this.lock.indexOf(url);
                if (index === -1) {
                    _this.lock.push(url);
                    GM_xmlhttpRequest({
                        url,
                        method   : 'GET',
                        headers  : {
                            "Cache-Control": "no-cache"
                        },
                        timeout  : 30000,
                        onload   : function (response) {
                            console.log(url + ' success');
                            _this.lock.splice(index, 1);
                            resolve(response);
                        },
                        onabort  : (e) => {
                            console.log(url + " abort");
                            reject("wrong");
                        },
                        onerror  : (e) => {
                            console.log(url + " error");
                            console.log(e);
                            reject("wrong");
                        },
                        ontimeout: (e) => {
                            console.log(url + " timeout");
                            reject("wrong");
                        },
                    });
                } else {
                    reject("发送请求ing");
                }
            }).then(function (response) {
                successCallback(response);
            }, function (err) {
                console.log(err)
            });
        }
    }
    class Base {
        addVideo(code, obj) {
            let codeArr = code.split('-');
            let videoSeries = codeArr[0].toLowerCase();
            let videoNo = format_zero(codeArr[1], 5);
            let videoUrl = '//cc3001.dmm.co.jp/litevideo/freepv/' + videoSeries[0] + '/' + videoSeries.substr(0, 3) + '/' + videoSeries + videoNo + '/' + videoSeries + videoNo + '_mhb_w.mp4';
            let videoUrl2 = '//cc3001.dmm.co.jp/litevideo/freepv/' + videoSeries[0] + '/' + videoSeries.substr(0, 3) + '/' + videoSeries + codeArr[1] + '/' + videoSeries + codeArr[1] + '_mhb_w.mp4';
            let videoUrl3 = '//cc3001.dmm.co.jp/litevideo/freepv/1/1' + videoSeries.substr(0, 2) + '/1' + videoSeries + codeArr[1] + '/1' + videoSeries + codeArr[1] + '_mhb_w.mp4';
            if (code.indexOf('ABW') !== -1) {
                videoUrl = 'https://www.prestige-av.com/sample_movie/TKT' + code + '.mp4'
            }
            let video = $('<div style="text-align: center;padding: 10px;border-radius: 4px;border: 1px solid #ccc;margin: 10px 0;">\
                          <video controls style="width: 1120px;">\
                          <source src="' + videoUrl + '" type="video/mp4" />\
                          <source src="' + videoUrl2 + '" type="video/mp4" />\
                          <source src="' + videoUrl3 + '" type="video/mp4" />\
                          </video>\
                          </div>');
            $(obj).before(video)
        }
    }
    class JavBus extends Base {
        constructor(Request, Waterfull) {
            super(Request, Waterfull);
            this.deleteAD();
            if ($('.col-md-3.info').length > 0) {
                this.detailPage();
            }
        }
        detailPage() {
            let _this = this;
            let info = $('.col-md-3.info');
            //标题
            //识别码
            let codeRow = info.find('p').eq(0);
            let code = codeRow.find('span').eq(1).html();
            //资源表格生成
            //切换事件
            //添加预告视频观看按钮
            this.addVideo(code, '#mag-submit-show')
            //添加跳转到javlibrary链接
            //演员
            //封面图添加下载按钮
        }
        deleteAD() {
            //删除不需要的内容
            $('.mb20').prev('h4').remove();
            $('#urad2').parents('h4').remove();
            //删除广告
            $('.ad-box').remove();
            $('.ad-table,.ad-list,.mb20,.ptb10').remove();
        }
    }
    class JavLibrary extends Base {
        constructor(Request, Waterfull) {
            super(Request, Waterfull);
            GM_addStyle(`
                #video_info td {
                    vertical-align: text-bottom;
                }
                #video_jacket {
                    position: relative;
                }
                #video_jacket a {
                    position: absolute;
                    background: #fff;
                    border: 1px solid #000;
                    padding: 5px 10px;
                    border-radius: 5px;
                    font-size: 12px;
                    right: 5px;
                    top: 5px;
                }
            `);
            if ($('#video_info').length > 0) {
                this.detailPage();
            }
        }
        detailPage() {
            let _this = this;
            let info = $('#video_info');
            //标题
            //识别码
            let codeRow = info.find('.item').eq(0);
            let code = codeRow.find('.text').html();
            //添加跳转到javlibrary链接
            //演员
            //添加预告视频观看按钮
            this.addVideo(code, '#video_favorite_edit')
            //封面图添加下载按钮
        }
    }
    class Main {
        constructor() {
            if ($("footer:contains('JavBus')").length) {
                this.site = 'javBus';
            } else if ($("#bottomcopyright:contains('JAVLibrary')").length) {
                this.site = 'javLibrary'
            }
        }
        make() {
            let WaterfullObj = new Waterfull();
            let requestObj = new Request();
            let obj;
            switch (this.site) {
                case 'javBus':
                    obj = new JavBus(requestObj, WaterfullObj);
                    break;
                case 'javLibrary':
                    obj = new JavLibrary(requestObj, WaterfullObj);
                    break;
            }
            return obj;
        }
    }
    let main = new Main();
    main.make();
})();