豆瓣自动确认助手

在豆瓣电影、音乐和读书页面点击状态时自动确认

  1. // ==UserScript==
  2. // @name 豆瓣自动确认助手
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description 在豆瓣电影、音乐和读书页面点击状态时自动确认
  6. // @author [您的名字]
  7. // @match https://book.douban.com/subject/*
  8. // @match https://movie.douban.com/subject/*
  9. // @match https://music.douban.com/subject/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const buttonSelectors = {
  17. book: 'input[value="想读"], input[value="在读"], input[value="读过"]',
  18. movie: 'a.collect_btn[name^="pbtn-"], input[value="想看"], input[value="看过"]',
  19. music: 'a.collect_btn[name^="pbtn-"], input[value="想听"], input[value="在听"], input[value="听过"]'
  20. };
  21.  
  22. function addListeners(selectors) {
  23. document.querySelectorAll(selectors).forEach(button => {
  24. if (!button.dataset.listenerAdded) {
  25. button.addEventListener('click', handleStatusClick);
  26. button.dataset.listenerAdded = 'true';
  27. }
  28. });
  29. }
  30.  
  31. function handleStatusClick(event) {
  32. event.preventDefault();
  33. setTimeout(() => {
  34. const confirmButton = document.querySelector('input[value="确定"], button[type="submit"], .bn-flat input[type="submit"], .j.a_show_login');
  35. if (confirmButton) confirmButton.click();
  36. }, 500);
  37. }
  38.  
  39. function init() {
  40. const pageType = location.hostname.split('.')[0];
  41. if (buttonSelectors[pageType]) {
  42. addListeners(buttonSelectors[pageType]);
  43. new MutationObserver(() => addListeners(buttonSelectors[pageType]))
  44. .observe(document.body, { childList: true, subtree: true });
  45. }
  46. }
  47.  
  48. if (document.readyState === 'loading') {
  49. document.addEventListener('DOMContentLoaded', init);
  50. } else {
  51. init();
  52. }
  53. })();

QingJ © 2025

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