<commit_before>﻿browser.on("init", function () {
    "use strict";

    // Check if a file exists at the specified URL
    function fileExists(url) {
        let http = new XMLHttpRequest;
        try {
            http.open("HEAD", url, false);
            http.send();
            return http.status !== 404;
        }
        catch (e) {
            console.error(`Unsuccessful XMLHttpRequest: ${e.toString()}`);
        }
    }

    // Get the domain
    function getDomain(url, removeWWW) {
        var domain = url.match(/:\/\/([^\/]+)/)[1];
        // Remove `www` subdomain
        if (removeWWW) {
            let pair = domain.split(".");
            if (pair.length > 1 && pair[0] === "www") {
                domain = pair.slice(1).join(".");
            }
        }
        return domain;
    }

    // Navigate to the specified URL
    this.navigateTo = (loc) => {
        try {
            this.webview.navigate(loc);
        }
        catch (e) {
            // Auto-add a protocol for convenience
            console.log(`Unable to navigate to ${loc}\nAttemping to prepend http:// to URI...`);

            try {
                loc = `http://${loc}`;
                this.webview.navigate(loc);
            }
            catch (e) {
                console.error(`${e.message}\nPrepend unsuccessful\nUnable to navigate to ${loc}`);
            }
        }
    };

    // Update the address bar with the current URL and remove focus
    this.updateAddressBar = () => {
        this.urlInput.value = this.currentUrl;
        this.urlInput.blur();
    };

    // Show or hide the progress ring
    this.showProgressRing = (shown) => void (document.querySelector(".ring").style.display = shown ? "inline-block" : "none");

    // Show the favicon if available
    this.getFavicon = (uri) => {
        // Check if there is a favicon in the root directory
        let currentUrl = uri;
        let protocol = currentUrl.split(":");
        if (protocol[0].slice(0, 4) !== "http") {
            return;
        }<commit_msg>add protocol fallback<commit_after>﻿browser.on("init", function () {
    "use strict";

    // Check if a file exists at the specified URL
    function fileExists(url) {
        let http = new XMLHttpRequest;
        try {
            http.open("HEAD", url, false);
            http.send();
            return http.status !== 404;
        }
        catch (e) {
            console.error(`Unsuccessful XMLHttpRequest: ${e.message}`);
        }
    }

    // Get the domain
    function getDomain(url, removeWWW) {
        let uri = new Windows.Foundation.Uri(url);
        return removeWWW ? uri.domain : uri.host;
    }

    // Attempt a function
    function attempt(func) {
        try {
            return func();
        }
        catch (e) {
            return e;
        }
    }

    // Navigate to the specified URL
    this.navigateTo = (loc) => {
        let result = attempt(() => this.webview.navigate(loc));
        if (!(result instanceof Error)) {
            return;
        }

        console.log(`Unable to navigate to ${loc}\nAttemping to prepend http:// to URI...`);
        let locProtocol = `https://${loc}`;
        result = attempt(() => new Windows.Foundation.Uri(locProtocol));

        if (result instanceof Error || !result.domain) {
            console.log(`${result.message}\nPrepend unsuccessful\nQuerying bing.com... "${loc}"`);
            let bingPath = `https://www.bing.com/search?q=${encodeURIComponent(loc)}`;

            result = attempt(() => this.webview.navigate(bingPath));
            if (result instanceof Error) {
                console.error(`${result.message}\nUnable to navigate to ${bingPath}`);
            }
        }
        else {
            // Check if the site supports https
            Windows.Web.Http.HttpClient().getAsync(result, Windows.Web.Http.HttpCompletionOption.responseHeadersRead).done(
                () => {
                    // The site supports https, navigate using that protocol
                    result = attempt(() => this.webview.navigate(locProtocol));
                    if (result instanceof Error) {
                        console.error(`${result.message}\nUnable to navigate to ${locProtocol}`);
                    }
                }
            );
            // Get a head start on loading via http
            result = attempt(() => this.webview.navigate(`http://${loc}`));
            if (result instanceof Error) {
                console.error(`${result.message}\nUnable to navigate to http://${loc}`);
            }
        }
    };

    // Update the address bar with the current URL and remove focus
    this.updateAddressBar = () => {
        this.urlInput.value = this.currentUrl;
        this.urlInput.blur();
    };

    // Show or hide the progress ring
    this.showProgressRing = (shown) => void (document.querySelector(".ring").style.display = shown ? "inline-block" : "none");

    // Show the favicon if available
    this.getFavicon = (uri) => {
        // Check if there is a favicon in the root directory
        let currentUrl = uri;
        let protocol = currentUrl.split(":");
        if (protocol[0].slice(0, 4) !== "http") {
            return;
        }
{'fraction_non_alphanumeric': 0.13759355210132412, 'fraction_numerical': 0.003070427940894262, 'mean_word_length': 1.7345225603357817, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 2, 'lorem ipsum': 0, 'www.': 3, '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': '4727965', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1409, 'n_words': 374}