File size: 2,294 Bytes
8e9fe4d
 
 
 
 
 
 
 
a98f3fa
 
8e9fe4d
 
 
 
 
 
 
 
 
 
 
 
a98f3fa
8e9fe4d
 
 
 
 
 
 
3cbe1cb
8e9fe4d
 
 
 
 
 
 
 
 
 
 
 
 
a98f3fa
8e9fe4d
 
c6e833c
8e9fe4d
 
 
a98f3fa
 
8e9fe4d
 
3cbe1cb
8e9fe4d
 
 
 
 
3cbe1cb
8e9fe4d
 
 
 
 
 
a98f3fa
8e9fe4d
 
3cbe1cb
a98f3fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function toggleAllSelection() {
  document
    .querySelectorAll('.engine')
    .forEach(
      (engine_checkbox) =>
        (engine_checkbox.checked =
          document.querySelector('.select_all').checked)
    )
}

function setActiveTab(current_tab) {
  document
    .querySelectorAll('.tab')
    .forEach((tab) => tab.classList.remove('active'))
  document
    .querySelectorAll('.btn')
    .forEach((tab) => tab.classList.remove('active'))
  current_tab.classList.add('active')
  document
    .querySelector(`.${current_tab.innerText.toLowerCase().replace(' ', '_')}`)
    .classList.add('active')
}

function setClientSettings() {
  let cookie_dictionary = new Object()
  document.querySelectorAll('select').forEach((select_tag) => {
    if (select_tag.name === 'themes') {
      cookie_dictionary['theme'] = select_tag.value
    } else if (select_tag.name === 'colorschemes') {
      cookie_dictionary['colorscheme'] = select_tag.value
    }
  })
  let engines = []
  document.querySelectorAll('.engine').forEach((engine_checkbox) => {
    if (engine_checkbox.checked === true) {
      engines.push(engine_checkbox.parentNode.parentNode.innerText.trim())
    }
  })
  cookie_dictionary['engines'] = engines
  let expiration_date = new Date()
  expiration_date.setFullYear(expiration_date.getFullYear() + 1)
  document.cookie = `appCookie=${JSON.stringify(
    cookie_dictionary
  )}; expires=${expiration_date.toUTCString()}`

  document.querySelector('.message').innerText =
    '✅ The settings have been saved sucessfully!!'

  setTimeout(() => {
    document.querySelector('.message').innerText = ''
  }, 10000)
}

function getClientSettings() {
  let cookie = decodeURIComponent(document.cookie)

  if (cookie !== '') {
    let cookie_value = decodeURIComponent(document.cookie)
      .split(';')
      .map((item) => item.split('='))
      .reduce((acc, [_, v]) => (acc = JSON.parse(v)) && acc, {})

    let links = Array.from(document.querySelectorAll('link')).forEach(
      (item) => {
        if (item.href.includes('static/themes')) {
          item.href = `static/themes/${cookie_value['theme']}.css`
        } else if (item.href.includes('static/colorschemes')) {
          item.href = `static/colorschemes/${cookie_value['colorscheme']}.css`
        }
      }
    )
  }
}