Skip to content

Instantly share code, notes, and snippets.

@katai5plate
Created November 8, 2019 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katai5plate/8a7a3c3eae0d74995c9a23efd9c7c726 to your computer and use it in GitHub Desktop.
Save katai5plate/8a7a3c3eae0d74995c9a23efd9c7c726 to your computer and use it in GitHub Desktop.

Original

function nativeApLoginStart() {
  var c = installVersionCheck(false);
  var d = c[1];
  var a = c[0];
  if (d === "" || a === "") {
    var f = $("#browserType").val();
    var e = $("#osType").val();
    if ("Win" === e && "IE" === f) {
      $("#ieInstallDialog").dialog("open");
    } else {
      if ("Win" === e && "Edge" === f) {
        $("#edgeInstallDialog").dialog("open");
      } else {
        if ("Win" === e && "Chrome" === f) {
          $("#chromeInstallDialog").dialog("open");
        } else {
          if ("Win" === e && "Firefox" === f) {
            $("#firefoxInstallDialog").dialog("open");
          } else {
            if ("Mac" === e && "Safari" === f) {
              $("#safariInstallDialog").dialog("open");
            } else {
              if ("Mac" === e && "Chrome" === f) {
                $("#chromeInstallDialog").dialog("open");
              } else {
                if ("Mac" === e && "Firefox" === f) {
                  $("#firefoxInstallDialog").dialog("open");
                }
              }
            }
          }
        }
      }
    }
    return;
  }
}

My refactoring

const nativeApLoginStart = () => {
  const [what, theFuck] = installVersionCheck(false);
  if (what === "" || theFuck === "") {
    const targetPlatform = document.getElementById("#osType").value;
    const targetBrowser = document.getElementById("#browserType").value;
    [
      { platform: "Win", browser: "IE", alias: "ie" },
      { platform: "Win", browser: "Edge", alias: "edge" },
      { platform: "Win", browser: "Chrome", alias: "chrome" },
      { platform: "Win", browser: "Firefox", alias: "firefox" },
      { platform: "Mac", browser: "Safari", alias: "safari" },
      { platform: "Mac", browser: "Chrome", alias: "chrome" },
      { platform: "Mac", browser: "Firefox", alias: "firefox" }
    ].forEach(([platform, browser, alias]) => {
      if (targetPlatform === platform && targetBrowser === browser)
        $(document.getElementById(`${alias}InstallDialog`)).dialog("open");
    });
  }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment