LibraryThing make author combining easier

This script moves the "Improve this author" box to the top, always shows "(never)" links, always shows the search box, prepopulates it with the author name, etc.

当前为 2015-07-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name LibraryThing make author combining easier
  3. // @namespace https://greasyfork.org/en/users/11592-max-starkenburg
  4. // @description This script moves the "Improve this author" box to the top, always shows "(never)" links, always shows the search box, prepopulates it with the author name, etc.
  5. // @include http*://*librarything.tld/author/*
  6. // @include http*://*librarything.com/author/*
  7. // @version 2
  8. // ==/UserScript==
  9.  
  10. // Set up some stuff here that's used in multiple features (in case users want to delete/comment some features)
  11. var improveAuthBox = getImproveAuth();
  12. function getImproveAuth(){
  13. el = document.getElementById("searchcombine"); // a unique ID within the box we want
  14. if (el) {
  15. while (el = el.parentNode) {
  16. if ((" " + el.className + " ").indexOf(" greenbox ") > -1) { // the class of the top element we want
  17. return el;
  18. }
  19. }
  20. }
  21. return null;
  22. }
  23. var searchInput = document.getElementsByName("searchbox")[0];
  24. var searchDiv = document.getElementById("searchcombine");
  25. var nevers = document.getElementsByClassName("nevercombinelink");
  26. var combineWith = document.getElementById("combinewith");
  27. // Don't remove any of the above code. If you want to delete or comment sections, start from here on down.
  28.  
  29.  
  30. // Make the "Impove this author" the top box at right
  31. var rightCol = document.getElementsByClassName("cColumn")[0];
  32. if (rightCol && improveAuthBox) rightCol.insertBefore(improveAuthBox, rightCol.firstChild);
  33.  
  34.  
  35. // Instead of the Header "Combine/separate works" followed by a link of the author's name, remove the header
  36. // and replace the link with the "Combine/separate works" text.
  37. if (improveAuthBox) {
  38. var combSep = improveAuthBox.getElementsByTagName("h3")[0];
  39. var combSepLink = combSep.nextSibling.getElementsByTagName("a");
  40. if (combSepLink.length == 1) { // Skips this feature if it's disambiguated page, which has two links
  41. combSepLink[0].textContent = combSep.textContent;
  42. combSep.style.display = "none";
  43. }
  44. }
  45.  
  46.  
  47. // Always have the "Search for the author" input box showing instead of having to click "Search" each time
  48. if (searchDiv) searchDiv.style.display = "block";
  49. // in which case we don't really need that "Search" link anymore
  50. if (combineWith) {
  51. var combineLinks = combineWith.getElementsByTagName("li");
  52. combineLinks[combineLinks.length - 1].style.display = "none";
  53. }
  54. // Always show the "(never combine)" links (especially because the above code hides the "Never?" link)
  55. for (i=0; i<nevers.length; i++) nevers[i].style.display = "inline";
  56.  
  57.  
  58. // If we're in English, shorten "never combine" to "never" so that that we don't have so much wrapping
  59. if (nevers.length && nevers[0].textContent.indexOf("never combine") > -1) {
  60. for (i=0; i<nevers.length; i++) {
  61. nevers[i].getElementsByTagName("a")[0].textContent = "never";
  62. }
  63. }
  64.  
  65.  
  66. // Right-align the "never" links to get through them more quickly while lowering the risk of clicking "combine"
  67. for (i=0; i<nevers.length; i++) {
  68. par = nevers[i].parentNode;
  69. par.insertBefore(nevers[i], par.firstChild);
  70. nevers[i].style.cssFloat = "right";
  71. nevers[i].style.marginLeft = "10px"; // I think this is necessary in certain cases dues to some textIndent business
  72. }
  73.  
  74.  
  75. // Don't limit the search box to just 30 characters
  76. if (searchInput) searchInput.removeAttribute("maxlength");
  77.  
  78.  
  79. // Prepopulate the search box with the displayed author name
  80. var authNameInVal = document.getElementsByName("combinewithfullname")[0]; // better than h1, which might have dates or disambiguation stuff
  81. if (searchInput && authNameInVal) searchInput.setAttribute("value",authNameInVal.value); // .value here since certain pages error if authNameInVal not found
  82.  
  83.  
  84. // Don't show combining options on disambiguated pages, as a reminder not to combine from there
  85. var authorString = document.URL.match(/.*\/author\/\w*(-\d*)?(?:$|.*)/); // captures a disambiguation number if it exists
  86. if (authorString[1] != undefined) { // testing if on a split page (i.e. if there was a disambiguation number in the URL)
  87. // Hide the search input
  88. if (searchDiv) searchDiv.style.display = "none";
  89. // Hide the "Combine with ..." section
  90. if (combineWith) {
  91. combineWith.previousSibling.style.display = "none";
  92. combineWith.style.display = "none";
  93. }
  94. }