Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Apply for url RegEx .*/lednicka
- // m: "Počet minut"
- // h: "Trojnásobek počtu hodin"
- // d: "Dvojnásobek čísla dne"
- // M: "Pětinásobek čísla měsíce"
- // k: "Dvoutisícina našetřených kaček"
- // c: "Trojnásobek lidí v klubovně"
- // r: "Hod hexeraktem"
- // 1: "Jedničku"
- // o: "Odmražení čtyřčíslí"
- window.addEventListener('load', () => {
- if (!location.href.includes('-')) {
- setInterval(async () => {
- // const kacek = Number(document.getElementById('pocet-kacek').innerText.replace(/\s|!/,''))
- const lidi = document.getElementById('pocet-lidi').dataset.lidi
- if (lidi) {
- localStorage.xxlidi = lidi
- }
- if (!localStorage.xxlast || +localStorage.xxlast < (Date.now() - 1000 * 60 * 60 )) { // only once per hour
- const resp = await fetch('https://www.alik.cz/s/konto')
- const html = await resp.text()
- const kacek = +html.match(/maxima ([0-9\s]+) tebou/)[1].replace(/\s/g, '')
- localStorage.xxlast = Date.now()
- localStorage.xxkacek = kacek
- }
- }, 5000)
- }
- })
- const isPrime = num => {
- for (let i = 2, s = Math.sqrt(num); i <= s; i++) {
- if(num % i === 0) {
- return false
- }
- }
- return num > 1
- }
- const getValue = (id) => {
- const count = +document.querySelector('#cislo').firstChild.textContent.replace(/\s/g, '')
- const now = new Date()
- const lednicka = [...document.querySelectorAll('#historie tr td+td')]
- .map(el => Number(el.innerText.replace(/\s/g,'')))
- .reduce((sum, val, i) => sum + val*((100-i)/100))
- const val = {
- m: now.getMinutes(),
- h: now.getHours() * 3,
- d: now.getDate() * 2,
- M: (now.getMonth()+1) * 5,
- 1: '~' + Math.floor(lednicka / 150),
- k: Math.floor(+localStorage.xxkacek / 2000),
- c: +((localStorage.xxlidi).replace('!','')) * 3,
- r: '~46',
- o: '~' + (isPrime(count) ? 10000 - count % 10000 : 0)
- }[id]
- return val === undefined ? '???' : val
- }
- const evaluate = () => {
- const buttons = [...document.querySelectorAll('button[name=pricti]')]
- const countEl = document.querySelector('#cislo')
- const count = +countEl.firstChild.textContent.replace(/\s/g, '')
- // mark count as prime if prime
- if (countEl.lastElementChild.tagName === "SMALL") {
- countEl.appendChild(document.createElement('span'))
- }
- if (isPrime(count)) {
- countEl.lastElementChild.innerText = ' prvočíslo!'
- } else {
- countEl.lastElementChild.innerText = ''
- }
- const vals = {}
- buttons.forEach(button => {
- vals[button.value] = getValue(button.value)
- })
- const max = Object.values(vals).reduce((max, value) => {
- if (typeof value === 'number') {
- return Math.max(max, value)
- }
- return max
- }, 0)
- buttons.forEach(button => {
- const text = button.innerText
- const label = text.split(' = ')[0]
- const value = vals[button.value]
- if (typeof value === 'number' && value !== max) {
- // button.disabled = true
- } else {
- // button.disabled = false
- }
- const willPrimeText = isPrime(count + value)
- ? ' (udělá prvočíslo)'
- : ''
- button.innerHTML = `${label} = ${value} ${willPrimeText}`
- })
- const rawVal = (btn) => Number(btn.innerText.replace(/[^0-9]/g,''))
- // show to next prime
- let toNextPrime = 0
- let i
- for (i = 0; i < 1000; i++) {
- if (isPrime(count + i )) {
- toNextPrime = i
- break
- }
- }
- if (i === 1000) {
- i = '999+'
- }
- if (buttons.length) {
- const parent = buttons[0].parentElement
- if (parent.firstElementChild.tagName !== 'SPAN') {
- parent.insertBefore(document.createElement('span'), buttons[0])
- }
- parent.firstElementChild.innerText = `${toNextPrime} do dalšího prvočísla`
- }
- // sort buttons
- buttons
- .sort((a, b) => rawVal(b) - rawVal(a))
- .forEach(button => {
- button.parentElement.appendChild(button)
- })
- }
- if (location.href.includes('-')) {
- setTimeout(evaluate, 100)
- setInterval(evaluate, 2000)
- }
- // const rand = (min, max) => {
- // return min + Math.floor(Math.random() * (max-min+1))
- // }
- // const numbers = []
- // const MAX = 1000000
- // for (let i = 0; i < 50; i++) {
- // for (let i = 0; i < MAX; i++) {
- // numbers[i] = rand(rand(2,5),rand(30, rand(60, 240)))
- // }
- // const avg = numbers.reduce((sum, val) => (sum + val), 0) / MAX
- // console.log('avg', avg)
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement