Advertisement
draho

Alik ledničkovač

Jan 24th, 2022
1,159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Apply for url RegEx .*/lednicka
  2.  
  3. // m: "Počet minut"
  4. // h: "Trojnásobek počtu hodin"
  5. // d: "Dvojnásobek čísla dne"
  6. // M: "Pětinásobek čísla měsíce"
  7.  
  8. // k: "Dvoutisícina našetřených kaček"
  9. // c: "Trojnásobek lidí v klubovně"
  10.  
  11. // r: "Hod hexeraktem"
  12.  
  13. // 1: "Jedničku"
  14. // o: "Odmražení čtyřčíslí"
  15.  
  16.  
  17. window.addEventListener('load', () => {
  18.   if (!location.href.includes('-')) {
  19.     setInterval(async () => {
  20.       // const kacek = Number(document.getElementById('pocet-kacek').innerText.replace(/\s|!/,''))
  21.       const lidi = document.getElementById('pocet-lidi').dataset.lidi
  22.       if (lidi) {
  23.         localStorage.xxlidi = lidi
  24.       }
  25.  
  26.       if (!localStorage.xxlast || +localStorage.xxlast < (Date.now() - 1000 * 60 * 60 )) { // only once per hour
  27.         const resp = await fetch('https://www.alik.cz/s/konto')
  28.         const html = await resp.text()
  29.         const kacek = +html.match(/maxima ([0-9\s]+) tebou/)[1].replace(/\s/g, '')
  30.         localStorage.xxlast = Date.now()
  31.         localStorage.xxkacek = kacek
  32.       }
  33.     }, 5000)
  34.   }
  35. })
  36.  
  37. const isPrime = num => {
  38.   for (let i = 2, s = Math.sqrt(num); i <= s; i++) {
  39.     if(num % i === 0) {
  40.       return false
  41.     }
  42.   }
  43.   return num > 1
  44. }
  45.  
  46. const getValue = (id) => {
  47.   const count = +document.querySelector('#cislo').firstChild.textContent.replace(/\s/g, '')
  48.   const now = new Date()
  49.   const lednicka = [...document.querySelectorAll('#historie tr td+td')]
  50.     .map(el => Number(el.innerText.replace(/\s/g,'')))
  51.     .reduce((sum, val, i) => sum + val*((100-i)/100))  
  52.   const val = {
  53.     m: now.getMinutes(),
  54.     h: now.getHours() * 3,
  55.     d: now.getDate() * 2,
  56.     M: (now.getMonth()+1) * 5,
  57.  
  58.     1: '~' + Math.floor(lednicka / 150),
  59.  
  60.     k: Math.floor(+localStorage.xxkacek / 2000),
  61.     c: +((localStorage.xxlidi).replace('!','')) * 3,
  62.     r: '~46',
  63.  
  64.     o: '~' + (isPrime(count) ? 10000 - count % 10000 : 0)
  65.   }[id]
  66.  
  67.   return val === undefined ? '???' : val
  68. }
  69.  
  70.  
  71. const evaluate = () => {
  72.   const buttons = [...document.querySelectorAll('button[name=pricti]')]
  73.   const countEl = document.querySelector('#cislo')
  74.  
  75.   const count = +countEl.firstChild.textContent.replace(/\s/g, '')
  76.  
  77.   // mark count as prime if prime
  78.   if (countEl.lastElementChild.tagName === "SMALL") {
  79.     countEl.appendChild(document.createElement('span'))
  80.   }
  81.   if (isPrime(count)) {
  82.     countEl.lastElementChild.innerText = ' prvočíslo!'
  83.   } else {
  84.     countEl.lastElementChild.innerText = ''
  85.   }
  86.  
  87.   const vals = {}
  88.   buttons.forEach(button => {
  89.     vals[button.value] = getValue(button.value)
  90.   })
  91.  
  92.   const max = Object.values(vals).reduce((max, value) => {
  93.     if (typeof value === 'number') {
  94.       return Math.max(max, value)
  95.     }
  96.     return max
  97.   }, 0)
  98.  
  99.   buttons.forEach(button => {
  100.     const text = button.innerText
  101.     const label = text.split(' = ')[0]
  102.     const value = vals[button.value]
  103.     if (typeof value === 'number' && value !== max) {
  104.       // button.disabled = true
  105.     } else {
  106.       // button.disabled = false
  107.     }
  108.  
  109.     const willPrimeText = isPrime(count + value)
  110.       ? ' (udělá prvočíslo)'
  111.       : ''
  112.  
  113.     button.innerHTML = `${label} = ${value} ${willPrimeText}`
  114.   })
  115.  
  116.   const rawVal = (btn) => Number(btn.innerText.replace(/[^0-9]/g,''))
  117.  
  118.   // show to next prime
  119.   let toNextPrime = 0
  120.   let i
  121.   for (i = 0; i < 1000; i++) {
  122.     if (isPrime(count + i )) {
  123.       toNextPrime = i
  124.       break
  125.     }
  126.   }
  127.   if (i === 1000) {
  128.     i = '999+'
  129.   }
  130.   if (buttons.length) {
  131.     const parent = buttons[0].parentElement
  132.     if (parent.firstElementChild.tagName !== 'SPAN') {
  133.       parent.insertBefore(document.createElement('span'), buttons[0])
  134.     }
  135.     parent.firstElementChild.innerText = `${toNextPrime} do dalšího prvočísla`
  136.   }
  137.  
  138.   // sort buttons
  139.   buttons
  140.     .sort((a, b) => rawVal(b) - rawVal(a))
  141.     .forEach(button => {
  142.       button.parentElement.appendChild(button)
  143.     })
  144.  
  145. }
  146.  
  147. if (location.href.includes('-')) {
  148.  
  149.   setTimeout(evaluate, 100)
  150.   setInterval(evaluate, 2000)
  151. }
  152.  
  153.  
  154.  
  155. // const rand = (min, max) => {
  156. //   return min + Math.floor(Math.random() * (max-min+1))
  157. // }
  158.  
  159. // const numbers = []
  160. // const MAX = 1000000
  161.  
  162. // for (let i = 0; i < 50; i++) {
  163. //   for (let i = 0; i < MAX; i++) {
  164. //     numbers[i] = rand(rand(2,5),rand(30, rand(60, 240)))
  165. //   }
  166. //   const avg = numbers.reduce((sum, val) => (sum + val), 0) / MAX
  167. //   console.log('avg', avg)
  168. // }
  169.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement