Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name acikerisim.uludag.edu.tr auto form submitter
- // @namespace https://greasyfork.org/en/users/85671-jcunews
- // @version 1.0.2
- // @license AGPL v3
- // @author jcunews
- // @description Context: https://old.reddit.com/r/learnprogramming/comments/170eoq2/help_autofill_a_webpage/
- // @match https://acikerisim.uludag.edu.tr/*
- // @grant none
- // ==/UserScript==
- setTimeout((textboxes, lastTextbox, btnAdd, btnAuto, list, i) => {
- localStorage.removeItem("autolist");
- textboxes = document.querySelectorAll('#edit_metadata input[name^="dc_subject_emtree_"]');
- if (!textboxes.length) sessionStorage.removeItem("autolist");
- if (sessionStorage.autolist) {
- list = JSON.parse(sessionStorage.autolist);
- if (list.toUpperCase) list = JSON.parse(list);
- if (!Array.isArray(list)) {
- list = null;
- sessionStorage.removeItem("autolist")
- }
- }
- lastTextbox = textboxes[textboxes.length - 1];
- btnAdd = document.querySelector('#edit_metadata button[name="submit_dc_subject_emtree_add"]');
- if (list) {
- if (btnAuto = lastTextbox || btnAdd) {
- btnAuto.scrollIntoView();
- scrollBy(0, -innerHeight / 2)
- }
- if (list.length) {
- if (lastTextbox && !lastTextbox.value && btnAdd) {
- lastTextbox.value = list.shift();
- sessionStorage.setItem("autolist", JSON.stringify(list));
- btnAdd.click()
- } else {
- alert(`Below ${list.length} text input(s) still remains, but there's no more textbox to input to.\n\n${list.join("\n")}`);
- sessionStorage.removeItem("autolist")
- }
- } else {
- sessionStorage.removeItem("autolist");
- alert("Finished automating text input(s)")
- }
- } else if (textboxes.length && btnAdd) {
- btnAdd.previousElementSibling.style.display = "flex";
- btnAdd.previousElementSibling.appendChild(btnAuto = document.createElement("BUTTON")).textContent = "Auto";
- btnAuto.title = "Automate submission of this type of form field";
- btnAuto.className = "btn btn-default";
- btnAuto.style.cssText = 'margin-left:1em; padding:0 .8em';
- btnAuto.onclick = function(ev, text) {
- ev.preventDefault();
- if (text = lastTextbox.value.trim()) {
- list = text.split(/\s*\.\s*/);
- for (i = list.length - 1; i >= 0; i--) {
- if (!list[i]) list.splice(i, 1)
- }
- 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")}`)) {
- lastTextbox.value = list.shift();
- sessionStorage.setItem("autolist", JSON.stringify(list));
- btnAdd.click()
- }
- } else {
- alert(`\
- No text input to automate.
- Text inputs must be separated with period/dot character (".").
- Blank text input entries will be removed.
- For example:
- input 1. input 2, with comma. input 3`)
- }
- };
- }
- }, 200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement