<commit_before>/* global PouchDB, page, Toast, emit, Page, showdown  */
//PouchDB.debug.enable('*');

showdown.setOption("strikethrough", 'true');
showdown.setOption("tables", 'true');
showdown.setOption("tasklists", 'true');
showdown.setOption("tablesHeaderId", 'true');
showdown.setOption("omitExtraWLInCodeBlocks", 'true');
showdown.setOption("literalMidWordUnderscores","true");

class WuZhu {
  static get defaults(){
    return {};
  }
  constructor(){
    this.db = {
      local: new PouchDB(window.config.db_name),
      remote: new PouchDB(`https://${window.config.db_host}/${window.config.db_name}`, { skipSetup: true })
    }
    this._sidenav = document.querySelector("side-nav");
    this._stage = document.querySelector("view");
    this._searchEl = document.querySelector("search-results");


    this.showIndex = this.showIndex.bind(this);
    this.getArticle = this.getArticle.bind(this);
    this.showArticle = this.showArticle.bind(this);
    this._handleLogin = this._handleLogin.bind(this);
    this._checkSession = this._checkSession.bind(this);
    this._saveMetadata = this._saveMetadata.bind(this);
    this._getMetadata = this._getMetadata.bind(this);
    this._clearStage = this._clearStage.bind(this);
    this._toggleFav = this._toggleFav.bind(this);
    this.newArticle = this.newArticle.bind(this);
    this._addFav = this._addFav.bind(this);
    this._delFav = this._delFav.bind(this);
    this._saveMetadata = this._saveMetadata.bind(this);
    this._saveArticle = this._saveArticle.bind(this);
    this._deleteArticle = this._deleteArticle.bind(this);
    this._search = this._search.bind(this);
    this._parseTitles = this._parseTitles.bind(this);
    this._initServiceWorker = this._initServiceWorker.bind(this);


    this._addEventListeners();
    this._addRoutes();
    this._initDbFuncs();
    this._initServiceWorker();
  }

  _initServiceWorker(){
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('/worker.js').then(function(registration) {
        // Registration was successful
        //console.log('ServiceWorker registration successful with scope: ', registration.scope);
      }).catch(function(err) {
        // registration failed :(
        //console.log('ServiceWorker registration failed: ', err);
      });
    }
  }

  _initDbFuncs(){
    this.db.local.put({
      _id: "_design/tagView",
      views: {
        tagView: {
          map: function(doc){
            if (doc.tags){
              doc.tags.forEach(function(tag){
                emit(tag);
              });
            }
          }.toString(),
          reduce: "_count"
        }
      }
    }).catch(err => {
      if (err.name !== "conflict"){
        throw err;
      }
    })

    this.db.local.put({
      _id: "_design/titleView",
      views: {
        titleView: {
          map: function(doc){
            emit(doc.title);
          }.toString()
        }
      }
    }).catch(err => {
      if (err.name !== "conflict"){
        throw err;
      }
    })
  }

  _clearStage() {
    if (this._stage.classList.contains("hidden")){
      this._stage.classList.remote("hidden");<commit_msg>classList.remove not classList.remote<commit_after>/* global PouchDB, page, Toast, emit, Page, showdown  */
//PouchDB.debug.enable('*');

showdown.setOption("strikethrough", 'true');
showdown.setOption("tables", 'true');
showdown.setOption("tasklists", 'true');
showdown.setOption("tablesHeaderId", 'true');
showdown.setOption("omitExtraWLInCodeBlocks", 'true');
showdown.setOption("literalMidWordUnderscores","true");

class WuZhu {
  static get defaults(){
    return {};
  }
  constructor(){
    this.db = {
      local: new PouchDB(window.config.db_name),
      remote: new PouchDB(`https://${window.config.db_host}/${window.config.db_name}`, { skipSetup: true })
    }
    this._sidenav = document.querySelector("side-nav");
    this._stage = document.querySelector("view");
    this._searchEl = document.querySelector("search-results");


    this.showIndex = this.showIndex.bind(this);
    this.getArticle = this.getArticle.bind(this);
    this.showArticle = this.showArticle.bind(this);
    this._handleLogin = this._handleLogin.bind(this);
    this._checkSession = this._checkSession.bind(this);
    this._saveMetadata = this._saveMetadata.bind(this);
    this._getMetadata = this._getMetadata.bind(this);
    this._clearStage = this._clearStage.bind(this);
    this._toggleFav = this._toggleFav.bind(this);
    this.newArticle = this.newArticle.bind(this);
    this._addFav = this._addFav.bind(this);
    this._delFav = this._delFav.bind(this);
    this._saveMetadata = this._saveMetadata.bind(this);
    this._saveArticle = this._saveArticle.bind(this);
    this._deleteArticle = this._deleteArticle.bind(this);
    this._search = this._search.bind(this);
    this._parseTitles = this._parseTitles.bind(this);
    this._initServiceWorker = this._initServiceWorker.bind(this);


    this._addEventListeners();
    this._addRoutes();
    this._initDbFuncs();
    this._initServiceWorker();
  }

  _initServiceWorker(){
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('/worker.js').then(function(registration) {
        // Registration was successful
        //console.log('ServiceWorker registration successful with scope: ', registration.scope);
      }).catch(function(err) {
        // registration failed :(
        //console.log('ServiceWorker registration failed: ', err);
      });
    }
  }

  _initDbFuncs(){
    this.db.local.put({
      _id: "_design/tagView",
      views: {
        tagView: {
          map: function(doc){
            if (doc.tags){
              doc.tags.forEach(function(tag){
                emit(tag);
              });
            }
          }.toString(),
          reduce: "_count"
        }
      }
    }).catch(err => {
      if (err.name !== "conflict"){
        throw err;
      }
    })

    this.db.local.put({
      _id: "_design/titleView",
      views: {
        titleView: {
          map: function(doc){
            emit(doc.title);
          }.toString()
        }
      }
    }).catch(err => {
      if (err.name !== "conflict"){
        throw err;
      }
    })
  }

  _clearStage() {
    if (this._stage.classList.contains("hidden")){
      this._stage.classList.remove("hidden");
{'fraction_non_alphanumeric': 0.15438152483391332, 'fraction_numerical': 0.0, 'mean_word_length': 2.8484479610468654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '848756', 'n_tokens_mistral': 1970, 'n_tokens_neox': 1922, 'n_words': 289}