f0ckv2/public/js/f0ck.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-05-07 20:23:19 +00:00
import rt from "./rt.js";
2019-05-15 17:51:11 +00:00
import events from "./events.js";
import lib from "./lib.js";
2019-05-07 20:23:19 +00:00
2019-05-19 01:45:45 +00:00
if(rt.debug) {
window.d = {
rt: rt,
events: events,
lib: lib
};
}
2019-05-15 17:51:11 +00:00
(async () => {
lib.showLayer("page");
window.addEventListener("hashchange", events.hashchange);
2019-05-19 01:45:45 +00:00
document.addEventListener("wheel", events.wheel);
window.addEventListener("resize", events.resize);
[...rt.ct.arrows] // add pagebuttons
.forEach(p => p.addEventListener("click", events.wheel));
2019-05-07 20:23:19 +00:00
2019-05-15 17:51:11 +00:00
const debug = document.querySelectorAll("span#debug > a");
2019-05-19 01:45:45 +00:00
debug[0].addEventListener("click", async () => { // random
const random = await (await fetch(`${rt.api}/random`)).json();
window.location = `${window.location.pathname}#${random.id}`;
2019-05-15 17:51:11 +00:00
});
2019-05-07 20:23:19 +00:00
setTimeout(() => {
const pn = parseInt(document.location.pathname.split("/").splice(-1));
2019-05-15 17:51:11 +00:00
const hash = document.location.hash;
2019-05-19 01:45:45 +00:00
if(!hash) {
lib.getItems({
el: rt.ct.wrapper.pages[1],
opt: pn > 0 ? `id=${pn + 1}&order=desc` : ""
});
lib.scrolltomiddle(rt.ct.wrapper.pages);
}
else
2019-05-15 17:51:11 +00:00
window.dispatchEvent(new CustomEvent("hashchange", { detail: { newURL: hash } }));
}, 300);
2019-05-07 20:23:19 +00:00
2019-05-15 17:51:11 +00:00
})();