Bangumi简易修改收藏条目

在收藏页面点击“Edit”即可修改收藏条目的状态,评分,标签,评论等信息,可单项修改,随改随存。

  1. // ==UserScript==
  2. // @name Bangumi简易修改收藏条目
  3. // @namespace https://github.com/bangumi/scripts/tree/master/liaune
  4. // @author liaune
  5. // @license MIT
  6. // @description 在收藏页面点击“Edit”即可修改收藏条目的状态,评分,标签,评论等信息,可单项修改,随改随存。
  7. // @include /^https?://(bangumi\.tv|bgm\.tv|chii\.in)\/\S+\/list\/\S+\/(wish|collect|do|on_hold|dropped).*
  8. // @version 1.4
  9. // @grant GM_addStyle
  10. // ==/UserScript==
  11. GM_addStyle(`
  12. .input_tags{
  13. min-width: 200px;
  14. height: 20px;
  15. border: 1px solid;
  16. border-radius: 5px;
  17. margin: 5px 0;
  18. padding: 0 5px;
  19. }
  20. .select_rating{
  21. border-radius: 5px;
  22. }
  23. .select_interest{
  24. width: 50px;
  25. border-radius: 5px;
  26. }
  27. `);
  28. class BgmCollections {
  29. constructor() {
  30.  
  31. }
  32. init(){
  33. // $('#browserTools').append('<a id="saveCollect" class="chiiBtn" href="#">保存修改</a>');
  34. let securitycode = $('#badgeUserPanel a[href*="logout"]')[0].href.split('/logout/')[1].toString();
  35. let interest = this.get_interest();
  36. let itemsList = document.querySelectorAll('#browserItemList li.item');
  37. itemsList.forEach( (elem, i) =>{
  38. let subject_id = elem.querySelector('a.subjectCover').href.split('/subject/')[1];
  39. //评分
  40. let rating = elem.querySelector('.collectInfo .starlight')? elem.querySelector('.collectInfo .starlight').className.match(/stars(\d+)/)[1]:0;
  41. //标签
  42. let tags = '';
  43. let privacy = '';
  44. let elem_tips = elem.querySelectorAll('.collectInfo .tip');
  45. elem_tips.forEach((tip,i) =>{
  46. if(tip.textContent.match(/标签: (.*)/)){
  47. tags = tip.textContent.match(/标签: (.*)/)[1];
  48. $(tip).hide();
  49. }
  50. if(tip.textContent.match(/自己可见/)) privacy = 1;
  51. });
  52. //评论
  53. let comment = elem.querySelector('.text')? elem.querySelector('.text').textContent: '';
  54. let info = {
  55. securitycode: securitycode,
  56. subject_id: subject_id,
  57. interest: interest,
  58. rating: rating,
  59. tags: tags,
  60. comment: comment,
  61. privacy: privacy,
  62. };
  63. this.edit_interest(elem,info);
  64. this.edit_rating(elem,info);
  65. this.edit_tags(elem,info);
  66. this.edit_privacy(elem, info);
  67. this.edit_comment(elem,info);
  68. });
  69. }
  70. get_interest(){
  71. let status = location.href.match(/list\/\S+\/(wish|collect|do|on_hold|dropped)/)[1];
  72. const dc = {"wish":1,"collect":2,"do":3,"on_hold":4,"dropped":5};
  73. return dc[status];
  74. }
  75. edit_interest(elem,info){
  76. let select_interest = document.createElement('select');
  77. select_interest.classList.add("select_interest");
  78. let media = location.href.match(/^https?:\/\/(bgm\.tv|chii\.in|bangumi\.tv)\/(\S+)\/list\//)[2];
  79. const dc = {anime:'看',book:'读',music:'听',game:'玩',real:'看'};
  80. $(select_interest).append(`
  81. <option value="0">取消收藏</option>
  82. <option value="1">想${dc[media]}</option>
  83. <option value="2">${dc[media]}过</option>
  84. <option value="3">在${dc[media]}</option>
  85. <option value="4">搁置</option>
  86. <option value="5">抛弃</option>
  87. `);
  88. select_interest.value = info.interest;
  89. $(elem.querySelector('.inner h3')).append(select_interest);
  90. select_interest.addEventListener('change',function(){
  91. let data = {
  92. interest: select_interest.value,
  93. rating: info.rating,
  94. tags: info.tags,
  95. comment: info.comment,
  96. privacy: info.privacy,
  97. };
  98. if(data.interest == '0') $.post(`/subject/${info.subject_id}/remove?gh=${info.securitycode}`);
  99. else $.post(`/subject/${info.subject_id}/interest/update?gh=${info.securitycode}`, data);
  100.  
  101. });
  102. }
  103. edit_rating(elem,info){
  104. let select_rating = document.createElement('select');
  105. select_rating.classList.add("select_rating");;
  106. $(select_rating).append(`
  107. <option value="0"></option>
  108. <option value="1">1</option>
  109. <option value="2">2</option>
  110. <option value="3">3</option>
  111. <option value="4">4</option>
  112. <option value="5">5</option>
  113. <option value="6">6</option>
  114. <option value="7">7</option>
  115. <option value="8">8</option>
  116. <option value="9">9</option>
  117. <option value="10">10</option>
  118. `);
  119. select_rating.value = info.rating;
  120. $(elem.querySelector('.tip_j')).before(`<span> 评分:</span>`);
  121. $(elem.querySelector('.tip_j')).before(select_rating);
  122. select_rating.addEventListener('change',function(){
  123. let data = {
  124. interest: info.interest,
  125. rating: select_rating.value,
  126. tags: info.tags,
  127. comment: info.comment,
  128. privacy: info.privacy,
  129. };
  130. $.post(`/subject/${info.subject_id}/interest/update?gh=${info.securitycode}`, data);
  131. });
  132. }
  133. edit_tags(elem,info){
  134. let input_tags = document.createElement('input');input_tags.type='text';
  135. input_tags.classList.add("input_tags");
  136. input_tags.value = info.tags;
  137. $(elem.querySelector('.collectInfo')).after(input_tags);
  138. $(elem.querySelector('.collectInfo')).after(`<span> 标签: </span>`);
  139. input_tags.addEventListener('blur',function(){
  140. let data = {
  141. interest: info.interest,
  142. rating: info.rating,
  143. tags: input_tags.value.trim(),
  144. comment: info.comment,
  145. privacy: info.privacy,
  146. };
  147. $.post(`/subject/${info.subject_id}/interest/update?gh=${info.securitycode}`, data);
  148. });
  149. }
  150. edit_privacy(elem, info){
  151. let input_privacy = document.createElement('input'); input_privacy.type='checkbox';
  152. input_privacy.checked = info.privacy;
  153. input_privacy.title = '自己可见';
  154. $(elem.querySelector('.collectInfo')).append(input_privacy);
  155. input_privacy.addEventListener('change',function(){
  156. let data = {
  157. interest: info.interest,
  158. rating: info.rating,
  159. tags: info.tags,
  160. comment: info.comment,
  161. privacy: input_privacy.checked? 1: '',
  162. };
  163. $.post(`/subject/${info.subject_id}/interest/update?gh=${info.securitycode}`, data);
  164. });
  165. }
  166. edit_comment(elem,info){
  167. if(!info.comment)
  168. $(elem).find('.inner').append(`<div id="comment_box"><div class="item"><div style="float:none;" class="text_main_even"><div class="text"><br></div><div class="text_bottom"></div></div></div></div>`);
  169. let comment = $(elem).find('.text')[0];
  170. $(comment).attr('contenteditable', 'true');
  171. comment.addEventListener('blur',function(){
  172. let data = {
  173. interest: info.interest,
  174. rating: info.rating,
  175. tags: info.tags,
  176. comment: $(comment).text().trim(),
  177. privacy: info.privacy,
  178. };
  179. $.post(`/subject/${info.subject_id}/interest/update?gh=${info.securitycode}`, data);
  180. });
  181. }
  182. }
  183.  
  184. (function() {
  185. let You = $('#headerNeue2 .idBadgerNeue a.avatar')[0]? $('#headerNeue2 .idBadgerNeue a.avatar')[0].href.split('/user/')[1]:null;
  186. let User = location.href.match(/\/list\/(\S+)\//)? location.href.match(/\/list\/(\S+)\//)[1]: null;
  187. if(You != User) return;
  188. $('#browserTools').append(`<a id="modifyCollect" class="chiiBtn" href="javascript:;">Edit</a>`);
  189. $('#modifyCollect').on('click',()=>{
  190. $('#modifyCollect').remove();
  191. let bc = new BgmCollections();
  192. bc.init();
  193. });
  194. })();

QingJ © 2025

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