BvS Workshop: Select for Distillation

Select an item directly from the distillation list.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        BvS Workshop: Select for Distillation
// @namespace   BvS
// @description Select an item directly from the distillation list.
// @include     http://*animecubed.com/billy/bvs/workshop.html
// @license     http://wtfpl.org/
// @version     1.0.1
// @history     1.0.1 [Medin] Updated with license information
// @history     1.0.0 [Medin] Initial version
// @grant       none
// ==/UserScript==

(function(){
  "use strict";
  try {
    // auxiliary DOM-tree-constructor function
    var cE = function(name) {
      var elem = document.createElement(name);
      for (var i = 1; i < arguments.length; ++i)
        elem.appendChild(arguments[i]);
      return elem;
    }

    // The distillation form.
    var form = document.forms.reduc;
    
    // The table as a whole.
    var dt = form.getElementsByClassName("stats2")[0];
    
    // The relevant rows. (No header, no footer, no locked items.)
    var rows = Array.prototype.slice.call(dt.getElementsByTagName("tr"), 2, -3)
         .filter(function(n) { return !n.textContent.match(/ \(Locked\)$/); });
    
    // The dropdown, numeric input field, and action-submission link.
    var selector = document.forms.reduc.elements.crackitem;
    var counter = document.forms.reduc.elements.amount;
    var submitLink = document.forms.reduc.getElementsByTagName("a")[0]

    // The modifying action.
    rows.forEach(function(row, index) {
      var num = parseInt(row.children[0].textContent.trim())
      var name = row.children[1].textContent.trim();

      if (selector[index].textContent != name) {
        throw ["Name mismatch", row, index, name];
      }
      var f = function() {
        selector.selectedIndex = index;
        counter.value = num;
        submitLink.focus();
      }
      
      // Create the tree-fragment.
      var span, Ldiv, Rdiv, link;
      span = cE("span",
                Ldiv = cE("div"),
                Rdiv = cE("div",
                          link = cE("a")
                          )
                );
      Ldiv.style.cssFloat = "left";
      Rdiv.style.cssFloat = "right";
      Rdiv.style.textAlign = "right";
      link.appendChild(document.createTextNode("Select"));
      link.href = "javascript:;";
      link.onclick = f;

      // Splice in the constructed tree.
      var textTD = row.children[1];
      while (textTD.firstChild)
        Ldiv.appendChild(textTD.firstChild);
      textTD.appendChild(span);
    });

  } catch (e) {
    // report and give up
    console.log(e);
  }
})();