Greasy Fork 支持简体中文。

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. $("#idbtn_custom").click(function() {
  45. var customIds = $("#custom_ids").val().trim();
  46. if (customIds !== '') {
  47. var ids = customIds.split(',').map(function(item) {
  48. return parseInt(item.trim());
  49. });
  50. generateAndSelect(ids);
  51. }
  52. });
  53. }
  54.  
  55. // 生成并选择指定ID的条目
  56. function generateAndSelect(ids) {
  57. var chunk = ids.slice(0, 10);
  58. var arra = chunk.join(',');
  59. $("#subjectName").val('bgm_id=' + arra);
  60. $("#findSubject").click();
  61. $("#subjectList").one("DOMSubtreeModified", function() {
  62. if ($("#subjectList").length > 0) {
  63. setTimeout(function() {
  64. $("#subjectList .clearit p .avatar").click();
  65. var personType = $('#relationListContainer select').val();
  66.  
  67. $('#crtRelateSubjects li:not(.old.clearit)').slice(0, chunk.length).find('select').val(personType);
  68. setTimeout(function() {
  69. ids = ids.slice(10); // 剔除已经处理的前10个ID
  70. if (ids.length > 0) {
  71. generateAndSelect(ids);
  72. } else {
  73. $('#subjectList').hide(); // 生成完成后隐藏查询结果区域
  74. }
  75. }, 1000); // 等待一秒钟后执行下一组查询
  76. }, 1000); // 等待一秒钟后执行全选操作
  77. }
  78. });
  79. }
  80.  
  81.  
  82. // 获取关系列表
  83. function infoprsn() {
  84. var prsninfo = genPrsnStaffList(-1);
  85. if (prsninfo && prsninfo.trim() !== '') {
  86. $("#relationListContainer").html(prsninfo);
  87. console.log("通过 genPrsnStaffList 获取关系列表。");
  88. } else {
  89. var fallbackPrsninfo = $("#crtRelateSubjects .clearit select").eq(0).clone(); // 选择第一个下拉列表并复制
  90. if (fallbackPrsninfo && fallbackPrsninfo.length > 0) {
  91. $("#relationListContainer").html(fallbackPrsninfo); // 将复制的下拉列表添加到 relationListContainer 中
  92. console.log("通过备选方法获取关系列表。");
  93. } else {
  94. // 如果没有找到备选方法获取关系列表,可以提供一个提示或者采取其他操作
  95. console.log("无法获取关系列表!");
  96. }
  97. }
  98. }
  99.  
  100.  
  101.  
  102. // 执行主函数
  103. main();
  104. })();