(() => {

  "use strict";

  let defaults = {
    domain: "",
    client: {},
    token: {},
    visibility: "public",
  };

  load();

  function load() {
    chrome.storage.sync.get(defaults, function(storage) {
      document.querySelector("#domain").value = storage.domain;
      if (storage.token.access_token) {
        document.querySelector("#button").textContent = "Reauth";
      }
      document.querySelector("#visibility").value = storage.visibility;
    });

    document.querySelector("#auth").addEventListener("submit", function(event) {
      event.preventDefault();
      getAuthorizationCode();
    });

    document.querySelector("#domain").addEventListener("keydown", function(event) {
      document.querySelector("#instance-url-msg").textContent = "";
    });

    document.querySelector("#save").addEventListener("click", save);
  }

  function save() {
    chrome.storage.sync.set({
      domain: document.querySelector("#domain").value,
      visibility: document.querySelector("#visibility").value
    }, function() {
      let status = document.querySelector("#status");
      status.classList.add("text-success");
      status.textContent = "Saved successfully!";
      setTimeout(function() {
        status.textContent = "";
        status.classList.remove("text-success");
      }, 1500);
    });
  }

  function getAuthorizationCode() {
    let xhr = new XMLHttpRequest();
    const clientName = "Fastoot";
    const redirectURI = chrome.extension.getURL("auth.html");
    const scope = "write";
    let domain = document.querySelector("#domain").value;

    if (domain !== "") {
      // TODO: remove trailing slash
    }
    else {
      alert("Please set an instance");
      return false;
    }

    xhr.open("POST", domain + "/api/v1/apps", true);
    xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    xhr.send("client_name=" + clientName + "&redirect_uris=" + redirectURI + "&scopes=" + scope);

    xhr.onreadystatechange = function(event) {
      if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
        let msg = document.querySelector("#instance-url-msg");
        msg.textContent = "";

        let response = JSON.parse(xhr.response);
        chrome.storage.sync.set({
          domain: document.querySelector("#domain").value,
          client: response
        }, function() {
          window.location.href = domain + "/oauth/authorize?client_id=" + response.client_id + "&response_type=code&redirect_uri=" + response.redirect_uri + "&scope=" + scope;
        });
      }
      else {
        let msg = document.querySelector("#instance-url-msg");
        msg.classList.remove("text-success");
        msg.classList.add("text-danger");
        msg.textContent = "An error occurred. Please check an instance URL.";
      }

    }
  }

})();

@@ -275,121 +275,38 @@
 in;%0A
- 
+%0A
      
-if (storage.token.access_token) %7B%0A        document.querySelector(%22#button%22).textContent = %22Reauth%22;%0A      %7D
+ toggleAuthAndRevoke();%0A
 %0A   
@@ -474,57 +474,63 @@
     
-event.preventDefault();%0A      getAuthorizationCod
+selectOperationAuthOrRevoke();%0A      toggleAuthAndRevok
 e();
@@ -2746,14 +2746,1321 @@
  %7D%0A  %7D%0A%0A
+  function revokeAuthorizationCode() %7B%0A    chrome.storage.sync.set(%7B%0A      token: %7B%7D%0A    %7D, function() %7B%0A      let msg = document.querySelector(%22#instance-url-msg%22);%0A      msg.classList.remove(%22text-danger%22);%0A      msg.classList.add(%22text-success%22);%0A      msg.textContent = %22Revoke successfully%22;%0A%0A      setTimeout(function() %7B%0A        msg.classList.remove(%22text-success%22);%0A        msg.textContent = %22%22;%0A      %7D, 1500);%0A    %7D);%0A  %7D%0A%0A  function selectOperationAuthOrRevoke() %7B%0A    let button = document.querySelector(%22#button%22);%0A%0A    if (button.textContent === %22Auth%22) %7B%0A      event.preventDefault();%0A      getAuthorizationCode();%0A    %7D%0A    else if (button.textContent === %22Revoke%22) %7B%0A      event.preventDefault();%0A      revokeAuthorizationCode();%0A    %7D%0A  %7D%0A%0A  function toggleAuthAndRevoke() %7B%0A    chrome.storage.sync.get(defaults, function(storage) %7B%0A      if (storage.token.access_token) %7B%0A        let button = document.querySelector(%22#button%22);%0A%0A        button.classList.remove(%22btn-primary%22);%0A        button.classList.add(%22btn-danger%22);%0A        button.textContent = %22Revoke%22;%0A      %7D%0A      else %7B%0A        let button = document.querySelector(%22#button%22);%0A%0A        button.classList.remove(%22btn-danger%22);%0A        button.classList.add(%22btn-primary%22);%0A        button.textContent = %22Auth%22;%0A      %7D%0A    %7D);%0A  %7D%0A%0A
 %7D)();%0A

Add new feature to revoke an authorization code