import rt from './runtimes.js'; import { render } from './helper.js'; export const api = { items: new Map(), meta: [], getItems: function() { return fetch("//api.allorigins.win/raw?url=https://f0ck.me/api/p", { headers: { //'Accept': 'application/json', //'Content-Type': 'application/json' }, method: 'GET' //method: 'POST', //body: JSON.stringify({ ...rt.events.hash, eps: rt.events.dims.eps }) }) .then(res => res.status === 200? res.json() : {error:true} ) .then(data => { if(!data.error) { this.meta = data.meta; [...data.items.prev, ...data.items.next].forEach(e => this.items.set(e.stamp, e)); } return { prev: data.items.prev.sort().reverse(), next: data.items.next.sort().reverse() }; }) .then(data => { this.items = new Map([...this.items.entries()].sort().reverse()); console.log(data); }); }, get pos() { return { latest: [...this.items][0], first: [...this.items][this.items.size - 1] }; } }; api.getItems().then(() => { render(api.items); });