Password-Be-Gone

Bypasses the need to enter the password for every single chapter

  1. // ==UserScript==
  2. // @name Password-Be-Gone
  3. // @version 3
  4. // @grant none
  5. // @namespace https://dueldu.neocities.org/
  6. // @license MIT
  7. // @include https://chrysanthemumgarden.com/*
  8. // @description Bypasses the need to enter the password for every single chapter
  9. // ==/UserScript==
  10. /**
  11. * This is what the password submit button does once clicked. It gets the two
  12. * important information fields. The one with the input password and the one
  13. * with the “nonce” (number used once). These two information are necessary to
  14. * be able to open the novel site.
  15. */
  16. function storePassword(event) {
  17. let password = document.getElementById("site-pass").value;
  18. let nonce = event.target.children["nonce-site-pass"].value;
  19. window.sessionStorage.setItem("password", password);
  20. window.sessionStorage.setItem("nonce", nonce);
  21. }
  22.  
  23. /**
  24. * This is what the next and previous buttons do now.
  25. * They no longer link to the page but instead submit our password to their
  26. * link instead.
  27. */
  28. function formSubmit(event) {
  29. // Do not let the link change the page
  30. event.preventDefault();
  31. // Instead, change the page via a form submit
  32. // To do that, we need the password and nonce
  33. const password = window.sessionStorage.getItem("password");
  34. const nonce = window.sessionStorage.getItem("nonce");
  35. // Create the form to submit
  36. let passwordField = document.createElement("input");
  37. passwordField.type = "hidden";
  38. passwordField.name = "site-pass";
  39. passwordField.value = password;
  40. let nonceField = document.createElement("input");
  41. nonceField.type = "hidden";
  42. nonceField.name = "nonce-site-pass";
  43. nonceField.value = nonce;
  44. let form = document.createElement("form");
  45. form.method = "POST";
  46. form.enctype = "multipart/form-data";
  47. // Now let's find out where our button was headed…
  48. const link = event.currentTarget.href;
  49. form.action = link;
  50. // And now let's put it all together
  51. form.append(passwordField);
  52. form.append(nonceField);
  53. document.body.append(form);
  54. // And now finally send over the data
  55. form.submit();
  56. }
  57.  
  58. function main() {
  59. let passwordLock = document.getElementById("password-lock");
  60. // Is there a password-lock element?
  61. if(passwordLock) {
  62. // Add my own text to let the user know it worked.
  63. let msg = document.createElement("b");
  64. msg.innerText = "Password-Be-Gone has successfully activated! It will remember\
  65. the password you type in here.";
  66. passwordLock.previousSibling.append(msg);
  67. document.getElementsByClassName("button")[0].style.backgroundColor="#5a4fe8";
  68. // Change what the “SUBMIT PASSWORD” button does
  69. passwordLock.onsubmit = storePassword;
  70. // And enter in the already stored password, because why not?
  71. document.getElementById("site-pass").value = window.sessionStorage.getItem("password");
  72. }
  73. // We just assume if it's not password-locked, it's a novel
  74. else {
  75. // Leave a message so our user knows it's working
  76. let msg = document.createElement("h2");
  77. msg.innerText = "Password-Be-Gone working as intended"
  78. document.getElementById("main").prepend(msg);
  79. // Look for all our “next” and “previous” buttons…
  80. let nextButtons = document.getElementsByClassName("nav-next");
  81. let prevButtons = document.getElementsByClassName("nav-previous");
  82. // … and change what they do, when clicked
  83. // By iterating through them. The Array.from is JavaScript madness
  84. Array.from(nextButtons).forEach( (button) => {
  85. button.onclick = formSubmit;
  86. });
  87. Array.from(prevButtons).forEach( (button) => {
  88. button.onclick = formSubmit;
  89. });
  90. }
  91. }
  92.  
  93. main();