<commit_before>define([
    '/api/config',
    '/customize/messages.js',
    '/common/common-util.js',
    '/common/common-hash.js',
    '/common/common-messaging.js',
    '/common/common-constants.js',
    '/common/common-feedback.js',
    '/common/visible.js',
    '/common/userObject.js',
    '/common/outer/local-store.js',
    '/common/outer/worker-channel.js',
    '/common/outer/login-block.js',

    '/customize/application_config.js',
    '/bower_components/nthen/index.js',
], function (Config, Messages, Util, Hash,
            Messaging, Constants, Feedback, Visible, UserObject, LocalStore, Channel, Block,
            AppConfig, Nthen) {

/*  This file exposes functionality which is specific to Cryptpad, but not to
    any particular pad type. This includes functions for committing metadata
    about pads to your local storage for future use and improved usability.

    Additionally, there is some basic functionality for import/export.
*/
    var urlArgs = Util.find(Config, ['requireConf', 'urlArgs']) || '';

    var postMessage = function (/*cmd, data, cb*/) {
        /*setTimeout(function () {
            AStore.query(cmd, data, cb);
        });*/
        console.error('NOT_READY');
    };
    var tryParsing = function (x) {
        try { return JSON.parse(x); }
        catch (e) {
            console.error(e);
            return null;
        }
    };

    // Upgrade and donate URLs duplicated in pages.js
    var origin = encodeURIComponent(window.location.hostname);
    var common = window.Cryptpad = {
        Messages: Messages,
        donateURL: AppConfig.donateURL || "https://opencollective.com/cryptpad/",
        upgradeURL: AppConfig.upgradeURL || 'https://accounts.cryptpad.fr/#/?on=' + origin,
        account: {},
    };

    // Store the href in memory
    // This is a placeholder value overriden in common.ready from sframe-common-outer
    var currentPad = common.currentPad = {
        href: window.location.href
    };

    // COMMON
    common.getLanguage = function () {
        return Messages._languageUsed;
    };
    common.setLanguage = function (l, cb) {
        var LS_LANG = "CRYPTPAD_LANG";
        localStorage.setItem(LS_LANG, l);
        postMessage("SET_ATTRIBUTE", {
            attr: ['general', 'language'],
            value: l
        }, cb);
    };

    common.getAccessKeys = function (cb) {
        var keys = [];
        Nthen(function (waitFor) {
            // Push account keys
            postMessage("GET", {
                key: ['edPrivate'],
            }, waitFor(function (obj) {
                if (obj.error) { return; }
                try {
                    keys.push({
                        edPrivate: obj,
                        edPublic: Hash.getSignPublicFromPrivate(obj)
                    });
                } catch (e) { console.error(e); }
            }));
            // Push teams keys
            postMessage("GET", {
                key: ['teams'],
            }, waitFor(function (obj) {
                if (obj.error) { return; }
                Object.keys(obj || {}).forEach(function (id) {
                    var t = obj[id];
                    var _keys = t.keys.drive || {};
                    if (!_keys.edPrivate) { return; }
                    keys.push(t.keys.drive);
                });
            }));
        }).nThen(function () {
            cb(keys);
        });
    };

    common.makeNetwork = function (cb) {
        require([
            '/bower_components/netflux-websocket/netflux-client.js',
            '/common/outer/network-config.js'
        ], function (Netflux, NetConfig) {
            var wsUrl = NetConfig.getWebsocketURL();
            Netflux.connect(wsUrl).then(function (network) {
                cb(null, network);
            }, function (err) {
                cb(err);
            });
        });
    };


    common.getTeamsId = function () {
        postMessage("GET", {
            key: ['teams'],
        }, function (obj) {
            if (obj.error) { return; }
            Object.keys(obj || {}).forEach(function (id) {
                console.log(obj[id].metadata.name, ':', id);
            });
        });

    };
    common.fixFork = function (teamId) {
        var i = 0;
        var send = function () {
            if (i >= 110) {
                postMessage("SET", {
                    teamId: teamId,
                    key: ['fixFork'],
                }, function () {});
                return;
            }
            postMessage("SET", {
                teamId: teamId,
                key: ['fixFork'],
                value: i
            }, function () {
                i++;
                setTimeout(send, 500);
            });
        };
        send();
    };

    common.setTabHref = function (href) {
        var ohc = window.onhashchange;
        window.onhashchange = function () {};
        window.location.href = href;
        window.onhashchange = ohc;
        ohc({reset: true});
    };
    common.setTabHash = function (hash) {
        var ohc = window.onhashchange;
        window.onhashchange = function () {};
        window.location.hash = hash;
        window.onhashchange = ohc;
        ohc({reset: true});
    };

    // RESTRICTED
    // Settings only
    common.resetDrive = function (cb) {
        postMessage("RESET_DRIVE", null, function (obj) {
            if (obj && obj.error) { return void cb(obj.error); }
            cb();
        });
    };
    common.logoutFromAll = function (cb) {
        var token = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);<commit_msg>refactor two mostly-identical functions<commit_after>define([
    '/api/config',
    '/customize/messages.js',
    '/common/common-util.js',
    '/common/common-hash.js',
    '/common/common-messaging.js',
    '/common/common-constants.js',
    '/common/common-feedback.js',
    '/common/visible.js',
    '/common/userObject.js',
    '/common/outer/local-store.js',
    '/common/outer/worker-channel.js',
    '/common/outer/login-block.js',

    '/customize/application_config.js',
    '/bower_components/nthen/index.js',
], function (Config, Messages, Util, Hash,
            Messaging, Constants, Feedback, Visible, UserObject, LocalStore, Channel, Block,
            AppConfig, Nthen) {

/*  This file exposes functionality which is specific to Cryptpad, but not to
    any particular pad type. This includes functions for committing metadata
    about pads to your local storage for future use and improved usability.

    Additionally, there is some basic functionality for import/export.
*/
    var urlArgs = Util.find(Config, ['requireConf', 'urlArgs']) || '';

    var postMessage = function (/*cmd, data, cb*/) {
        /*setTimeout(function () {
            AStore.query(cmd, data, cb);
        });*/
        console.error('NOT_READY');
    };
    var tryParsing = function (x) {
        try { return JSON.parse(x); }
        catch (e) {
            console.error(e);
            return null;
        }
    };

    // Upgrade and donate URLs duplicated in pages.js
    var origin = encodeURIComponent(window.location.hostname);
    var common = window.Cryptpad = {
        Messages: Messages,
        donateURL: AppConfig.donateURL || "https://opencollective.com/cryptpad/",
        upgradeURL: AppConfig.upgradeURL || 'https://accounts.cryptpad.fr/#/?on=' + origin,
        account: {},
    };

    // Store the href in memory
    // This is a placeholder value overriden in common.ready from sframe-common-outer
    var currentPad = common.currentPad = {
        href: window.location.href
    };

    // COMMON
    common.getLanguage = function () {
        return Messages._languageUsed;
    };
    common.setLanguage = function (l, cb) {
        var LS_LANG = "CRYPTPAD_LANG";
        localStorage.setItem(LS_LANG, l);
        postMessage("SET_ATTRIBUTE", {
            attr: ['general', 'language'],
            value: l
        }, cb);
    };

    common.getAccessKeys = function (cb) {
        var keys = [];
        Nthen(function (waitFor) {
            // Push account keys
            postMessage("GET", {
                key: ['edPrivate'],
            }, waitFor(function (obj) {
                if (obj.error) { return; }
                try {
                    keys.push({
                        edPrivate: obj,
                        edPublic: Hash.getSignPublicFromPrivate(obj)
                    });
                } catch (e) { console.error(e); }
            }));
            // Push teams keys
            postMessage("GET", {
                key: ['teams'],
            }, waitFor(function (obj) {
                if (obj.error) { return; }
                Object.keys(obj || {}).forEach(function (id) {
                    var t = obj[id];
                    var _keys = t.keys.drive || {};
                    if (!_keys.edPrivate) { return; }
                    keys.push(t.keys.drive);
                });
            }));
        }).nThen(function () {
            cb(keys);
        });
    };

    common.makeNetwork = function (cb) {
        require([
            '/bower_components/netflux-websocket/netflux-client.js',
            '/common/outer/network-config.js'
        ], function (Netflux, NetConfig) {
            var wsUrl = NetConfig.getWebsocketURL();
            Netflux.connect(wsUrl).then(function (network) {
                cb(null, network);
            }, function (err) {
                cb(err);
            });
        });
    };


    common.getTeamsId = function () {
        postMessage("GET", {
            key: ['teams'],
        }, function (obj) {
            if (obj.error) { return; }
            Object.keys(obj || {}).forEach(function (id) {
                console.log(obj[id].metadata.name, ':', id);
            });
        });

    };
    common.fixFork = function (teamId) {
        var i = 0;
        var send = function () {
            if (i >= 110) {
                postMessage("SET", {
                    teamId: teamId,
                    key: ['fixFork'],
                }, function () {});
                return;
            }
            postMessage("SET", {
                teamId: teamId,
                key: ['fixFork'],
                value: i
            }, function () {
                i++;
                setTimeout(send, 500);
            });
        };
        send();
    };

    (function () {
        var bypassHashChange = function (key) {
            return function (value) {
                var ohc = window.onhashchange;
                window.onhashchange = function () {};
                window.location[key] = value;
                window.onhashchange = ohc;
                ohc({reset: true});
            };
        };
        common.setTabHref = bypassHashChange('href');
        common.setTabHash = bypassHashChange('hash');
    }());

    // RESTRICTED
    // Settings only
    common.resetDrive = function (cb) {
        postMessage("RESET_DRIVE", null, function (obj) {
            if (obj && obj.error) { return void cb(obj.error); }
            cb();
        });
    };
    common.logoutFromAll = function (cb) {
        var token = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);
{'fraction_non_alphanumeric': 0.1377309649201107, 'fraction_numerical': 0.0012496652682317236, 'mean_word_length': 1.5995359628770303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '751441', 'n_tokens_mistral': 3238, 'n_tokens_neox': 3083, 'n_words': 663}