scriptStartPage.js.map 27.2 KB
Newer Older
1
{"version":3,"sources":["scriptStartPage.js","results.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACncA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"scriptStartPage.js","sourcesContent":["$(document).ready(function () {\n  // checkPlugin()\n  if (location.href.indexOf('#plugin-modal') > -1) {\n    $('#plugin-modal').modal('show');\n  }\n  $('#addFocusBtn').removeClass('hide');\n  $('button').popover();\n  if (localStorage) {\n    var theme = localStorage.getItem('theme');\n    if (theme != null) {\n      if ((theme.match(/,/g) || []).length != 3) {\n        localStorage.removeItem('theme');\n      } else {\n        theme = theme.split(',');\n        $('#theme').attr('href', '/css/theme.css.php?r=' + theme[0] + '&g=' + theme[1] + '&b=' + theme[2] + '&a=' + theme[3]);\n      }\n    }\n    if (localStorage.getItem('pers') && !isUseOnce()) {\n      setSettings();\n    }\n  }\n  setActionListeners();\n  loadInitialCustomFocuses();\n  loadSavedResults();\n});\n\nfunction setActionListeners () {\n  $('button').on('shown.bs.popover', function () {\n    $('#color-chooser a').click(function () {\n      var theme = $(this).attr('data-rgba');\n      if (localStorage) {\n        localStorage.setItem('theme', theme);\n        location.href = '/';\n      }\n    });\n  });\n  $('#mobileFoki').change(function () {\n    var focus = $('#mobileFoki > option:selected').val();\n    if (focus == 'angepasst') {\n      window.location = './settings/';\n    } else {\n      window.location = './?focus=' + focus;\n    }\n  });\n  if ($('fieldset#foki.mobile').length) {\n    $('fieldset#foki.mobile label#anpassen-label').click(function () {\n      window.location = './settings/';\n    });\n  }\n  $('#addFocusBtn').click(function () {\n    showFocusCreateDialog('');\n  });\n  $('#save-focus-btn').click(saveFocus);\n  $('#delete-focus-btn').click(deleteFocus);\n  $('#focus-name').keyup(function (event) {\n    if (event.keyCode == 13) {\n      $('#save-focus-btn').click();\n    }\n  });\n  $('#create-focus-modal').on('shown.bs.modal', function () {\n    $('#focus-name').focus();\n  });\n}\n\nfunction setSettings () {\n  for (var i = 0; i < localStorage.length; i++) {\n    var key = localStorage.key(i);\n    var value = localStorage.getItem(key);\n    if (key.startsWith('param_') && !key.endsWith('lang') && !key.endsWith('autocomplete')) {\n      key = key.substring(key.indexOf('param_') + 6);\n      $('#searchForm').append('<input type=\"hidden\" name=\"' + key + '\" value=\"' + value + '\">');\n    }\n    $('#foki input[type=radio]#angepasst').attr('checked', true);\n  }\n  if (localStorage.getItem('param_lang') !== null) {\n    var value = localStorage.getItem('param_lang');\n    // Change the value of the lang input field to the given parameter\n    $('input[name=lang]').val(value);\n  }\n  if (localStorage.getItem('param_autocomplete') !== null) {\n    var value = localStorage.getItem('param_autocomplete');\n    // Change the value of the lang input field to the given parameter\n    $('input[name=eingabe]').attr('autocomplete', value);\n  }\n  if ($('fieldset#foki.mobile').length) {\n    $('fieldset.mobile input#bilder').val('angepasst');\n    $('fieldset.mobile input#bilder').prop('checked', true);\n    $('fieldset.mobile input#bilder').attr('id', 'angepasst');\n    $('fieldset.mobile label#bilder-label').attr('id', 'anpassen-label');\n    $('fieldset.mobile label#anpassen-label').attr('for', 'angepasst');\n    $('fieldset.mobile label#anpassen-label i.fa').attr('class', 'fa fa-cog');\n    $('fieldset.mobile label#anpassen-label span.content').html('angepasst');\n  }\n}\n// Polyfill for form attribute\n(function ($) {\n  /**\n   * polyfill for html5 form attr\n   */\n  // detect if browser supports this\n  var sampleElement = $('[form]').get(0);\n  var isIE11 = !(window.ActiveXObject) && 'ActiveXObject' in window;\n  if (sampleElement && window.HTMLFormElement && sampleElement.form instanceof HTMLFormElement && !isIE11) {\n    // browser supports it, no need to fix\n    return;\n  }\n  /**\n   * Append a field to a form\n   *\n   */\n  $.fn.appendField = function (data) {\n    // for form only\n    if (!this.is('form')) return;\n    // wrap data\n    if (!$.isArray(data) && data.name && data.value) {\n      data = [data];\n    }\n    var $form = this;\n    // attach new params\n    $.each(data, function (i, item) {\n      $('<input/>').attr('type', 'hidden').attr('name', item.name).val(item.value).appendTo($form);\n    });\n    return $form;\n  };\n  /**\n   * Find all input fields with form attribute point to jQuery object\n   * \n   */\n  $('form[id]').submit(function (e) {\n    var $form = $(this);\n    // serialize data\n    var data = $('[form=' + $form.attr('id') + ']').serializeArray();\n    // append data to form\n    $form.appendField(data);\n  }).each(function () {\n    var form = this,\n      $form = $(form),\n      $fields = $('[form=' + $form.attr('id') + ']');\n    $fields.filter('button, input').filter('[type=reset],[type=submit]').click(function () {\n      var type = this.type.toLowerCase();\n      if (type === 'reset') {\n        // reset form\n        form.reset();\n        // for elements outside form\n        $fields.each(function () {\n          this.value = this.defaultValue;\n          this.checked = this.defaultChecked;\n        }).filter('select').each(function () {\n          $(this).find('option').each(function () {\n            this.selected = this.defaultSelected;\n          });\n        });\n      } else if (type.match(/^submit|image$/i)) {\n        $(form).appendField({\n          name: this.name,\n          value: this.value\n        }).submit();\n      }\n    });\n  });\n})(jQuery);\n// Opera 8.0+\nvar isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;\n// Firefox 1.0+\nvar isFirefox = typeof InstallTrigger !== 'undefined';\n// At least Safari 3+: \"[object HTMLElementConstructor]\"\nvar isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;\n// Internet Explorer 6-11\nvar isIE = /*@cc_on!@*/ false || !!document.documentMode;\n// Edge 20+\nvar isEdge = !isIE && !!window.StyleMedia;\n// Chrome 1+\nvar isChrome = !!window.chrome && !!window.chrome.webstore;\n// Blink engine detection\nvar isBlink = (isChrome || isOpera) && !!window.CSS;\n// Prüft, ob der URL-Parameter \"usage\" auf \"once\" gesetzt ist.\nfunction isUseOnce () {\n  var url = document.location.search;\n  var pos = url.indexOf('usage=');\n  if (pos >= 0 && url.substring(pos + 6, pos + 11) == 'once') {\n    return true;\n  } else {\n    return false;\n  }\n}\n/**\n * Loads all the custom focuses stored in local storage\n */\nfunction loadInitialCustomFocuses () {\n  for (var key in localStorage) {\n    if (key.startsWith('focus_')) {\n      var focus = loadFocusById(key);\n      addFocus(focus.name);\n    }\n  }\n}\n/**\n * Shows the focus create dialog\n * If an id is given it will try to load a focus for the given id\n */\nfunction showFocusCreateDialog (id) {\n  if (id === undefined) {\n    id = '';\n  }\n  document.getElementById('original-id').value = id;\n  $('#create-focus-modal').modal('show');\n  var storedFocus = loadFocusById(id);\n  var focus = {};\n  // Try to load a focus for the given id\n  $('#focus-name').val('');\n  uncheckAll();\n  if (storedFocus !== null) {\n    try {\n      focus = JSON.parse(localStorage.getItem(id));\n      $('#focus-name').val(focus.name);\n      for (var key in focus) {\n        if (key.startsWith('engine_')) {\n          $('.focusCheckbox[name=' + key + ']').prop('checked', true);\n        }\n      }\n    } catch (ex) {\n      console.error(ex);\n    }\n  }\n}\n/**\n * Shows the focus create dialog for a given id\n */\nfunction showFocusEditDialog (id) {\n  showFocusCreateDialog(id);\n}\n/**\n * Save the current Focus\n * Listens for save button\n */\nfunction saveFocus () {\n  var name = document.getElementById('focus-name').value;\n  if (isValidName(name) && atLeastOneChecked()) {\n    var oldId = document.getElementById('original-id').value;\n    var id = getIdFromName(name);\n    var overwrite = true;\n    if (alreadyInUse(name) && oldId !== id) {\n      overwrite = confirm('Name bereits genutzt\\nüberschreiben?');\n      if (overwrite) {\n        localStorage.removeItem(id);\n        removeFocusById(id);\n      }\n    }\n    if (overwrite) {\n      var focus = {};\n      $('input[type=checkbox]:checked').each(function (el) {\n        focus[$(this).attr('name')] = $(this).val();\n      });\n      focus['name'] = name;\n      if (oldId !== '') {\n        localStorage.removeItem(oldId);\n        removeFocusById(oldId);\n      }\n      localStorage.setItem(id, JSON.stringify(focus));\n      addFocus(name);\n      $('#create-focus-modal').modal('hide');\n    }\n  } else {\n    alert('Bitte gültigen Namen eingeben:\\n* Keine Sonderzeichen\\n* Mindestens 1 Buchstabe\\n* Mindestens 1 Suchmaschine auswählen');\n  }\n}\n/**\n * Delete current Focus\n * Listens for delete button\n */\nfunction deleteFocus () {\n  var oldId = document.getElementById('original-id').value;\n  if ($('#' + oldId).prop('checked')) {\n    setFocusToDefault();\n  }\n  localStorage.removeItem(oldId);\n  removeFocusById(oldId);\n  $('#create-focus-modal').modal('hide');\n}\n/**\n * Is the name valid (in terms of characters)?\n */\nfunction isValidName (name) {\n  // no Characters other then a-z, A-Z, 0-9, ä, ö, ü, ß, -, _ allowed\n  // at least 1 character\n  return /^[a-zA-Z0-9äöüß\\-_ ]*$/.test(name);\n}\n/**\n * Is at least one focus selected?\n */\nfunction atLeastOneChecked () {\n  return $('input[type=checkbox]:checked').length > 0;\n}\n/**\n * Is there already a focus with this name?\n */\nfunction alreadyInUse (name) {\n  return localStorage.hasOwnProperty(getIdFromName(name));\n}\n/**\n * Adds a focus html-element to the focus selection\n * \n * <input id=\"NAME\" class=\"hide\" type=\"radio\" name=\"focus\" value=\"NAME\" form=\"searchForm\" checked required>\n * <label id=\"NAME-label\" for=\"NAME\">\n *     <i class=\"fa fa-star\" aria-hidden=\"true\"></i>\n *     <span class=\"content\">NAME</span>\n *     <button class=\"btn btn-default\">\n *         <i class=\"fa fa-pencil\" aria-hidden=\"true\"></i>\n *     </button>\n * </label>\n */\nfunction addFocus (name) {\n  var id = getIdFromName(name);\n  var foki = document.getElementById('foki');\n  // create <div> to wrap all Elements\n  var wrapper = document.createElement('div');\n  wrapper.classList.add('focus');\n  // create <input>\n  var newFocus = document.createElement('input');\n  newFocus.id = id;\n  newFocus.classList.add('focus-radio');\n  newFocus.classList.add('custom-focus');\n  newFocus.classList.add('hide');\n  newFocus.type = 'radio';\n  newFocus.name = 'focus';\n  newFocus.value = id;\n  newFocus.setAttribute('Form', 'searchForm');\n  newFocus.checked = true;\n  newFocus.required = true;\n  // create <label>\n  var newFocusLabel = document.createElement('label');\n  newFocusLabel.id = id + '-label';\n  newFocusLabel.classList.add('focus-label');\n  newFocusLabel.classList.add('custom-focus-label');\n  newFocusLabel.htmlFor = id;\n  // create <i> icon\n  var newFocusIcon = document.createElement('i');\n  newFocusIcon.classList.add('fa');\n  newFocusIcon.classList.add('fa-star');\n  newFocusIcon.setAttribute('aria-hidden', 'true');\n  // create content\n  var newFocusContent = document.createElement('span');\n  newFocusIcon.classList.add('content');\n  newFocusContent.textContent = ' ' + name;\n  // create edit button\n  var newFocusEditLink = document.createElement('a');\n  newFocusEditLink.classList.add('focus-edit');\n  newFocusEditLink.classList.add('custom-focus-edit');\n  newFocusEditLink.classList.add('mutelink');\n  newFocusEditLink.href = '#';\n  newFocusEditLink.onclick = function () {\n    showFocusEditDialog(id);\n  };\n  var newFocusEditLinkIcon = document.createElement('i');\n  newFocusEditLinkIcon.classList.add('fa');\n  newFocusEditLinkIcon.classList.add('fa-pencil');\n  newFocusEditLinkIcon.setAttribute('aria-hidden', 'true');\n  // add new elements\n  var addFocusBtn = document.getElementById('addFocusBtnDiv');\n  foki.insertBefore(wrapper, addFocusBtn);\n  wrapper.appendChild(newFocus);\n  wrapper.appendChild(newFocusLabel);\n  newFocusLabel.appendChild(newFocusIcon);\n  newFocusLabel.appendChild(newFocusContent);\n  wrapper.appendChild(newFocusEditLink);\n  newFocusEditLink.appendChild(newFocusEditLinkIcon);\n}\n/**\n * Remove the focuses html-elements\n */\nfunction removeFocus (name) {\n  removeFocusById(getIdFromName(name));\n}\n/**\n * Remove the focuses html-elements\n */\nfunction removeFocusById (id) {\n  var focusRadio = document.getElementById(id);\n  var focus = focusRadio.parentNode;\n  var parent = focus.parentNode;\n  parent.removeChild(focus);\n}\n/**\n * Turns a name into an id\n * Converts special characters and spaces\n */\nfunction getIdFromName (name) {\n  name = name.toLowerCase();\n  name = name.split(' ').join('_');\n  name = name.split('ä').join('ae');\n  name = name.split('ö').join('oe');\n  name = name.split('ü').join('ue');\n  return 'focus_' + name;\n}\n/**\n * Loads the focus object for the given id from local storage\n */\nfunction loadFocusById (id) {\n  return JSON.parse(localStorage.getItem(id));\n}\n/**\n * Unchecks all focuses from the focus creator dialog\n */\nfunction uncheckAll () {\n  $('.focusCheckbox').prop('checked', false);\n}\n/**\n * Resets all settings\n */\nfunction resetOptions () {\n  localStorage.removeItem('pers');\n  var keys = [];\n  for (var i = 0; i < localStorage.length; i++) {\n    var key = localStorage.key(i);\n    keys.push(key);\n  }\n  for (var i = 0; i < keys.length; i++) {\n    var key = keys[i];\n    if (key.startsWith('param_' || key.startsWith('focus'))) {\n      localStorage.removeItem(key);\n    }\n  }\n}\n\nfunction setFocusToDefault () {\n  setFocus('web');\n}\n\nfunction setFocus (focusID) {\n  $('#' + focusID).prop('checked', true);\n}\n\nfunction loadSavedResults() {\n  var results = new Results();\n  if(results.length > 0){\n    var html = $('\\\n    <div class=\"focus\">\\\n      <input id=\"savedResults\" class=\"focus-radio hide\" name=\"focus\" value=\"container\" form=\"searchForm\" type=\"radio\" required=\"\">\\\n      <label id=\"saved-results-label\" class=\"focus-label\" for=\"savedResults\">\\\n        <span class=\"glyphicon glyphicon-floppy-disk\"></span>\\\n        <span class=\"content\">gespeicherte Ergebnisse</span>\\\n        <span class=\"badge\">' + results.length + '</span>\\\n      </label>\\\n    </div>\\\n    ');\n    $(\"#addFocusBtnDiv\").before(html);\n    $(\"#foki input#savedResults\").change(function(){\n      if($(this).prop(\"checked\")) $(\"#searchForm\").submit();\n    });\n  }\n}\n","/*\n * This object gathers all stored Result Objects and can Update the Interface to show them.\n*/\nfunction Results(sort){\n  if(!localStorage) return;\n  this.prefix = \"result_\";\n  this.results = [];\n  this.updateResults();\n  this.length = this.results.length;\n  this.sortResults(sort);\n}\n\nResults.prototype.sortResults = function(sortType){\n  if(sortType === undefined) sortType = \"chronological\";\n  switch(sortType){\n    case \"chronological\":\n      this.results.sort(function(a,b){\n        if(a.added > b.added) return -1;\n        if(a.added < b.added) return 1;\n        return 0;\n      });\n      break;\n    case \"rank\":\n      this.results.sort(function(a,b){\n        if(a.rank > b.rank) return -1;\n        if(a.rank < b.rank) return 1;\n        return 0;\n      });\n      break;\n    case \"alphabetical\":\n      this.results.sort(function(a,b){\n        if(b.hostname > a.hostname) return -1;\n        if(b.hostname < a.hostname) return 1;\n        return 0;\n      });\n      break;\n  }\n}\n\nResults.prototype.updateResults = function(){\n  // Iterate over all Keys in the LocalStorage\n  for(var i = 0; i < localStorage.length; i++){\n    if(localStorage.key(i).indexOf(this.prefix) === 0){\n      var key = localStorage.key(i);\n      key = key.substr(this.prefix.length);\n      var tmpResult = new Result(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, key);\n      tmpResult.setIndex(i);\n      this.results.push(tmpResult);\n    }\n  }\n}\n\nResults.prototype.deleteResults = function(){\n  var keys = [];\n  for(var i = 0; i < localStorage.length; i++){\n    if(localStorage.key(i).indexOf(this.prefix) === 0){\n      var key = localStorage.key(i);\n      keys.push(key);\n    }\n  }\n  $.each(keys, function(index, value){\n    localStorage.removeItem(value);\n  });\n}\n\nResults.prototype.updateResultPageInterface = function(sortType){\n  if(this.results.length === 0){\n    $(\"#savedFokiTabSelector, #savedFoki\").remove();\n    $($(\"#foki > li[data-loaded=1]\").get(0)).find(\">a\").tab(\"show\");\n    return;\n  }\n  if($(\"#savedFokiTabSelector\").length === 0){\n    var savedFoki = $('\\\n      <li id=\"savedFokiTabSelector\" data-loaded=\"1\" class=\"tab-selector\" role=\"presentation\">\\\n        <a aria-controls=\"savedFoki\" href=\"#savedFoki\" role=\"tab\" data-toggle=\"tab\">\\\n          <span class=\"glyphicon glyphicon-floppy-disk\"></span> gespeicherte Ergebnisse\\\n          <span class=\"badge\">' + this.results.length + '</span>\\\n        </a>\\\n      </li>\\\n      ');\n    $(\"#foki\").append(savedFoki);\n  }else{\n    $(\"#savedFokiTabSelector span.badge\").html(this.results.length);\n  }\n    if($(\"#savedFoki\").length === 0){\n      // Now append the Tab Panel\n      var tabPanel = $('\\\n        <div role=\"tabpanel\" class=\"tab-pane\" id=\"savedFoki\">\\\n        </div>\\\n        ');\n      $(\"#main-content-tabs\").append(tabPanel);\n    }else{\n      $(\"#savedFoki\").html(\"\");\n      var tabPanel = $(\"#savedFoki\");\n    }\n    this.addToContainer(tabPanel, sortType);\n}\n\nResults.prototype.addToContainer = function(container, sortType){\n  $.each(this.results, function(index, result){\n    $(container).append(result.toHtml());\n  });\n\n  var options = $('\\\n      <div class=\"saver-options row\">\\\n          <input class=\"form-control\" type=\"text\" placeholder=\"Filtern\">\\\n          <select class=\"form-control\">\\\n            <option value=\"chronological\">Chronologisch</option>\\\n            <option value=\"rank\">MetaGer-Ranking</option>\\\n            <option value=\"alphabetical\">Alphabetisch (Hostname)</option>\\\n          </select>\\\n          <button class=\"btn btn-danger btn-md\"><span class=\"glyphicon glyphicon-trash\"></span> <span class=\"hidden-xs\">Ergebnisse</span> löschen</button>\\\n      </div>\\\n    ');\n\n  $(options).find(\"option[value=\" + sortType + \"]\").prop(\"selected\", true);\n\n  $(container).prepend(options);\n\n  $(options).find(\"select\").change(function(){\n    new Results($(this).val()).updateResultPageInterface();\n  });\n\n  $(options).find(\"button\").click({caller: this}, function(event){\n      event.data.caller.deleteResults();\n      new Results().updateResultPageInterface();\n  });\n\n  $(options).find(\"input\").keyup(function(){\n    var search = $(this).val();\n    $(\"#savedFoki > div.result\").each(function(index, value){\n      var html = $(this).html();\n      if(html.toLowerCase().indexOf(search.toLowerCase()) === -1){\n        $(value).addClass(\"hidden\");\n      }else{\n        $(value).removeClass(\"hidden\");\n      }\n    });\n  });\n\n}\n\nfunction Result(title, link, anzeigeLink, gefVon, hoster, anonym, description, color, rank, hash){\n  this.prefix = \"result_\";  // Präfix for the localStorage so we can find all Items\n\n  if(hash !== null && hash !== undefined){\n    this.hash = hash;\n    this.load();\n  }else{\n    this.hash = MD5(title + link + anzeigeLink + gefVon + hoster + anonym + description);\n\n    this.title = title;\n    this.link = link;\n    this.anzeigeLink = anzeigeLink;\n    this.gefVon = gefVon;\n    this.hoster = hoster;\n    this.anonym = anonym;\n    this.description = description;\n    this.color = color;\n    this.rank = rank;\n    this.added = new Date().getTime();\n    var parser = document.createElement('a');\n    parser.href = this.anzeigeLink;\n    this.hostname = parser.hostname;\n    this.save()\n  }\n}\n\nResult.prototype.load = function(){\n  if(localStorage){\n    var result = localStorage.getItem(this. prefix + this.hash);\n    if(result === null) return false;\n    result = b64DecodeUnicode(result);\n    result = JSON.parse(result);\n    this.title = result.title;\n    this.link = result.link;\n    this.anzeigeLink = result.anzeigeLink;\n    this.gefVon = result.gefVon;\n    this.hoster = result.hoster;\n    this.anonym = result.anonym;\n    this.description = result.description;\n    this.added = result.added;\n    this.color = result.color;\n    this.rank = result.rank;\n    this.hostname = result.hostname;\n    return true;\n  }else{\n    return false;\n  }\n}\n\nResult.prototype.save = function(){\n  /*\n  * This function will save the data of this Result to the LocalStorage\n  */\n  if(localStorage){\n\n    var result = {\n      title: this.title,\n      link: this.link,\n      anzeigeLink: this.anzeigeLink,\n      gefVon: this.gefVon,\n      hoster: this.hoster,\n      anonym: this.anonym,\n      description: this.description,\n      added: this.added,\n      color: this.color,\n      rank: this.rank,\n      hostname: this.hostname\n    };\n\n    result = JSON.stringify(result);\n    result = b64EncodeUnicode(result);\n\n    localStorage.setItem(this.prefix + this.hash, result);\n\n    return true;\n  }else{\n    return false;\n  }\n}\n\nfunction b64EncodeUnicode(str) {\n    return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {\n        return String.fromCharCode('0x' + p1);\n    }));\n}\n\nfunction b64DecodeUnicode(str) {\n    return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) {\n        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);\n    }).join(''));\n}\n\n\nResult.prototype.setIndex = function(index){\n  this.index = index;\n}\n\nResult.prototype.remove = function(){\n  localStorage.removeItem(this.prefix + this.hash);\n  new Results().updateResultPageInterface();\n}\n\nResult.prototype.toHtml = function(){\n  var result = $('\\\n    <div class=\"result row\">\\\n      <div class=\"col-sm-1 glyphicon glyphicon-trash remover\" title=\"Ergebnis aus dem Speicher löschen\">\\\n      </div>\\\n      <div class=\"resultInformation col-xs-12 col-sm-11\">\\\n        <div class=\"col-xs-10 col-sm-11\" style=\"padding:0; \">\\\n          <p class=\"title\">\\\n            <a class=\"title\" href=\"' + this.link + '\" target=\"_blank\" data-hoster=\"' + this.hoster + '\" data-count=\"1\" rel=\"noopener\">\\\n              ' + this.title + '\\\n            </a>\\\n          </p>\\\n          <div class=\"link\">\\\n            <div>\\\n              <div class=\"link-link\">\\\n                <a href=\"' + this.link + '\" target=\"_blank\" data-hoster=\"' + this.hoster + '\" data-count=\"' + this.index + '\" rel=\"noopener\">\\\n                  ' + this.anzeigeLink + '\\\n                </a>\\\n            </div>\\\n          </div>\\\n          <span class=\"hoster\">\\\n            ' + this.gefVon + '\\\n          </span>\\\n          <a class=\"proxy\" onmouseover=\"$(this).popover(\\'show\\');\" onmouseout=\"$(this).popover(\\'hide\\');\" data-toggle=\"popover\" data-placement=\"auto right\" data-container=\"body\" data-content=\"Der Link wird anonymisiert geöffnet. Ihre Daten werden nicht zum Zielserver übertragen. Möglicherweise funktionieren manche Webseiten nicht wie gewohnt.\" href=\"' + this.proxy + '\" target=\"_blank\" rel=\"noopener\" data-original-title=\"\" title=\"\">\\\n            <img src=\"/img/proxyicon.png\" alt=\"\">\\\n            anonym öffnen\\\n          </a>\\\n        </div>\\\n      </div>\\\n      <div class=\"description\">' + this.description + '</div>\\\n      </div>\\\n    </div>');\n  $(result).find(\".remover\").click({caller: this}, function(event){\n    event.data.caller.remove();\n  });\n  return result;\n}"]}