AO3 Random Nice Comments

Want to leave more kudos? Leave a random nice comment with the click of a button

目前为 2022-08-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name AO3 Random Nice Comments
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @license MIT
  6. // @description Want to leave more kudos? Leave a random nice comment with the click of a button
  7. // @match *://*.archiveofourown.org/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. let anonName = 'Anon';
  12. let anonEmail = 'askd.noreply@noreply.com';
  13.  
  14. function niceComment() {
  15. let niceComments = [
  16. 'Kudos! ♥',
  17. 'I loved this!',
  18. 'This was great ♥',
  19. '♥ ♥ ♥',
  20. '<3 <3 <3',
  21. 'This is great ♥',
  22. 'Loved this <3',
  23. 'Thank you for sharing this ♥',
  24. 'Kudos ♥'
  25. ]
  26.  
  27. let n = Math.floor(Math.random() * niceComments.length)
  28. return niceComments[n]
  29. }
  30.  
  31. function getInputsByValue(value) {
  32. // kudos button has a universal id but the comment button id is unique to the work
  33. var allInputs = document.getElementsByTagName("input");
  34. var results = [];
  35. for(var x=0;x<allInputs.length;x++) {
  36. if(allInputs[x].value == value) {
  37. results.push(allInputs[x]);
  38. }
  39. }
  40. return results;
  41. }
  42.  
  43. (function() {
  44. 'use strict';
  45.  
  46. if (!getInputsByValue('Comment').length || !getInputsByValue('Kudos ♥').length) {
  47. return null;
  48. }
  49.  
  50. var submitButton = getInputsByValue('Comment')[0]
  51. var kudosButton = getInputsByValue('Kudos ♥')[0]
  52. var workID = submitButton.id.split('_')[3]
  53.  
  54. const extraKudosButton = document.createElement("button")
  55. extraKudosButton.textContent = 'Comment Kudos ♥'
  56. extraKudosButton.onclick = function() {
  57. if (document.querySelectorAll('#comment_name_for_' + workID).length) {
  58. document.querySelector('#comment_name_for_' + workID).value = anonName;
  59. document.querySelector('#comment_email_for_' + workID).value = anonEmail;
  60. }
  61.  
  62. document.querySelector('#comment_content_for_' + workID).value = niceComment();
  63. submitButton.click();
  64. extraKudosButton.remove(); // prevent extra clicks
  65. }
  66.  
  67. kudosButton.parentNode.parentNode.insertBefore(extraKudosButton,kudosButton.parentNode)
  68.  
  69. })();