OB Onekey-Info-Generator

Ourbits 一键获取信息

目前为 2018-06-08 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name OB Onekey-Info-Generator
  3. // @namespace exhen32@live.com
  4. // @version 20180608
  5. // @description Ourbits 一键获取信息
  6. // @author Exhen
  7. // @match https://ourbits.club/upload.php*
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_setClipboard
  10. // @icon https://ourbits.club/favicon.ico
  11. // @grant GM_addStyle
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @grant GM_download
  15. // @require http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js
  16. // @require https://cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js
  17. // @connect *
  18. // ==/UserScript==
  19.  
  20. var getDoc = function (url, meta, callback) {
  21. GM_xmlhttpRequest({
  22. method: 'GET',
  23. url: url,
  24. headers: {
  25. 'User-agent': window.navigator.userAgent,
  26. 'Content-type': null
  27. },
  28. onload: function (responseDetail) {
  29. var doc;
  30. doc = '';
  31. if (responseDetail.status == 200) {
  32. doc = (new DOMParser).parseFromString(responseDetail.responseText, 'text/html');
  33. if (doc == undefined) {
  34. doc = document.implementation.createHTMLDocument('');
  35. doc.querySelector('html').innerHTML = responseText;
  36. }
  37. }
  38. callback(doc, responseDetail, meta);
  39. }
  40. });
  41. };
  42.  
  43.  
  44. var getBlob = function (url, referer, callback) {
  45. GM_xmlhttpRequest({
  46. method: 'GET',
  47. url,
  48. headers: {
  49. 'User-agent': window.navigator.userAgent,
  50. 'Content-type': null,
  51. 'referer':referer
  52. },
  53. responseType: 'blob',
  54. onload: function (responseDetail) {
  55. if (responseDetail.status >= 200 && responseDetail.status < 300) {
  56. callback(responseDetail.response);
  57. }
  58. }
  59. })
  60. }
  61. var postAttach = function (blob, filename, callback) {
  62. let xhr = new XMLHttpRequest();
  63. let formData = new FormData();
  64. formData.append('file', blob, filename);
  65. xhr.open('POST', '/attachment.php');
  66. xhr.send(formData);
  67. xhr.onreadystatechange = function () {
  68. if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
  69. let match = xhr.responseText.match(/(?<=\[attach\]).*(?=\[\/attach\])/);
  70. if (match) callback(match);
  71. }
  72. };
  73. }
  74.  
  75. $('form#compose td').filter(function () { return $(this).text() == '豆瓣链接' }).parent().addClass('douban');
  76. var douban_button = $('<input type="button" class="douban_button" value="一键填写">');
  77. douban_button.click(function () {
  78. var dburl = $(this).prev()[0].value;
  79. getDoc(dburl, null, function (doc, res, meta) {
  80. var douban_id = dburl.split('/')[4];
  81. var title_cn = $('#content > h1 > span', doc)[0].textContent.split(' ').shift();
  82. var director = $('div.article #info span.attrs:first', doc).text();
  83. var imdburl = $('div#info a[href^=\'http://www.imdb.com/title/tt\']', doc).attr('href');
  84.  
  85.  
  86. var posterAnchor = $('#mainpic img', doc);
  87. if (posterAnchor.attr('src')) {
  88. // get the posters page's URL via movie.douban.com's customs
  89. var postersUrl = 'https://movie.douban.com/subject/' + douban_id + '/photos?type=R';
  90. getDoc(postersUrl, null, function (doc1, res, meta) {
  91. var aPosterUrl = $('.article > ul > li:nth-child(1) > div.cover > a', doc1).attr('href');
  92. getDoc(aPosterUrl, null, function (doc2, res, meta) {
  93. var hdPosterAnchor = $('span.magnifier > a', doc2);
  94. console.log(hdPosterAnchor.attr('href'))
  95. getBlob(hdPosterAnchor.attr('href'), dburl, function (blob) {
  96. console.log(blob);
  97. postAttach(blob, hdPosterAnchor.attr('href').split('/')[7], function (attach_id) {
  98. $('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]'));
  99. })
  100. })
  101. })
  102. })
  103. }
  104.  
  105. var moive_info = '';
  106. moive_info = moive_info + '\n◎片  名 ' + title_cn.replace(/ \/ /g,'\n     '+' ');
  107. moive_info=moive_info+'\n◎又  名 '+$('div.article #info', doc).contents().filter(function () {
  108. return (this.nodeType === 3) && ($(this).prev().text() == "又名:");
  109. }).text().trim().replace(/ \/ /g,'\n     '+' ');
  110. moive_info = moive_info + '\n◎年  代 ' + $('#content > h1 > span.year', doc).text().substr(1, 4);
  111.  
  112. moive_info = moive_info + '\n◎产  地 ' + $('div.article #info', doc).contents().filter(function () {
  113. return (this.nodeType === 3) && ($(this).prev().text() == "制片国家/地区:");
  114. }).text().trim();
  115. moive_info = moive_info + '\n◎类  别 ' + $('div.article #info span[property="v:genre"]', doc).text();
  116. moive_info = moive_info + '\n◎语  言 ' + $('div.article #info', doc).contents().filter(function () {
  117. return (this.nodeType === 3) && ($(this).prev().text() == "语言:");
  118. }).text().trim();
  119. moive_info = moive_info + '\n◎上映日期 ' + $('div.article #info [property="v:initialReleaseDate"]', doc).text();
  120. moive_info = moive_info + '\n◎豆瓣评分 ' + $('strong.rating_num.ll', doc).text() + '/10 from ' + $('.rating_douban a.rating_people').text();
  121. moive_info = moive_info + '\n◎豆瓣链接 ' + dburl;
  122. moive_info = moive_info + '\n◎片  长 ' + $('div.article #info', doc).contents().filter(function () {
  123. return ($(this).prev().attr('property') == "v:runtime") || ($(this).prev().text() == "片长:");
  124. }).text().trim();
  125. moive_info = moive_info + '\n◎导  演 ' + $('div.article #info span.attrs:first', doc).text().replace(/ \/ /g,'\n     '+' ');
  126. moive_info = moive_info + '\n◎主  演 ' + $('div.article #info span.actor span.attrs', doc).contents().filter(function () {
  127. return $(this).attr("class") !== "more-actor";
  128. }).text().replace(/ \/ /g,'\n     '+' ');
  129. moive_info = moive_info + '\n\n◎简  介\n' + $('div.article div.related-info [property="v:summary"]', doc).text().replace(/ \n/g, '').replace(/ /g, '');
  130.  
  131. getDoc(imdburl, null, function (doc_imdb, res, meta) {
  132. var imdb_rating = $('span[itemprop=ratingValue]', doc_imdb).text();
  133. $('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◎豆瓣评分'));
  134. })
  135.  
  136.  
  137.  
  138. $('form#compose td').filter(function () { return $(this).text() == '简介*' }).parent().find('textarea').val(`[quote]请在这里上传海报[/quote]\n[quote]${moive_info}[/quote]\n[quote]\n\n[/quote]`);
  139.  
  140. $('form#compose td').filter(function () { return $(this).text() == 'IMDb链接' }).parent().find('input')[0].value = imdburl;
  141. $('form#compose td').filter(function () { return $(this).text() == '副标题' }).parent().find('input')[0].value = title_cn + ' ' + director + '导演作品';
  142. console.log(title_cn, ' ', director, '导演作品');
  143.  
  144.  
  145.  
  146.  
  147. //alert( $(this).prev()[0].value);
  148.  
  149. })
  150. })
  151. $('.douban td:last input').after(douban_button);

QingJ © 2025

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