BvS Workshop: Select for Distillation

Select an item directly from the distillation list.

  1. // ==UserScript==
  2. // @name BvS Workshop: Select for Distillation
  3. // @namespace BvS
  4. // @description Select an item directly from the distillation list.
  5. // @include http://*animecubed.com/billy/bvs/workshop.html
  6. // @license http://wtfpl.org/
  7. // @version 1.0.1
  8. // @history 1.0.1 [Medin] Updated with license information
  9. // @history 1.0.0 [Medin] Initial version
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function(){
  14. "use strict";
  15. try {
  16. // auxiliary DOM-tree-constructor function
  17. var cE = function(name) {
  18. var elem = document.createElement(name);
  19. for (var i = 1; i < arguments.length; ++i)
  20. elem.appendChild(arguments[i]);
  21. return elem;
  22. }
  23.  
  24. // The distillation form.
  25. var form = document.forms.reduc;
  26. // The table as a whole.
  27. var dt = form.getElementsByClassName("stats2")[0];
  28. // The relevant rows. (No header, no footer, no locked items.)
  29. var rows = Array.prototype.slice.call(dt.getElementsByTagName("tr"), 2, -3)
  30. .filter(function(n) { return !n.textContent.match(/ \(Locked\)$/); });
  31. // The dropdown, numeric input field, and action-submission link.
  32. var selector = document.forms.reduc.elements.crackitem;
  33. var counter = document.forms.reduc.elements.amount;
  34. var submitLink = document.forms.reduc.getElementsByTagName("a")[0]
  35.  
  36. // The modifying action.
  37. rows.forEach(function(row, index) {
  38. var num = parseInt(row.children[0].textContent.trim())
  39. var name = row.children[1].textContent.trim();
  40.  
  41. if (selector[index].textContent != name) {
  42. throw ["Name mismatch", row, index, name];
  43. }
  44. var f = function() {
  45. selector.selectedIndex = index;
  46. counter.value = num;
  47. submitLink.focus();
  48. }
  49. // Create the tree-fragment.
  50. var span, Ldiv, Rdiv, link;
  51. span = cE("span",
  52. Ldiv = cE("div"),
  53. Rdiv = cE("div",
  54. link = cE("a")
  55. )
  56. );
  57. Ldiv.style.cssFloat = "left";
  58. Rdiv.style.cssFloat = "right";
  59. Rdiv.style.textAlign = "right";
  60. link.appendChild(document.createTextNode("Select"));
  61. link.href = "javascript:;";
  62. link.onclick = f;
  63.  
  64. // Splice in the constructed tree.
  65. var textTD = row.children[1];
  66. while (textTD.firstChild)
  67. Ldiv.appendChild(textTD.firstChild);
  68. textTD.appendChild(span);
  69. });
  70.  
  71. } catch (e) {
  72. // report and give up
  73. console.log(e);
  74. }
  75. })();