<commit_before>/*
 * Copyright (C) 2016  <NAME> @Joxit
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
var registryUI = {}
registryUI.url = function() {
  return registryUI.getRegistryServer(0);
}
registryUI.getRegistryServer = function(i) {
  try {
    var res = JSON.parse(localStorage.getItem('registryServer'));
    if (res instanceof Array) {
      return (!isNaN(i)) ? res[i] : res.map(function(url) {
        return url.trim().replace(/\/*$/, '');
      });
    }
  } catch (e) {}
  return (!isNaN(i)) ? '' : [];
}
registryUI.addServer = function(url) {
  var registryServer = registryUI.getRegistryServer();
  url = url.trim().replace(/\/*$/, '');
  var index = registryServer.indexOf(url);
  if (index != -1) {
    return;
  }
  registryServer.push(url);
  localStorage.setItem('registryServer', JSON.stringify(registryServer));
}
registryUI.changeServer = function(url) {
  var registryServer = registryUI.getRegistryServer();
  url = url.trim().replace(/\/*$/, '');
  var index = registryServer.indexOf(url);
  if (index == -1) {
    return;
  }
  registryServer.splice(index, 1);
  registryServer = [url].concat(registryServer);
  localStorage.setItem('registryServer', JSON.stringify(registryServer));
}
registryUI.removeServer = function(url) {
  var registryServer = registryUI.getRegistryServer();
  url = url.trim().replace(/\/*$/, '');
  var index = registryServer.indexOf(url);
  if (index == -1) {
    return;
  }
  registryServer.splice(index, 1);
  localStorage.setItem('registryServer', JSON.stringify(registryServer));
}
registryUI.isImageRemoveActivated = true;
registryUI.catalog = {};
registryUI.taglist = {};

riot.mount('add');
riot.mount('change');
riot.mount('remove');
riot.mount('menu');
riot.mount('app');<commit_msg>[query-param] Add url query param for sharing<commit_after>/*
 * Copyright (C) 2016  <NAME> @Joxit
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
var registryUI = {}
registryUI.URL_QUERY_PARAM_REGEX = /[&?]url=/;
registryUI.URL_PARAM_REGEX = /^url=/;

registryUI.url = function() {
  if (!registryUI._url) {
    var url = registryUI.getUrlQueryParam();
    if (url) {
      try {
        registryUI._url = registryUI.decodeURI(url);
        return registryUI._url;
      } catch (e) {
        console.log(e);
      }
    }
    registryUI._url = registryUI.getRegistryServer(0);
  }
  return registryUI._url;
}
registryUI.getRegistryServer = function(i) {
  try {
    var res = JSON.parse(localStorage.getItem('registryServer'));
    if (res instanceof Array) {
      return (!isNaN(i)) ? res[i] : res.map(function(url) {
        return url.trim().replace(/\/*$/, '');
      });
    }
  } catch (e) {}
  return (!isNaN(i)) ? '' : [];
}
registryUI.addServer = function(url) {
  var registryServer = registryUI.getRegistryServer();
  url = url.trim().replace(/\/*$/, '');
  var index = registryServer.indexOf(url);
  if (index != -1) {
    return;
  }
  registryServer.push(url);
  if (!registryUI._url) {
    registryUI.updateHistory(url);
  }
  localStorage.setItem('registryServer', JSON.stringify(registryServer));
}
registryUI.changeServer = function(url) {
  var registryServer = registryUI.getRegistryServer();
  url = url.trim().replace(/\/*$/, '');
  var index = registryServer.indexOf(url);
  if (index == -1) {
    return;
  }
  registryServer.splice(index, 1);
  registryServer = [url].concat(registryServer);
  registryUI.updateHistory(url);
  localStorage.setItem('registryServer', JSON.stringify(registryServer));
}
registryUI.removeServer = function(url) {
  var registryServer = registryUI.getRegistryServer();
  url = url.trim().replace(/\/*$/, '');
  var index = registryServer.indexOf(url);
  if (index == -1) {
    return;
  }
  registryServer.splice(index, 1);
  localStorage.setItem('registryServer', JSON.stringify(registryServer));
}

registryUI.updateHistory = function(url) {
  history.pushState(null, '', '?url=' + registryUI.encodeURI(url) + window.location.hash);
  registryUI._url = url;
}

registryUI.getUrlQueryParam = function () {
  var search = window.location.search;
  if (registryUI.URL_QUERY_PARAM_REGEX.test(search)) {
    var param = search.split(/^\?|&/).find(function(param) {
      return param && registryUI.URL_PARAM_REGEX.test(param);
    });
    return param ? param.replace(registryUI.URL_PARAM_REGEX, '') : param;
  }
};

registryUI.encodeURI = function(url) {
  return url.indexOf('&') < 0 ? window.encodeURI(url) : btoa(url);
};

registryUI.decodeURI = function(url) {
  return url.startsWith('http') ? window.decodeURI(url) : atob(url);
};

registryUI.isImageRemoveActivated = true;
registryUI.catalog = {};
registryUI.taglist = {};

riot.mount('add');
riot.mount('change');
riot.mount('remove');
riot.mount('menu');
riot.mount('app');
{'fraction_non_alphanumeric': 0.14958263772954924, 'fraction_numerical': 0.0038397328881469117, 'mean_word_length': 4.030226700251889, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5072078', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1835, 'n_words': 464}