- // ==UserScript==
- // @name OB Onekey-Info-Generator
- // @namespace exhen32@live.com
- // @version 20180608
- // @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 posterAnchor = $('#mainpic img', doc);
- if (posterAnchor.attr('src')) {
- // 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);
- console.log(hdPosterAnchor.attr('href'))
- getBlob(hdPosterAnchor.attr('href'), dburl, function (blob) {
- console.log(blob);
- 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(/请在这里上传海报/, '[attach]' + attach_id + '[/attach]'));
- })
- })
- })
- })
- }
-
- var moive_info = '';
- moive_info = moive_info + '\n◎片 名 ' + title_cn.replace(/ \/ /g,'\n '+' ');
- moive_info=moive_info+'\n◎又 名 '+$('div.article #info', doc).contents().filter(function () {
- return (this.nodeType === 3) && ($(this).prev().text() == "又名:");
- }).text().trim().replace(/ \/ /g,'\n '+' ');
- moive_info = moive_info + '\n◎年 代 ' + $('#content > h1 > span.year', doc).text().substr(1, 4);
-
- moive_info = moive_info + '\n◎产 地 ' + $('div.article #info', doc).contents().filter(function () {
- return (this.nodeType === 3) && ($(this).prev().text() == "制片国家/地区:");
- }).text().trim();
- moive_info = moive_info + '\n◎类 别 ' + $('div.article #info span[property="v:genre"]', doc).text();
- moive_info = moive_info + '\n◎语 言 ' + $('div.article #info', doc).contents().filter(function () {
- return (this.nodeType === 3) && ($(this).prev().text() == "语言:");
- }).text().trim();
- moive_info = moive_info + '\n◎上映日期 ' + $('div.article #info [property="v:initialReleaseDate"]', doc).text();
- moive_info = moive_info + '\n◎豆瓣评分 ' + $('strong.rating_num.ll', doc).text() + '/10 from ' + $('.rating_douban a.rating_people').text();
- moive_info = moive_info + '\n◎豆瓣链接 ' + dburl;
- moive_info = moive_info + '\n◎片 长 ' + $('div.article #info', doc).contents().filter(function () {
- return ($(this).prev().attr('property') == "v:runtime") || ($(this).prev().text() == "片长:");
- }).text().trim();
- moive_info = moive_info + '\n◎导 演 ' + $('div.article #info span.attrs:first', doc).text().replace(/ \/ /g,'\n '+' ');
- moive_info = moive_info + '\n◎主 演 ' + $('div.article #info span.actor span.attrs', doc).contents().filter(function () {
- return $(this).attr("class") !== "more-actor";
- }).text().replace(/ \/ /g,'\n '+' ');
- moive_info = moive_info + '\n\n◎简 介\n' + $('div.article div.related-info [property="v:summary"]', doc).text().replace(/ \n/g, '').replace(/ /g, '');
-
- getDoc(imdburl, null, function (doc_imdb, res, meta) {
- var imdb_rating = $('span[itemprop=ratingValue]', doc_imdb).text();
- $('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 + '\n◎IMDb链接 ' + imdburl + '\n◎豆瓣评分'));
- })
-
-
-
- $('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val(`[quote]请在这里上传海报[/quote]\n[quote]${moive_info}[/quote]\n[quote]\n\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, '导演作品');
-
-
-
-
- //alert( $(this).prev()[0].value);
-
- })
- })
- $('.douban td:last input').after(douban_button);