Goto-login on gerrit

Check if you're logged in to gerrit or not. If not, click the sign-in link. Based on https://greasyfork.org/en/scripts/441236-auto-login-on-gerrit

Installer dette script?
Skaberens foreslåede script

Du vil måske også kunne lide Gerrit fill user and pass

Installer dette script

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Goto-login on gerrit
// @name:zh-CN   gerrit自动转到登录
// @namespace    https://greasyfork.org/en/scripts/468102-goto-login-on-gerrit
// @version      1.1
// @description  Check if you're logged in to gerrit or not.  If not, click the sign-in link. Based on https://greasyfork.org/en/scripts/441236-auto-login-on-gerrit
// @description:zh-CN 测试是否登录到了gerrit。如果没有则点击“登录”。基于https://greasyfork.org/en/scripts/441236-auto-login-on-gerrit
// @author       Allen Tse
// @match        SetYourGerritUrl
// @grant        none
// @license      Apache-2.0. And not welcomed to be modified or used by, or, if possible, redistributed to people who discriminate against people based on race, gender or sexual orientation.
// ==/UserScript==

(function() {
    'use strict';

    setTimeout(function() {
        try
        {
            console.log("Looking for login button...");
            var eleApp = document.querySelector("gr-app");
            if (eleApp) {
              var mainHeader = eleApp.shadowRoot.querySelector("gr-app-element").shadowRoot.querySelector("gr-main-header")
              if(mainHeader.attributes["logged-in"])
              {
                  console.log("Already logged in");
                  return;
              }

              var loginButton = mainHeader.shadowRoot.querySelector(".loginButton")
              console.log("query for login button: " + loginButton);
              if (loginButton)
              {
                  loginButton.click();
              }
            } else {
              eleApp = document.getElementsByClassName('topmenuMenuRight');
              if (eleApp && eleApp.length > 0) {
                eleApp = eleApp[0].getElementsByClassName('menuItem');
                if (eleApp && eleApp.length > 0) {
                  if (eleApp[0].textContent == 'Sign In') {
                    console.log("clicking sign in for gerrit");
                    eleApp[0].click();
                  } else {
                    console.log("menuItem="+eleApp[0].textContent);
                  }
                } else {
                  console.log("No menu item found for gerrit");
                }
              } else {
                console.log("No menu bar found for gerrit");
              }
            }
        } catch(e)
        {
            console.log("Caught: " + e);
        }}, 1000);

})();