LibraryThing add ten authors at a time

A shortcut for adding multiple "Other authors" inputs at once

  1. // ==UserScript==
  2. // @name LibraryThing add ten authors at a time
  3. // @description A shortcut for adding multiple "Other authors" inputs at once
  4. // @namespace https://greasyfork.org/en/users/11592-max-starkenburg
  5. // @include http*://*librarything.tld/work/*edit/*
  6. // @include http*://*librarything.com/work/*edit/*
  7. // @include http*://*librarything.tld/addnew.php*
  8. // @include http*://*librarything.com/addnew.php*
  9. // @version 2
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // Find the "add another author" link and put a "add another 10 authors" link next to it
  14. var addAnotherAuthor = document.evaluate(
  15. '//div[@id="addPersonControl"]//a',
  16. document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  17. if (addAnotherAuthor.snapshotLength > 0) {
  18. addAnotherAuthor = addAnotherAuthor.snapshotItem(0);
  19. addTenAuthors = document.createElement('span');
  20. addTenAuthors.innerHTML = ' | <a href="javascript:addTenPersons();">add another 10 authors</a>'
  21. var par = addAnotherAuthor.parentNode;
  22. par.insertBefore(addTenAuthors, addAnotherAuthor.nextSibling);
  23. }
  24.  
  25. // Append to the document body the function that repeats addPerson() 10 times
  26. var body = document.getElementsByTagName("body")[0];
  27. var script = document.createElement("script");
  28. script.type = "text/javascript";
  29. script.innerHTML = '\
  30. function addTenPersons() {\
  31. for (var i=0; i<10; i++) {\
  32. addPerson();\
  33. }\
  34. }\
  35. ';
  36. body.appendChild(script);