<commit_before>$(document).ready(function () {
  var ua = navigator.userAgent
  if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile|mobile/i.test(ua)) {
    document.querySelector("#mute").checked = true;
    document.querySelector('#player').muted = true;
  }
  else{
    document.querySelector("#mute").checked = false;
    document.querySelector('#player').muted = false;
  }
  
  if (navigator.language.indexOf('ja') == 0) {
    $('#searchBtn').contents().last()[0].textContent = ' 検索'
    $('#safeBtn').contents().last()[0].textContent = ' セーフサーチ'
    $('#flipBtn').contents().last()[0].textContent = ' 反転'
    $('.btn-file').contents().first()[0].textContent = 'ファイル選択'
    $('#autoplay').parent().contents().last()[0].textContent = '自動再生'
    $('#loop').parent().contents().last()[0].textContent = 'ループ'
    $('#mute').parent().contents().last()[0].textContent = 'ミュート'
    $('#fitWidthRadio').parent().contents().last()[0].textContent = '横幅設定'
    $('#fitHeightRadio').parent().contents().last()[0].textContent = '縦幅設定'
    $('#imageURL').attr('placeholder', '画像 URL')
  }
  if (navigator.language.toLocaleLowerCase() == 'zh-cn') {
    $('#searchBtn').contents().last()[0].textContent = ' 搜寻'
    $('#safeBtn').contents().last()[0].textContent = ' 安全过滤'
    $('#flipBtn').contents().last()[0].textContent = ' 反转'
    $('.btn-file').contents().first()[0].textContent = '选取档案'
    $('#autoplay').parent().contents().last()[0].textContent = '自动播放'
    $('#loop').parent().contents().last()[0].textContent = '循环播放'
    $('#mute').parent().contents().last()[0].textContent = '静音'
    $('#fitWidthRadio').parent().contents().last()[0].textContent = '符合宽度'
    $('#fitHeightRadio').parent().contents().last()[0].textContent = '符合高度'
    $('#imageURL').attr('placeholder', '图片网址')
    $('#instruction').text(' / 拖放图片至上方 / Ctrl+V 贴上 / 输入图片网址')
  }
  else if (navigator.language.indexOf('zh') == 0) {
    $('#searchBtn').contents().last()[0].textContent = ' 搜尋'
    $('#safeBtn').contents().last()[0].textContent = ' 安全過濾'
    $('#flipBtn').contents().last()[0].textContent = ' 反轉'
    $('.btn-file').contents().first()[0].textContent = '選取檔案'
    $('#autoplay').parent().contents().last()[0].textContent = '自動播放'
    $('#loop').parent().contents().last()[0].textContent = '循環播放'
    $('#mute').parent().contents().last()[0].textContent = '靜音'
    $('#fitWidthRadio').parent().contents().last()[0].textContent = '乎合寬度'
    $('#fitHeightRadio').parent().contents().last()[0].textContent = '乎合高度'
    $('#imageURL').attr('placeholder', '圖片網址')
    $('#instruction').text(' / 拖放圖片至上方 / Ctrl+V 貼上 / 輸入圖片網址')
  }

  document.querySelector("#autoplay").checked = true;
  document.querySelector("#loop").checked = false;

  location.search.substr(1).split('&').forEach(function(param){
    let key = param.split('=')[0];
    let val = param.split('=')[1];
    if (key === "autoplay") {
      document.querySelector("#autoplay").checked = val !== "0" ? true : false;
    }
    if (key === "mute") {
      document.querySelector("#mute").checked = val !== "0" ? true : false;
    }
    if (key === "loop") {
      document.querySelector("#loop").checked = val !== "0" ? true : false;
    }
  });

  document.querySelector("#autoplay").onchange = updateURLParam;
  document.querySelector("#mute").onchange = updateURLParam;
  document.querySelector("#loop").onchange = updateURLParam;
})

var updateURLParam = function(){
  let urlString = '';
  let params = [];
  if(document.querySelector("#autoplay").checked !== true){
    params.push("autoplay=0");
  }
  if(document.querySelector("#mute").checked === true){
    params.push("mute");
  }
  if(document.querySelector("#loop").checked === true){
    params.push("loop");
  }
  urlString += params.sort().join('&');
  if(document.querySelector("#imageURL").value){
    if(params.length > 0){
      urlString += '&';
    }
    urlString += 'url='+encodeURI(document.querySelector("#imageURL").value.replace(/ /g,'%20'))
  }
  if(urlString.length > 0){
    history.replaceState(null,null,'/?'+urlString);
  }
  else{
    history.replaceState(null,null,'/');
  }
}

var formatTime = function (timeInSeconds) {
  var sec_num = parseInt(timeInSeconds, 10)
  var hours = Math.floor(sec_num / 3600)
  var minutes = Math.floor((sec_num - (hours * 3600)) / 60)
  var seconds = sec_num - (hours * 3600) - (minutes * 60)

  if (hours < 10) {hours = '0' + hours;}
  if (minutes < 10) {minutes = '0' + minutes;}
  if (seconds < 10) {seconds = '0' + seconds;}
  var timestring = hours + ':' + minutes + ':' + seconds

  return timestring
}

function zeroPad (n, width, z) {
  z = z || '0'
  n = n + ''
  return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n
}

var player = document.querySelector('#player')
var preview = document.querySelector('#preview')
var autoSearch = document.querySelector('#autoSearch')
var originalImage = document.querySelector('#originalImage')
var fitWidth = true
var firstPlay = true

var safeSearch = false
var imgDataURL
var searchRequest
var search = function (trial, prev_result) {
  if (!trial) trial = 4;
  if (searchRequest && searchRequest.readyState != 4) {
    searchRequest.abort()
  }
  preview.classList.remove('movable')
  document.querySelector('#loading').classList.remove('hidden')
  document.querySelector('#searchBtn span').classList.remove('glyphicon-search')
  document.querySelector('#searchBtn span').classList.add('glyphicon-refresh')
  document.querySelector('#searchBtn span').classList.add('spinning')
  if (document.querySelector('#search2Btn span')) {
    document.querySelector('#search2Btn span').classList.remove('glyphicon-search')
    document.querySelector('#search2Btn span').classList.add('glyphicon-refresh')
    document.querySelector('#search2Btn span').classList.add('spinning')
  }
  resetInfo()
  animeInfo = ''
  document.querySelector('#player').pause()
  preview.removeEventListener('click', playPause)
  if (!trial) document.querySelector('#results').innerHTML = '<div id="status">Submitting image for searching...</div>'
  document.querySelector('#searchBtn').disabled = true
  if (document.querySelector('#search2Btn span')) document.querySelector('#search2Btn').disabled = true
  document.querySelector('#flipBtn').disabled = true
  document.querySelector('#imageURL').disabled = true
  
  searchRequest = $.post('/search',
    {'data': imgDataURL, 'filter': document.querySelector('#seasonSelector').value, 'trial': trial}, function (data, textStatus) {
      document.querySelector('#loading').classList.add('hidden')
      document.querySelector('#searchBtn').disabled = false
      if (document.querySelector('#search2Btn span')) document.querySelector('#search2Btn').disabled = false
      document.querySelector('#flipBtn').disabled = false
      document.querySelector('#imageURL').disabled = false<commit_msg>Fix UI text on first search<commit_after>$(document).ready(function () {
  var ua = navigator.userAgent
  if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile|mobile/i.test(ua)) {
    document.querySelector("#mute").checked = true;
    document.querySelector('#player').muted = true;
  }
  else{
    document.querySelector("#mute").checked = false;
    document.querySelector('#player').muted = false;
  }
  
  if (navigator.language.indexOf('ja') == 0) {
    $('#searchBtn').contents().last()[0].textContent = ' 検索'
    $('#safeBtn').contents().last()[0].textContent = ' セーフサーチ'
    $('#flipBtn').contents().last()[0].textContent = ' 反転'
    $('.btn-file').contents().first()[0].textContent = 'ファイル選択'
    $('#autoplay').parent().contents().last()[0].textContent = '自動再生'
    $('#loop').parent().contents().last()[0].textContent = 'ループ'
    $('#mute').parent().contents().last()[0].textContent = 'ミュート'
    $('#fitWidthRadio').parent().contents().last()[0].textContent = '横幅設定'
    $('#fitHeightRadio').parent().contents().last()[0].textContent = '縦幅設定'
    $('#imageURL').attr('placeholder', '画像 URL')
  }
  if (navigator.language.toLocaleLowerCase() == 'zh-cn') {
    $('#searchBtn').contents().last()[0].textContent = ' 搜寻'
    $('#safeBtn').contents().last()[0].textContent = ' 安全过滤'
    $('#flipBtn').contents().last()[0].textContent = ' 反转'
    $('.btn-file').contents().first()[0].textContent = '选取档案'
    $('#autoplay').parent().contents().last()[0].textContent = '自动播放'
    $('#loop').parent().contents().last()[0].textContent = '循环播放'
    $('#mute').parent().contents().last()[0].textContent = '静音'
    $('#fitWidthRadio').parent().contents().last()[0].textContent = '符合宽度'
    $('#fitHeightRadio').parent().contents().last()[0].textContent = '符合高度'
    $('#imageURL').attr('placeholder', '图片网址')
    $('#instruction').text(' / 拖放图片至上方 / Ctrl+V 贴上 / 输入图片网址')
  }
  else if (navigator.language.indexOf('zh') == 0) {
    $('#searchBtn').contents().last()[0].textContent = ' 搜尋'
    $('#safeBtn').contents().last()[0].textContent = ' 安全過濾'
    $('#flipBtn').contents().last()[0].textContent = ' 反轉'
    $('.btn-file').contents().first()[0].textContent = '選取檔案'
    $('#autoplay').parent().contents().last()[0].textContent = '自動播放'
    $('#loop').parent().contents().last()[0].textContent = '循環播放'
    $('#mute').parent().contents().last()[0].textContent = '靜音'
    $('#fitWidthRadio').parent().contents().last()[0].textContent = '乎合寬度'
    $('#fitHeightRadio').parent().contents().last()[0].textContent = '乎合高度'
    $('#imageURL').attr('placeholder', '圖片網址')
    $('#instruction').text(' / 拖放圖片至上方 / Ctrl+V 貼上 / 輸入圖片網址')
  }

  document.querySelector("#autoplay").checked = true;
  document.querySelector("#loop").checked = false;

  location.search.substr(1).split('&').forEach(function(param){
    let key = param.split('=')[0];
    let val = param.split('=')[1];
    if (key === "autoplay") {
      document.querySelector("#autoplay").checked = val !== "0" ? true : false;
    }
    if (key === "mute") {
      document.querySelector("#mute").checked = val !== "0" ? true : false;
    }
    if (key === "loop") {
      document.querySelector("#loop").checked = val !== "0" ? true : false;
    }
  });

  document.querySelector("#autoplay").onchange = updateURLParam;
  document.querySelector("#mute").onchange = updateURLParam;
  document.querySelector("#loop").onchange = updateURLParam;
})

var updateURLParam = function(){
  let urlString = '';
  let params = [];
  if(document.querySelector("#autoplay").checked !== true){
    params.push("autoplay=0");
  }
  if(document.querySelector("#mute").checked === true){
    params.push("mute");
  }
  if(document.querySelector("#loop").checked === true){
    params.push("loop");
  }
  urlString += params.sort().join('&');
  if(document.querySelector("#imageURL").value){
    if(params.length > 0){
      urlString += '&';
    }
    urlString += 'url='+encodeURI(document.querySelector("#imageURL").value.replace(/ /g,'%20'))
  }
  if(urlString.length > 0){
    history.replaceState(null,null,'/?'+urlString);
  }
  else{
    history.replaceState(null,null,'/');
  }
}

var formatTime = function (timeInSeconds) {
  var sec_num = parseInt(timeInSeconds, 10)
  var hours = Math.floor(sec_num / 3600)
  var minutes = Math.floor((sec_num - (hours * 3600)) / 60)
  var seconds = sec_num - (hours * 3600) - (minutes * 60)

  if (hours < 10) {hours = '0' + hours;}
  if (minutes < 10) {minutes = '0' + minutes;}
  if (seconds < 10) {seconds = '0' + seconds;}
  var timestring = hours + ':' + minutes + ':' + seconds

  return timestring
}

function zeroPad (n, width, z) {
  z = z || '0'
  n = n + ''
  return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n
}

var player = document.querySelector('#player')
var preview = document.querySelector('#preview')
var autoSearch = document.querySelector('#autoSearch')
var originalImage = document.querySelector('#originalImage')
var fitWidth = true
var firstPlay = true

var safeSearch = false
var imgDataURL
var searchRequest
var search = function (trial, prev_result) {
  if (!trial) trial = 4;
  if (searchRequest && searchRequest.readyState != 4) {
    searchRequest.abort()
  }
  preview.classList.remove('movable')
  document.querySelector('#loading').classList.remove('hidden')
  document.querySelector('#searchBtn span').classList.remove('glyphicon-search')
  document.querySelector('#searchBtn span').classList.add('glyphicon-refresh')
  document.querySelector('#searchBtn span').classList.add('spinning')
  if (document.querySelector('#search2Btn span')) {
    document.querySelector('#search2Btn span').classList.remove('glyphicon-search')
    document.querySelector('#search2Btn span').classList.add('glyphicon-refresh')
    document.querySelector('#search2Btn span').classList.add('spinning')
  }
  resetInfo()
  animeInfo = ''
  document.querySelector('#player').pause()
  preview.removeEventListener('click', playPause)
  if (trial === 4) document.querySelector('#results').innerHTML = '<div id="status">Submitting image for searching...</div>'
  document.querySelector('#searchBtn').disabled = true
  if (document.querySelector('#search2Btn span')) document.querySelector('#search2Btn').disabled = true
  document.querySelector('#flipBtn').disabled = true
  document.querySelector('#imageURL').disabled = true
  
  searchRequest = $.post('/search',
    {'data': imgDataURL, 'filter': document.querySelector('#seasonSelector').value, 'trial': trial}, function (data, textStatus) {
      document.querySelector('#loading').classList.add('hidden')
      document.querySelector('#searchBtn').disabled = false
      if (document.querySelector('#search2Btn span')) document.querySelector('#search2Btn').disabled = false
      document.querySelector('#flipBtn').disabled = false
      document.querySelector('#imageURL').disabled = false
{'fraction_non_alphanumeric': 0.21292996872954695, 'fraction_numerical': 0.011562795433059414, 'mean_word_length': 4.659259259259259, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6758833', 'n_tokens_mistral': 4405, 'n_tokens_neox': 4577, 'n_words': 685}