<commit_before>/* globals $ */

import { remote, ipcRenderer } from 'electron';
import i18n from '../i18n/index.js';
import servers from './servers';
import sidebar from './sidebar';
import webview from './webview';
import tray from './tray';
import './menus';

sidebar.on('badge-setted', function () {
    const badge = sidebar.getGlobalBadge();

    if (process.platform === 'darwin' && badge.showAlert) {
        remote.app.dock.setBadge(badge.count.toString());
    }
    tray.showTrayAlert(badge);
});

export const start = function () {
    const defaultInstance = 'https://open.rocket.chat';

    // connection check
    function online () {
        document.body.classList.remove('offline');
    }

    function offline () {
        document.body.classList.add('offline');
    }

    if (!navigator.onLine) {
        offline();
    }
    window.addEventListener('online', online);
    window.addEventListener('offline', offline);
    // end connection check

    const form = document.querySelector('form');
    const hostField = form.querySelector('[name="host"]');
    const button = form.querySelector('[type="submit"]');
    const invalidUrl = form.querySelector('#invalidUrl');

    window.addEventListener('load', function () {
        hostField.focus();
    });

    function validateHost () {
        return new Promise(function (resolve, reject) {
            const execValidation = function () {
                invalidUrl.style.display = 'none';
                hostField.classList.remove('wrong');

                let host = hostField.value.trim();
                host = host.replace(/\/$/, '');
                hostField.value = host;

                if (host.length === 0) {
                    button.value = i18n.__('Connect');
                    button.disabled = false;
                    resolve();
                    return;
                }

                button.value = i18n.__('Validating');
                button.disabled = true;

                servers.validateHost(host, 2000).then(function () {
                    button.value = i18n.__('Connect');
                    button.disabled = false;
                    resolve();
                }, function (status) {
                    // If the url begins with HTTP, mark as invalid
                    if (/^https?:\/\/.+/.test(host) || status === 'basic-auth') {
                        button.value = i18n.__('Invalid_url');
                        invalidUrl.style.display = 'block';
                        switch (status) {<commit_msg>[FIX] trailing slashes<commit_after>/* globals $ */

import { remote, ipcRenderer } from 'electron';
import i18n from '../i18n/index.js';
import servers from './servers';
import sidebar from './sidebar';
import webview from './webview';
import tray from './tray';
import './menus';

sidebar.on('badge-setted', function () {
    const badge = sidebar.getGlobalBadge();

    if (process.platform === 'darwin' && badge.showAlert) {
        remote.app.dock.setBadge(badge.count.toString());
    }
    tray.showTrayAlert(badge);
});

export const start = function () {
    const defaultInstance = 'https://open.rocket.chat';

    // connection check
    function online () {
        document.body.classList.remove('offline');
    }

    function offline () {
        document.body.classList.add('offline');
    }

    if (!navigator.onLine) {
        offline();
    }
    window.addEventListener('online', online);
    window.addEventListener('offline', offline);
    // end connection check

    const form = document.querySelector('form');
    const hostField = form.querySelector('[name="host"]');
    const button = form.querySelector('[type="submit"]');
    const invalidUrl = form.querySelector('#invalidUrl');

    window.addEventListener('load', function () {
        hostField.focus();
    });

    function validateHost () {
        return new Promise(function (resolve, reject) {
            const execValidation = function () {
                invalidUrl.style.display = 'none';
                hostField.classList.remove('wrong');

                let host = hostField.value.trim();
                hostField.value = host;

                if (host.length === 0) {
                    button.value = i18n.__('Connect');
                    button.disabled = false;
                    resolve();
                    return;
                }

                button.value = i18n.__('Validating');
                button.disabled = true;

                servers.validateHost(host, 2000).then(function () {
                    button.value = i18n.__('Connect');
                    button.disabled = false;
                    resolve();
                }, function (status) {
                    // If the url begins with HTTP, mark as invalid
                    if (/^https?:\/\/.+/.test(host) || status === 'basic-auth') {
                        button.value = i18n.__('Invalid_url');
                        invalidUrl.style.display = 'block';
                        switch (status) {
{'fraction_non_alphanumeric': 0.1420059582919563, 'fraction_numerical': 0.006752730883813307, 'mean_word_length': 1.8843069873997709, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1030745', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1269, 'n_words': 282}