<commit_before>"use strict";

var MediaPlayer = {
  init() {
    this.isElectron = window.process && window.process.type && window.process.versions.electron;

    /* Define elements */
    this.videoEl = document.getElementById("MediaPlayer");
    this.uploadEl = document.getElementById("upfile");
    this.headerEl = document.getElementById("header");

    this.playPauseEl = document.getElementById("play-pause");
    this.volumeIcon = document.getElementById("volume-icon");
    this.volumeSlider = document.getElementById("volume-range");
    this.loopEl = document.getElementById("loop");
    this.shuffleEl = document.getElementById("shuffle");
    this.speedBtnEl = document.getElementById("speed-btn");

    this.progressBar = document.getElementById("progress-bar");
    this.progressEl = document.getElementById("progress");
    this.tooltipEl = document.getElementById("tooltip");

    this.sidebarEl = document.getElementById("sidebar");
    this.controlsEl = document.getElementById("media-controls");
    this.canvasEl = document.getElementById("visualizer");

    this.controlOverlay = document.getElementById("control-overlay");
    this.videoEl.controls = false;

    this.previousBtn = document.getElementById("previous-btn");
    this.nextBtn = document.getElementById("next-btn");
    this.wirePrevNextControls({
      element: this.previousBtn,
      onHold: this.fastrewind.bind(this),
      onClick: () => {
        this.killContext();
        this.playlist.selectPrevious();
      }
    });
    this.wirePrevNextControls({
      element: this.nextBtn,
      onHold: this.fastforward.bind(this),
      onClick: () => {
        this.killContext();
        this.playlist.selectNext();
      }
    });

    /* Initialize playlist */
    this.playlist = new Playlist({
      element: document.getElementById("playlist"),
      onItemSelected: this.setMedia.bind(this),
      onItemRemoved: () => {},
      onItemCleared: () => {
        this.UIEnabled = false;
      },
    });

    this.settingsStore = new SettingsStore();
    this.settingsOverlay = new SettingsOverlay({
      store: this.settingsStore,
      element: document.getElementById("settings-overlay"),
      toggle: document.getElementById("settings-btn")
    });

    if (this.isElectron) {
      var ElectronApp = require("./js/ElectronApp");
      ElectronApp.init();
    }
    let fullscreenchange = (e) => {
      document.documentElement.classList.toggle("fullscreen",
        !!(document.fullscreenElement
        || document.webkitFullscreenElement
        || document.msFullscreenElement
        || document.mozFullScreenElement));
    };
    addEventListener("fullscreenchange", fullscreenchange);
    addEventListener("webkitfullscreenchange", fullscreenchange);
    addEventListener("msfullscreenchange", fullscreenchange);
    addEventListener("mozfullscreenchange", fullscreenchange);
    /* Bind functions */
    this.uploadFiles = this.uploadFiles.bind(this);

    /* Setup uploader */
    this.uploadEl.addEventListener("change", () => this.uploadFiles(this.uploadEl.files));

    this.sidebarEl.addEventListener("dragenter", () => {
      this.sidebarEl.classList.remove("no-drag");
      this.sidebarEl.classList.add("drag");
    });
    this.sidebarEl.addEventListener("dragleave", () => {
      this.sidebarEl.classList.remove("drag");
      this.sidebarEl.classList.add("no-drag");
    });
    this.sidebarEl.addEventListener("dragover", (e) => {
      e.preventDefault();
      e.stopPropagation();
    });
    this.sidebarEl.addEventListener("drop", (e) => {
      e.preventDefault();
      e.stopPropagation();
      this.uploadFiles(e.dataTransfer.files);
      this.sidebarEl.classList.remove("drag");
      this.sidebarEl.classList.add("no-drag");
    });

    this.progressBar.addEventListener("mousedown", function(e) {
      this.classList.add("dragging");
      MediaPlayer.onProgressClick(e.pageX);
    });
    this.progressBar.addEventListener("mouseup", (e) => {
      this.progressBar.classList.remove("dragging");
    });
    this.progressBar.addEventListener("mouseover", (e) => {
      if (this.progressBar.classList.contains("dragging")) {
        this.onProgressClick(e.pageX);
      }
    });
    this.progressBar.addEventListener("mouseover", function(e) {
      MediaPlayer.setProgressTooltip(e.pageX);
    });

    this.controlOverlay.addEventListener("click", () => {
      if (!this.UIEnabled) {
        return;
      }
      if (!this.videoEl.hidden) {
        this.togglePaused();
      }
    });

    addEventListener("keydown", (e) => {
      if (document.activeElement != document.body) {
        return;
      }
      switch (e.keyCode) {
        // Spacebar
        case 32:
          this.togglePaused();
          break;
        // Top arrow
        case 38:
          if (e.ctrlKey || e.metaKey) {
            this.changeVolume(Math.min(1, this.videoEl.volume + 0.1));
            e.preventDefault();
          } else {
            this.playlist.selectPrevious();
          }
          break;
        // Down arrow
        case 40:
          if (e.ctrlKey || e.metaKey) {
            this.changeVolume(Math.max(0, this.videoEl.volume - 0.1));
            e.preventDefault();
          } else {
            this.playlist.selectNext();
          }
          break;
        // Left arrow
        case 37:
          this.fastrewind();
          break;
        // Right arrow
        case 39:
          this.fastforward();
          break;
      }
    });
    this.videoEl.addEventListener("timeupdate", function() {
      MediaPlayer.updateProgressBar();
      MediaPlayer.tooltipEl.textContent = MediaPlayer.getTooltip(this.currentTime);
    });
    this.videoEl.addEventListener("play", () => {
      this.playPauseEl.classList.remove("paused");
    });
    this.videoEl.addEventListener("pause", () => {
      this.playPauseEl.classList.add("paused");
    });
    this.videoEl.addEventListener("ended", () => {
      this.killContext();
      this.playlist.selectNext();
    });
    this.initAudioContext();
  },
  set UIEnabled(value) {
    if (!value) {
      this.controlsEl.classList.add("disabled");
      this.headerEl.textContent = "";
      this.videoEl.hidden = true;
      this.canvasEl.hidden = false;
      this.videoEl.pause();
      this.videoEl.currentTime = 0;
    } else {
      this.controlsEl.classList.remove("disabled");
    }
  },
  get UIEnabled() {
    return !this.controlsEl.classList.contains("disabled");
  },

  toggleFullscreen() {
    let shouldGoFullscreen = !document.documentElement.classList.contains("fullscreen");

    if (shouldGoFullscreen) {
      if (!document.documentElement.requestFullScreen) {
        document.documentElement.requestFullScreen = document.documentElement.mozRequestFullScreen
            || document.documentElement.webkitRequestFullscreen;
      }
      document.documentElement.requestFullScreen();
    } else {<commit_msg>fix set UIenabled function<commit_after>"use strict";

var MediaPlayer = {
  init() {
    this.isElectron = window.process && window.process.type && window.process.versions.electron;

    /* Define elements */
    this.videoEl = document.getElementById("MediaPlayer");
    this.uploadEl = document.getElementById("upfile");
    this.headerEl = document.getElementById("header");

    this.playPauseEl = document.getElementById("play-pause");
    this.volumeIcon = document.getElementById("volume-icon");
    this.volumeSlider = document.getElementById("volume-range");
    this.loopEl = document.getElementById("loop");
    this.shuffleEl = document.getElementById("shuffle");
    this.speedBtnEl = document.getElementById("speed-btn");

    this.progressBar = document.getElementById("progress-bar");
    this.progressEl = document.getElementById("progress");
    this.tooltipEl = document.getElementById("tooltip");

    this.sidebarEl = document.getElementById("sidebar");
    this.controlsEl = document.getElementById("media-controls");
    this.canvasEl = document.getElementById("visualizer");

    this.controlOverlay = document.getElementById("control-overlay");
    this.videoEl.controls = false;

    this.previousBtn = document.getElementById("previous-btn");
    this.nextBtn = document.getElementById("next-btn");
    this.wirePrevNextControls({
      element: this.previousBtn,
      onHold: this.fastrewind.bind(this),
      onClick: () => {
        this.killContext();
        this.playlist.selectPrevious();
      }
    });
    this.wirePrevNextControls({
      element: this.nextBtn,
      onHold: this.fastforward.bind(this),
      onClick: () => {
        this.killContext();
        this.playlist.selectNext();
      }
    });

    /* Initialize playlist */
    this.playlist = new Playlist({
      element: document.getElementById("playlist"),
      onItemSelected: this.setMedia.bind(this),
      onItemRemoved: () => {},
      onItemCleared: () => {
        this.UIEnabled = false;
      },
    });

    this.settingsStore = new SettingsStore();
    this.settingsOverlay = new SettingsOverlay({
      store: this.settingsStore,
      element: document.getElementById("settings-overlay"),
      toggle: document.getElementById("settings-btn")
    });

    if (this.isElectron) {
      var ElectronApp = require("./js/ElectronApp");
      ElectronApp.init();
    }
    let fullscreenchange = (e) => {
      document.documentElement.classList.toggle("fullscreen",
        !!(document.fullscreenElement
        || document.webkitFullscreenElement
        || document.msFullscreenElement
        || document.mozFullScreenElement));
    };
    addEventListener("fullscreenchange", fullscreenchange);
    addEventListener("webkitfullscreenchange", fullscreenchange);
    addEventListener("msfullscreenchange", fullscreenchange);
    addEventListener("mozfullscreenchange", fullscreenchange);
    /* Bind functions */
    this.uploadFiles = this.uploadFiles.bind(this);

    /* Setup uploader */
    this.uploadEl.addEventListener("change", () => this.uploadFiles(this.uploadEl.files));

    this.sidebarEl.addEventListener("dragenter", () => {
      this.sidebarEl.classList.remove("no-drag");
      this.sidebarEl.classList.add("drag");
    });
    this.sidebarEl.addEventListener("dragleave", () => {
      this.sidebarEl.classList.remove("drag");
      this.sidebarEl.classList.add("no-drag");
    });
    this.sidebarEl.addEventListener("dragover", (e) => {
      e.preventDefault();
      e.stopPropagation();
    });
    this.sidebarEl.addEventListener("drop", (e) => {
      e.preventDefault();
      e.stopPropagation();
      this.uploadFiles(e.dataTransfer.files);
      this.sidebarEl.classList.remove("drag");
      this.sidebarEl.classList.add("no-drag");
    });

    this.progressBar.addEventListener("mousedown", function(e) {
      this.classList.add("dragging");
      MediaPlayer.onProgressClick(e.pageX);
    });
    this.progressBar.addEventListener("mouseup", (e) => {
      this.progressBar.classList.remove("dragging");
    });
    this.progressBar.addEventListener("mouseover", (e) => {
      if (this.progressBar.classList.contains("dragging")) {
        this.onProgressClick(e.pageX);
      }
    });
    this.progressBar.addEventListener("mouseover", function(e) {
      MediaPlayer.setProgressTooltip(e.pageX);
    });

    this.controlOverlay.addEventListener("click", () => {
      if (!this.UIEnabled) {
        return;
      }
      if (!this.videoEl.hidden) {
        this.togglePaused();
      }
    });

    addEventListener("keydown", (e) => {
      if (document.activeElement != document.body) {
        return;
      }
      switch (e.keyCode) {
        // Spacebar
        case 32:
          this.togglePaused();
          break;
        // Top arrow
        case 38:
          if (e.ctrlKey || e.metaKey) {
            this.changeVolume(Math.min(1, this.videoEl.volume + 0.1));
            e.preventDefault();
          } else {
            this.playlist.selectPrevious();
          }
          break;
        // Down arrow
        case 40:
          if (e.ctrlKey || e.metaKey) {
            this.changeVolume(Math.max(0, this.videoEl.volume - 0.1));
            e.preventDefault();
          } else {
            this.playlist.selectNext();
          }
          break;
        // Left arrow
        case 37:
          this.fastrewind();
          break;
        // Right arrow
        case 39:
          this.fastforward();
          break;
      }
    });
    this.videoEl.addEventListener("timeupdate", function() {
      MediaPlayer.updateProgressBar();
      MediaPlayer.tooltipEl.textContent = MediaPlayer.getTooltip(this.currentTime);
    });
    this.videoEl.addEventListener("play", () => {
      this.playPauseEl.classList.remove("paused");
    });
    this.videoEl.addEventListener("pause", () => {
      this.playPauseEl.classList.add("paused");
    });
    this.videoEl.addEventListener("ended", () => {
      this.killContext();
      this.playlist.selectNext();
    });
    this.initAudioContext();
  },
  set UIEnabled(value) {
    if (!value) {
      this.controlsEl.classList.add("disabled");
      this.headerEl.textContent = "";
      this.headerEl.title = "";
      document.title = "Media Player";
      this.videoEl.hidden = true;
      this.canvasEl.hidden = false;
      this.pause(true);
      this.videoEl.currentTime = 0;
    } else {
      this.controlsEl.classList.remove("disabled");
    }
  },
  get UIEnabled() {
    return !this.controlsEl.classList.contains("disabled");
  },

  toggleFullscreen() {
    let shouldGoFullscreen = !document.documentElement.classList.contains("fullscreen");

    if (shouldGoFullscreen) {
      if (!document.documentElement.requestFullScreen) {
        document.documentElement.requestFullScreen = document.documentElement.mozRequestFullScreen
            || document.documentElement.webkitRequestFullscreen;
      }
      document.documentElement.requestFullScreen();
    } else {
{'fraction_non_alphanumeric': 0.14437428243398392, 'fraction_numerical': 0.0024397244546498277, 'mean_word_length': 2.825693110074115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, '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': '1308158', 'n_tokens_mistral': 3900, 'n_tokens_neox': 3859, 'n_words': 521}