Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
const FIRE = String.fromCodePoint(0x1F525);
const savePos = (element, storage_key) => {
let {left, top} = element.style;
localStorage.setItem(storage_key, [left, top].join(','));
}
const appendCorners = (parent) => {
const common = {
position: 'absolute',
width: '35px',
height: '23px'
};
let left = document.createElement('div'),
right = document.createElement('div');
Object.assign(left.style, common, {
background: 'url(/img/tip-cor.png) no-repeat 0 -69px',
top: '-6px',
left: '-6px'
});
Object.assign(right.style, common, {
background: 'url(/img/tip-cor.png) no-repeat -35px -69px',
bottom: '-6px',
right: '-6px'
});
parent.appendChild(left);
parent.appendChild(right);
}
const isNI = (window.Engine !== undefined && (window.g === undefined || window.g.loadQueue === undefined));
let [left, top] = (localStorage.getItem('DZposition') !== null ? localStorage.getItem('DZposition').split(',') : ['calc(50% - 70px)', '10px']);
const box = document.createElement('div');
Object.assign(box.style, {
width: '140px',
zIndex: '391',
background: '#222',
border: '3px double #A95',
color: '#FFD700',
fontFamily: 'Verdana, Arial, sans-serif',
fontSize: '11px',
position: 'absolute',
padding: '3px 3px 4px',
textAlign: 'center',
left: left,
top: top
});
box.setAttribute('id', 'DZbox');
box.setAttribute('tip', '<div style="color:white; text-align:center;"><h3>Minutnik<h3/>LPM = przesuwanie</div>');
if(isNI === false) $(box).draggable({
start: () => g.lock.add('reski'),
stop: () => (g.lock.remove('reski'), savePos(box, 'DZposition'))
});
else $(box).draggable({stop: () => savePos(box, 'DZposition')});
const title = document.createElement('h3');
title.style.color = 'white';
title.innerHTML = FIRE+' Dzień Żaby '+FIRE;
const main = document.createElement('div');
Object.assign(main.style, {
margin: '3px'
});
main.innerText = 'Wpuści do jaskini za:';
const timer = document.createElement('h2');
timer.style.margin = '3px';
main.appendChild(timer);
const footer = document.createElement('span');
Object.assign(footer.style, {
color: 'orangered',
fontWeight: 'bold'
});
footer.innerText = 'Minutnik';
[title, main, footer].forEach(e => box.appendChild(e));
appendCorners(box);
document.body.appendChild(box);
const nice = (int) => (int > 9 ? int : '0'+int);
const formattedDiff = (ts1, ts2) => {
const diff = ts1 - ts2;
if(diff < 0) return 'teraz!';
let hours = (diff >= 3600 ? nice(Math.floor(diff/3600)) : '00');
let mins = nice(Math.floor((diff%3600)/60));
return hours+':'+mins+' h';
}
const resetTimer = (storage_key) => {
let stamp = Math.round(+new Date()/1000);
message('<span style="color:white;">Żabi minutnik - zapisałem!</span>');
let next = stamp+28830;
localStorage.setItem(storage_key, next);
timer.innerText = formattedDiff(next, stamp);
};
const setTimerInterval = (element, next) => {
next = parseInt(next);
setInterval(() => {
element.innerText = formattedDiff(next, Math.round(+new Date()/1000));
}, 60000);
};
const goal = 'Gombesh';
if(isNI === false) g.loadQueue.push({fun: () => {
const storage_key = 'DZ'+hero.id;
if(~map.name.indexOf(goal)) return resetTimer(storage_key);
let next = localStorage.getItem(storage_key);
if(next === null) return timer.innerText = '-';
timer.innerText = formattedDiff(parseInt(next), Math.round(+new Date()/1000));
setTimerInterval(timer, next);
}});
else setTimeout(() => { //NI fallback
const storage_key = 'DZ'+Engine.hero.d.nick;
setInterval(() => {
if(Engine.map.d.name.indexOf(goal) !== -1) resetTimer('DZ'+Engine.hero.d.nick);
}, 5000);
let next = localStorage.getItem(storage_key);
if(next === null) return timer.innerText = '-';
timer.innerText = formattedDiff(parseInt(next), Math.round(+new Date()/1000));
setTimerInterval(timer, next);
}, 400);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.