OB Onekey-Info-Generator

Ourbits 一键获取信息

当前为 2018-06-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         OB Onekey-Info-Generator
// @namespace    [email protected]
// @version      2018060901
// @description  Ourbits 一键获取信息
// @author       Exhen
// @match        https://ourbits.club/upload.php*
// @grant        GM_xmlhttpRequest
// @grant        GM_setClipboard
// @icon         https://ourbits.club/favicon.ico
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_download
// @require      http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js
// @require      https://cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js
// @connect      *
// ==/UserScript==

var getDoc = function (url, meta, callback) {
    GM_xmlhttpRequest({
        method: 'GET',
        url: url,
        headers: {
            'User-agent': window.navigator.userAgent,
            'Content-type': null
        },
        onload: function (responseDetail) {
            var doc;
            doc = '';
            if (responseDetail.status == 200) {
                doc = (new DOMParser).parseFromString(responseDetail.responseText, 'text/html');
                if (doc == undefined) {
                    doc = document.implementation.createHTMLDocument('');
                    doc.querySelector('html').innerHTML = responseText;
                }
            }
            callback(doc, responseDetail, meta);
        }
    });
};


var getBlob = function (url, referer, callback) {
    GM_xmlhttpRequest({
        method: 'GET',
        url,
        headers: {
            'User-agent': window.navigator.userAgent,
            'Content-type': null,
            'referer': referer
        },
        responseType: 'blob',
        onload: function (responseDetail) {
            if (responseDetail.status >= 200 && responseDetail.status < 300) {
                callback(responseDetail.response);
            }
        }
    })
}
var postAttach = function (blob, filename, callback) {
    let xhr = new XMLHttpRequest();
    let formData = new FormData();
    formData.append('file', blob, filename);
    xhr.open('POST', '/attachment.php');
    xhr.send(formData);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
            let match = xhr.responseText.match(/(?<=\[attach\]).*(?=\[\/attach\])/);
            if (match) callback(match);
        }
    };
}

$('form#compose td').filter(function () { return $(this).text() == '豆瓣链接' }).parent().addClass('douban');
var douban_button = $('<input type="button" class="douban_button" value="一键填写">');
douban_button.click(function () {
    var dburl = $(this).prev()[0].value;
    getDoc(dburl, null, function (doc, res, meta) {
        var douban_id = dburl.split('/')[4];
        var title_cn = $('#content > h1 > span', doc)[0].textContent.split(' ').shift();
        var director = $('div.article #info span.attrs:first', doc).text();
        var imdburl = $('div#info a[href^=\'http://www.imdb.com/title/tt\']', doc).attr('href');


        var moive_info = '';
        if (title_cn) { moive_info = moive_info + '\n◎片  名 ' + title_cn.replace(/ \/ /g, '\n     ' + ' '); }
        var title_aka = $('div.article #info', doc).contents().filter(function () {
            return (this.nodeType === 3) && ($(this).prev().text() == "又名:");
        }).text().trim().replace(/ \/ /g, '/');
        if (title_aka) {
            moive_info = moive_info + '\n◎又  名 ' + title_aka;
        }
        var year = $('#content > h1 > span.year', doc).text().substr(1, 4);
        if (year) {
            moive_info = moive_info + '\n◎年  代 ' + year;
        }
        var region = $('div.article #info', doc).contents().filter(function () {
            return (this.nodeType === 3) && ($(this).prev().text() == "制片国家/地区:");
        }).text().trim().replace(/ \/ /g, '/');
        if (region) {
            moive_info = moive_info + '\n◎产  地 ' + region;
        }
        var genre = '';
        $('div.article #info span[property="v:genre"]', doc).each(function () { genre += $(this).text() + '/' });
        if (genre) {
            moive_info = moive_info + '\n◎类  别 ' + genre.slice(0, -1);
        }
        var language = $('div.article #info', doc).contents().filter(function () {
            return (this.nodeType === 3) && ($(this).prev().text() == "语言:");
        }).text().trim().replace(/ \/ /g, '/');
        if (language) {
            moive_info = moive_info + '\n◎语  言 ' + language;
        }
        var releaseDate ='';
         $('div.article #info [property="v:initialReleaseDate"]', doc).each(function(){
             releaseDate+=$(this).text()+'/';
         })
        if (releaseDate) {
            moive_info = moive_info + '\n◎上映日期 ' + releaseDate.slice(0,-1);
        }
        var doubanRating = $('strong.rating_num.ll', doc).text();
        if (doubanRating) {
            moive_info = moive_info + '\n◎豆瓣评分 ' + doubanRating + '/10 from ' + $('a.rating_people span',doc).text().replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')+' users';
        }
        moive_info = moive_info + '\n◎豆瓣链接 ' + dburl;
        var duration = $('div.article #info', doc).contents().filter(function () {
            return ($(this).prev().attr('property') == "v:runtime") || ($(this).prev().text() == "片长:");
        }).text().trim();
        if (duration) {
            moive_info = moive_info + '\n◎片  长 ' + duration;
        }
        var director = $('div.article #info span.attrs:first', doc).text().replace(/ \/ /g, '\n     ' + ' ');
        if (director) {
            moive_info = moive_info + '\n◎导  演 ' + director;
        }
        var actors = $('div.article #info span.actor span.attrs', doc).contents().filter(function () {
            return $(this).attr("class") !== "more-actor";
        }).text().replace(/ \/ /g, '\n     ' + ' ');
        if (actors) {
            moive_info = moive_info + '\n◎主  演 ' + actors;
        }
        var intro = $('div.article div.related-info [property="v:summary"]', doc).text().replace(/ \n/g, '').replace(/ /g, '');
        if (intro) {
            moive_info = moive_info + '\n\n◎简  介\n' + intro;
        }
        var award = '';
        $('ul.award', doc).each(function () {
            $(this).find('li').each(function () {
                award += $(this).text().replace(/\n/g, ' ').replace(/ +/g, '') + ' ';
            })
            award += '\n  '
        });
        if (award) {
            moive_info = moive_info + '\n◎获奖情况\n\n  ' + award;
        }
        getDoc(imdburl, null, function (doc_imdb, res, meta) {
            var imdb_rating = $('span[itemprop=ratingValue]', doc_imdb).text();
            if(imdb_rating){
                $('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val($('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val().replace(/◎豆瓣评分/, '◎IMDb评分 ' + imdb_rating + '/10 from '+$('span[itemprop=ratingCount]', doc_imdb).text()+' users'+'\n◎IMDb链接 ' + imdburl + '\n◎豆瓣评分'));
            }
            
        })



        $('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val(`[quote]请在这里上传海报并把本行文字删掉[/quote]\n[quote]${moive_info}\n[/quote]\n[quote]\n请在这里补充INFO信息并把本行文字删掉\n[/quote]`);

        $('form#compose td').filter(function () { return $(this).text() == 'IMDb链接' }).parent().find('input')[0].value = imdburl;
        $('form#compose td').filter(function () { return $(this).text() == '副标题' }).parent().find('input')[0].value = title_cn + ' ' + director + '导演作品';
        console.log(title_cn, ' ', director, '导演作品');


        var posterAnchor = $('#mainpic img', doc);
        if (posterAnchor.attr('src') && (posterAnchor.attr('title') !== '点击上传封面图片')) {
            $('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val($('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val().replace(/请在这里上传海报并把本行文字删掉/, '已经找到可用海报,正在自动下载。'));
            // get the posters page's URL via movie.douban.com's customs
            var postersUrl = 'https://movie.douban.com/subject/' + douban_id + '/photos?type=R';
            getDoc(postersUrl, null, function (doc1, res, meta) {
                var aPosterUrl = $('.article > ul > li:nth-child(1) > div.cover > a', doc1).attr('href');
                getDoc(aPosterUrl, null, function (doc2, res, meta) {
                    var hdPosterAnchor = $('span.magnifier > a', doc2);
                    if (hdPosterAnchor.attr('href') == '#') {
                        $('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val($('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val().replace(/已经找到可用海报,正在自动下载。/, '未登录(不可用)豆瓣,无法自动下载海报,请手动登陆豆瓣后重试,或自行上传海报并把本行文字删掉。'));
                        return;
                    }
                    console.log(hdPosterAnchor.attr('href'))
                    getBlob(hdPosterAnchor.attr('href'), dburl, function (blob) {
                        if (!blob) {
                            $('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val($('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val().replace(/已经找到可用海报,正在自动下载。/, '自动下载海报失败,请自行上传海报并把本行文字删掉。'));
                        }
                        console.log(blob);
                        $('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val($('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val().replace(/已经找到可用海报,正在自动下载。/, '已成功下载海报,正在上传到OB服务器。'));
                        postAttach(blob, hdPosterAnchor.attr('href').split('/')[7], function (attach_id) {
                            $('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val($('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val().replace(/已成功下载海报,正在上传到OB服务器。/, '[attach]' + attach_id + '[/attach]'));
                        })
                    })
                })
            })
        }





        //alert( $(this).prev()[0].value);

    })
})
$('.douban td:last input').after(douban_button);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址