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 getInputsByValue(value) {
  15. // kudos button has a universal id but the comment button id is unique to the work
  16. var allInputs = document.getElementsByTagName("input");
  17. var results = [];
  18. for(var x=0;x<allInputs.length;x++) {
  19. if(allInputs[x].value == value) {
  20. results.push(allInputs[x]);
  21. }
  22. }
  23. return results;
  24. }
  25.  
  26. function niceComment() {
  27. let niceComments = [
  28. 'Kudos! ♥',
  29. 'I loved this!',
  30. 'This was great ♥',
  31. '♥ ♥ ♥',
  32. '<3 <3 <3',
  33. 'This is great ♥',
  34. 'Loved this <3',
  35. 'Thank you for sharing this ♥',
  36. 'Kudos ♥'
  37. ]
  38.  
  39. let n = Math.floor(Math.random() * niceComments.length)
  40. return niceComments[n]
  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. })();