阿里云云效增强

阿里云云效辅助脚本

// ==UserScript==
// @name         阿里云云效增强
// @namespace    http://bmqy.net/
// @version      1.1.0
// @author       bmqy
// @description  阿里云云效辅助脚本
// @license      ISC
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFgAAABYCAYAAABxlTA0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAANE0lEQVR42u2dWYwcx3nHf1XVPccOd3nu8hhS4h0qJqVQoihLsnjqtC0TdCzEMKIHS1aAPDhBAkNBkERwoiSI4wcjERIrcvTgBNKDrwQiaPmSqWNBypJI2SRtUqZEkyKX3F3t8thjdma6jjxUD3dIk9xZcnp2xcwfaGBmtru3+9c1X33fV1/VCOeco0pv9hqeOxSxs8dQ0g4haOoycg5aAsGmvOKzy1KsmiHP+7uoAD46ZHl8V4kXfhNRNDTBjkMOwMKUlOCzS0P+4bY0HVkPUDjn3JFBywPbCxzss4gAZBPuFck6cBpuzyu2PdDCzIxAagt/trPIwT6DCptwr0ZSgAphV5fmr98o+c86uzXbj2hk0CRbL4lA8PyhMr8+Y5HP/KpMZJs2t56SAgZKsP39CLn/lG3CTUICdvdaZNPmJicpQF79aZq6nJqAE1YTcMJqAk5YTcAJqwk4YTUBJ6wm4IQVTPQF1CLr4pRglQQ+vJ/scdKkA2wdOIsnKj3EtpSgNfR/d/FWiGAocujKvoCQky8bOCkAOwfW+tfTs4JVMxU3z5LcOENxfatgSihIKYE2jrKFyMJA2XKmDEcHLb8+a3nnjOXds5ZTJd/cpZgcCawJBWwdOAPpEO7KBzy0JGD9PEU+J2kJBNo5ygaKBkrWUdYiBuxoS0lmW1jcJlg3VzEUQXfB8sszlp3dhn39huHIQ57IVj0hgB1gDbSEgs8sD3hkRYrbZisyylGyoA0UtCOyULZQjltu2Xi4ZRN/Hr+OYuitKcHadsWNMxRHBi2d3YY3egwDZYeUE2O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rcR7Tg84PhJl+Z770Xs6jFEBqSaOLgwwSueVEqbHLDnA8OeHs2XU4JlbZLV7YpVMyQ3TPf+cC44vyxrWDt6RxwHTlv2nTK83Wc5eMYwUvInnmiwFU2KNXsEcXmTFEQW9p+y7O8z5xxkKfmtiYTD1QsixY6zFDS0A6tFk+xyzoddkcOH3uftJ6iaxD15x/0nHeCLqTJV68Oo5sp/CasJOGE1ASesJuCE1QScsJqAE1YTcMJqAk5Y8lqvMJ9IWQdy5YxkKlr+38vBLR0S+Ue/64vgmpDrJ+ugLQ2fuC5EfmxOwCcXBtjxz/5v6hJy2vHw8hTLp0lkIOFf7sywsl1i9LU/6ydJWQcmgrsXhvzdWl9Ge+5HU48NWR5/vcT/Ho4oavwC9RN9xR8SVf9o6h8u9z+aWik3EBf72d/vvBfxWrdhOLq2p1jVQy5eRnLjvIBPLwm58YKf/f0/gbPkpDsGqJoAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjAtMTAtMThUMTc6NTA6NDArMDg6MDBNm2TBAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIwLTEwLTE4VDE3OjUwOjQwKzA4OjAwPMbcfQAAAABJRU5ErkJggg==
// @match        https://packages.aliyun.com/*
// @match        https://signin.aliyun.com/*/login*
// @match        https://signin.aliyun.com/login*
// @grant        GM_deleteValue
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function () {
  'use strict';

  (function() {
    const app = {
      currentPackage: null,
      init: function() {
        this.onAddElementEventDoFunction("next-table-row", this.onTableRowClick.bind(this));
        this.onAddElementEventDoFunction("next-dialog-body", this.pkgUploadFormUpdate.bind(this));
        this.onAddElementEventDoFunction("next-btn", this.quickMFALogin.bind(this));
      },
      // ===================================================================================== 制品
      /**
       * 更新制品上传表单
       */
      pkgUploadFormUpdate: function() {
        if (location.href.indexOf("https://packages.aliyun.com") == -1)
          return false;
        let _this = this;
        let $groupId = document.querySelector("#groupId");
        let $artifactId = document.querySelector("#artifactId");
        let $version = document.querySelector("#version");
        if (_this.currentPackage) {
          $groupId.value = _this.currentPackage.group;
          _this.reactInputEmit($groupId);
          $artifactId.value = _this.currentPackage.artifact;
          _this.reactInputEmit($artifactId);
          $version.value = _this.currentPackage.version;
          _this.reactInputEmit($version);
        }
        _this.currentPackage = null;
      },
      // js如何在外部改变react受控组件的状态量?参考:https://github.com/ILovePing/ILovePing.github.io/issues/22
      reactInputEmit: function(element) {
        let event = new Event("input", { bubbles: true });
        event.simulated = true;
        let tracker = element._valueTracker;
        if (tracker) {
          tracker.setValue(element);
        }
        element.dispatchEvent(event);
      },
      versionFormat: function(version) {
        if (!version)
          return version;
        let arr = version.split("-");
        let numberArr = arr[0].split(".");
        numberArr.forEach((e, i) => {
          if (i >= numberArr.length - 1) {
            numberArr[numberArr.length - 1] = ++e;
          }
        });
        let out = numberArr.join(".");
        if (arr[1]) {
          out += "-SNAPSHOT";
        }
        return out;
      },
      clickTableRow: function(e) {
        if (e.button == 1) {
          let $parent = app.getParent(e.target, "next-table-row");
          let $cells = $parent.querySelectorAll(".next-table-cell");
          let $GA = $parent.querySelector(".teamix-title");
          let $ver = $cells[1].querySelector(".next-table-cell-wrapper");
          let GAStr = $GA.innerText;
          app.currentPackage = {
            group: GAStr.split(":")[0],
            artifact: GAStr.split(":")[1],
            version: app.versionFormat($ver.innerText)
          };
          document.querySelector("button.upload-btn").click();
        }
      },
      onTableRowClick: function() {
        document.querySelectorAll(".next-table-row").forEach((e) => {
          e.removeEventListener("mousedown", this.clickTableRow);
          e.addEventListener("mousedown", this.clickTableRow);
        });
      },
      /**
       * 监听指定元素加载完成,执行函数
       */
      onAddElementEventDoFunction: function(elementClassName, func) {
        let mos = new MutationObserver(function(mutations, observer) {
          for (const mutation in mutations) {
            if (Object.hasOwnProperty.call(mutations, mutation)) {
              const element = mutations[mutation];
              if (element.target.classList.contains(elementClassName)) {
                func();
              }
            }
          }
        });
        mos.observe(document.body, {
          attributes: true,
          childList: true,
          subtree: true
        });
      },
      /**
       * 获取指定元素的目标父元素
       * @param {Dom} element
       * @param {String} className
       * @returns Dom[]
       */
      getParent: function(element, className) {
        if (!element || !className) {
          return false;
        }
        let _this = this;
        while (element.parentNode) {
          element = element.parentNode;
          if (element.classList && element.classList.contains(className)) {
            return element;
          }
          _this.getParent(element, className);
        }
        return null;
      },
      // ===================================================================================== 登录
      // MFA快速登录
      quickMFALogin: function() {
        if (location.href.indexOf("signin.aliyun.com") == -1)
          return false;
        let $btnSubmit = document.querySelector(".next-btn[type=submit]");
        if ($btnSubmit.innerHTML.indexOf("提交验证") == -1)
          return false;
        let $nextMessageError = document.querySelector(".next-message-error");
        let $nextLoadingTip = document.querySelector(".next-loading-tip");
        if (!$btnSubmit.hasAttribute("disabled") && !$nextMessageError && !$nextLoadingTip) {
          $btnSubmit.click();
        }
      }
    };
    app.init();
  })();

})();