BatchItemRelation

在条目页面上执行批量关联新条目关系操作

目前为 2024-03-23 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name BatchItemRelation
  3. // @name:zh-CN 批量关联新条目关系
  4. // @namespace https://github.com/Adachi-Git
  5. // @version 0.2
  6. // @description 在条目页面上执行批量关联新条目关系操作
  7. // @author Adachi
  8. // @match *://bgm.tv/subject/*
  9. // @match *://chii.in/subject/*
  10. // @match *://bangumi.tv/subject*
  11. // @match *://bgm.tv.tv/character/*
  12. // @match *://chii.in/character/*
  13. // @match *://bangumi.tv/character/*
  14. // @match *://bgm.tv/person/*
  15. // @match *://chii.in/person/*
  16. // @match *://bangumi.tv/person/*
  17. // @grant none
  18. // @license MIT
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. // 主入口
  23. function main() {
  24. if ($("#indexCatBox").length > 0) {
  25. addCustomIDInputs();
  26. addCustomIDExecutionButton();
  27. }
  28. }
  29.  
  30. // 添加ID输入框、职位列表、执行按钮
  31. function addCustomIDInputs() {
  32. $("#sbjSearchMod").after(`<div align="center">
  33. <input id="custom_ids" type="text" placeholder="输入带逗号分隔的ID" style="width: 200px;">
  34. <div id="relationListContainer"></div>
  35. <button id="idbtn_custom" class="btnCustom">执行</button>
  36. </div>`);
  37. }
  38.  
  39. // 添加自定义ID执行按钮的点击事件处理
  40. function addCustomIDExecutionButton() {
  41. if ($("#crtRelateSubjects .clearit select").length > 0) {
  42. infoprsn();
  43. }
  44. // 为执行按钮绑定点击事件
  45. $("#idbtn_custom").click(function() {
  46. // 获取用户输入的自定义ID,并执行相应操作
  47.  
  48. var customIds = $("#custom_ids").val().trim();
  49. if (customIds !== '') {
  50. var ids = customIds.split(',').map(function(item) {
  51. return parseInt(item.trim());
  52. });
  53. generateAndSelect(ids);
  54. }
  55. });
  56. }
  57.  
  58. // 生成并选择指定ID的条目
  59. function generateAndSelect(ids) {
  60. var chunk = ids.slice(0, 10);
  61. var arra = chunk.join(',');
  62. $("#subjectName").val('bgm_id=' + arra);
  63. $("#findSubject").click();
  64. $("#subjectList").one("DOMSubtreeModified", function() {
  65. if ($("#subjectList").length > 0) {
  66. setTimeout(function() {
  67. $("#subjectList .clearit p .avatar").click();
  68. var personType = $('#relationListContainer select').val();
  69.  
  70. $('#crtRelateSubjects li:not(.old.clearit)').slice(0, chunk.length).find('select').val(personType);
  71. setTimeout(function() {
  72. ids = ids.slice(10); // 剔除已经处理的前10个ID
  73. if (ids.length > 0) {
  74. generateAndSelect(ids);
  75. } else {
  76. $('#subjectList').hide(); // 生成完成后隐藏查询结果区域
  77. }
  78. }, 1000); // 等待一秒钟后执行下一组查询
  79. }, 1000); // 等待一秒钟后执行全选操作
  80. }
  81. });
  82. }
  83.  
  84.  
  85. // 获取关系列表
  86. function infoprsn() {
  87. var prsninfo = genPrsnStaffList(-1);
  88. if (prsninfo && prsninfo.trim() !== '') {
  89. $("#relationListContainer").html(prsninfo);
  90. console.log("通过 genPrsnStaffList 获取关系列表。");
  91. } else {
  92. var fallbackPrsninfo = $("#crtRelateSubjects").find(".clearit select").eq(0).clone(); // 选择第一个下拉列表并复制
  93. if (fallbackPrsninfo && fallbackPrsninfo.length > 0) {
  94. $("#relationListContainer").html(fallbackPrsninfo); // 将复制的下拉列表添加到 relationListContainer 中
  95. console.log("通过备选方法获取关系列表。");
  96. } else {
  97. // 如果没有找到备选方法获取关系列表,可以提供一个提示或者采取其他操作
  98. console.log("无法获取关系列表!");
  99. }
  100. }
  101. }
  102.  
  103.  
  104.  
  105. // 执行主函数
  106. main();
  107. })();