Advertisement
jcunews

acikerisim.uludag.edu.tr-auto-form-submitter.user.js

Oct 8th, 2023 (edited)
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        acikerisim.uludag.edu.tr auto form submitter
  3. // @namespace   https://greasyfork.org/en/users/85671-jcunews
  4. // @version     1.0.2
  5. // @license     AGPL v3
  6. // @author      jcunews
  7. // @description Context: https://old.reddit.com/r/learnprogramming/comments/170eoq2/help_autofill_a_webpage/
  8. // @match       https://acikerisim.uludag.edu.tr/*
  9. // @grant       none
  10. // ==/UserScript==
  11.  
  12. setTimeout((textboxes, lastTextbox, btnAdd, btnAuto, list, i) => {
  13.   localStorage.removeItem("autolist");
  14.   textboxes = document.querySelectorAll('#edit_metadata input[name^="dc_subject_emtree_"]');
  15.   if (!textboxes.length) sessionStorage.removeItem("autolist");
  16.   if (sessionStorage.autolist) {
  17.     list = JSON.parse(sessionStorage.autolist);
  18.     if (list.toUpperCase) list = JSON.parse(list);
  19.     if (!Array.isArray(list)) {
  20.       list = null;
  21.       sessionStorage.removeItem("autolist")
  22.     }
  23.   }
  24.   lastTextbox = textboxes[textboxes.length - 1];
  25.   btnAdd = document.querySelector('#edit_metadata button[name="submit_dc_subject_emtree_add"]');
  26.   if (list) {
  27.     if (btnAuto = lastTextbox || btnAdd) {
  28.       btnAuto.scrollIntoView();
  29.       scrollBy(0, -innerHeight / 2)
  30.     }
  31.     if (list.length) {
  32.       if (lastTextbox && !lastTextbox.value && btnAdd) {
  33.         lastTextbox.value = list.shift();
  34.         sessionStorage.setItem("autolist", JSON.stringify(list));
  35.         btnAdd.click()
  36.       } else {
  37.         alert(`Below ${list.length} text input(s) still remains, but there's no more textbox to input to.\n\n${list.join("\n")}`);
  38.        sessionStorage.removeItem("autolist")
  39.      }
  40.    } else {
  41.      sessionStorage.removeItem("autolist");
  42.      alert("Finished automating text input(s)")
  43.    }
  44.  } else if (textboxes.length && btnAdd) {
  45.    btnAdd.previousElementSibling.style.display = "flex";
  46.    btnAdd.previousElementSibling.appendChild(btnAuto = document.createElement("BUTTON")).textContent = "Auto";
  47.    btnAuto.title = "Automate submission of this type of form field";
  48.    btnAuto.className = "btn btn-default";
  49.    btnAuto.style.cssText = 'margin-left:1em; padding:0 .8em';
  50.    btnAuto.onclick = function(ev, text) {
  51.      ev.preventDefault();
  52.      if (text = lastTextbox.value.trim()) {
  53.        list = text.split(/\s*\.\s*/);
  54.        for (i = list.length - 1; i >= 0; i--) {
  55.          if (!list[i]) list.splice(i, 1)
  56.        }
  57.        if (confirm(`Automate ${list.length} text input submission(s)?\nUp to 10 of them are shown below.\n\n${list.slice(0, 10).join("\n")}`)) {
  58.          lastTextbox.value = list.shift();
  59.          sessionStorage.setItem("autolist", JSON.stringify(list));
  60.          btnAdd.click()
  61.        }
  62.      } else {
  63.        alert(`\
  64. No text input to automate.
  65. Text inputs must be separated with period/dot character (".").
  66. Blank text input entries will be removed.
  67. For example:
  68.  
  69. input 1. input 2, with comma. input 3`)
  70.      }
  71.    };
  72.  }
  73. }, 200)
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement