2022-04-09 04:45:47 +02:00
|
|
|
/*
|
|
|
|
========================================================================
|
|
|
|
The 2022 /r/place Atlas
|
|
|
|
|
|
|
|
An Atlas of Reddit's 2022 /r/place, with information to each
|
|
|
|
artwork of the canvas provided by the community.
|
|
|
|
|
|
|
|
Copyright (c) 2017 Roland Rytz <roland@draemm.li>
|
|
|
|
Copyright (c) 2022 r/placeAtlas2 contributors
|
|
|
|
|
|
|
|
Licensed under the GNU Affero General Public License Version 3
|
|
|
|
https://place-atlas.stefanocoding.me/license.txt
|
|
|
|
========================================================================
|
|
|
|
*/
|
|
|
|
|
2022-04-05 20:17:39 +02:00
|
|
|
const timeConfig = [
|
|
|
|
{
|
2022-04-06 19:04:07 +02:00
|
|
|
timestamp: 1648822500,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1648822500.png",
|
2022-04-05 20:17:39 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
2022-04-06 19:04:07 +02:00
|
|
|
timestamp: 1648847036,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1648847036.png",
|
2022-04-05 20:17:39 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
2022-04-06 19:04:07 +02:00
|
|
|
timestamp: 1648870452,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1648870452.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 1648893666,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1648893666.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 1648917500,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1648917500.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 1648942113,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1648942113.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 1648956234,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1648956234.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 1648968061,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1648968061.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 1648979987,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1648979987.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
timestamp: 1648992274,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1648992274.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 1649012915,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1649012915.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 1649037182,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1649037182.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 1649060793,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1649060793.png",
|
2022-04-06 19:04:07 +02:00
|
|
|
image: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamp: 1649084741,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/1649084741.png",
|
2022-04-05 20:17:39 +02:00
|
|
|
image: null
|
|
|
|
},
|
2022-04-08 00:06:24 +02:00
|
|
|
{
|
|
|
|
timestamp: 1649113199,
|
2022-04-08 06:47:59 +02:00
|
|
|
url: "./_img/place/final.png",
|
2022-04-08 01:11:29 +02:00
|
|
|
image: null,
|
|
|
|
showAtlas: true,
|
2022-04-10 09:03:08 +02:00
|
|
|
}
|
2022-04-05 20:17:39 +02:00
|
|
|
];
|
|
|
|
|
2022-04-14 10:37:29 +02:00
|
|
|
let timelineSlider = document.getElementById("timeControlsSlider");
|
2022-04-10 09:03:08 +02:00
|
|
|
let tooltip = document.getElementById("timeControlsTooltip")
|
2022-04-05 20:17:39 +02:00
|
|
|
let image = document.getElementById("image");
|
|
|
|
|
2022-04-14 08:41:13 +02:00
|
|
|
let defaultPeriod = timeConfig.length - 1
|
|
|
|
let maxPeriod = timeConfig.length - 1
|
2022-04-10 11:11:34 +02:00
|
|
|
var period = defaultPeriod
|
|
|
|
window.period = period
|
2022-04-08 01:11:29 +02:00
|
|
|
|
2022-04-05 20:17:39 +02:00
|
|
|
// SETUP
|
2022-04-14 10:37:29 +02:00
|
|
|
timelineSlider.max = timeConfig.length - 1;
|
2022-04-14 08:41:13 +02:00
|
|
|
// document.querySelector('#period-group .period-start').max = defaultPeriod
|
|
|
|
// document.querySelector('#period-group .period-end').max = defaultPeriod
|
2022-04-14 19:12:28 +02:00
|
|
|
timelineSlider.value = period;
|
|
|
|
updateTime(period)
|
2022-04-05 20:17:39 +02:00
|
|
|
|
2022-04-14 10:37:29 +02:00
|
|
|
timelineSlider.addEventListener("input", (event) => {
|
2022-04-10 11:11:34 +02:00
|
|
|
updateTime(parseInt(event.target.value))
|
2022-04-10 09:03:08 +02:00
|
|
|
})
|
2022-04-05 20:17:39 +02:00
|
|
|
|
2022-04-14 08:41:13 +02:00
|
|
|
// document.querySelector('#period-group .period-start').oninput = (event) => {
|
|
|
|
// slider.value = parseInt(event.target.value)
|
|
|
|
// updateTime(parseInt(event.target.value))
|
|
|
|
// };
|
2022-04-10 11:11:34 +02:00
|
|
|
|
2022-04-14 08:41:13 +02:00
|
|
|
// document.querySelector('#period-group .period-end').oninput = (event) => {
|
|
|
|
// slider.value = parseInt(event.target.value)
|
|
|
|
// updateTime(parseInt(event.target.value))
|
|
|
|
// };
|
2022-04-10 11:11:34 +02:00
|
|
|
|
2022-04-14 10:37:29 +02:00
|
|
|
const dispatchTimeUpdateEvent = (period = timelineSlider.value, atlas = atlas) => {
|
2022-04-10 11:11:34 +02:00
|
|
|
const timeUpdateEvent = new CustomEvent('timeupdate', {
|
|
|
|
detail: {
|
|
|
|
period: period,
|
|
|
|
atlas: atlas
|
|
|
|
}
|
|
|
|
});
|
|
|
|
document.dispatchEvent(timeUpdateEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateTime(currentPeriod) {
|
|
|
|
period = currentPeriod
|
|
|
|
let configObject = timeConfig[currentPeriod];
|
2022-04-05 20:17:39 +02:00
|
|
|
if (!configObject.image) {
|
2022-04-10 11:11:34 +02:00
|
|
|
let fetchResult = await fetch(configObject.url);
|
2022-04-05 20:17:39 +02:00
|
|
|
let imageBlob = await fetchResult.blob();
|
|
|
|
configObject.image = URL.createObjectURL(imageBlob);
|
|
|
|
}
|
|
|
|
image.src = configObject.image;
|
2022-04-08 01:11:29 +02:00
|
|
|
// TEMP ATLAS ONLY ON LAST TIMESTAMP
|
2022-04-10 11:11:34 +02:00
|
|
|
atlas = []
|
|
|
|
for ( var atlasIndex in atlasAll ) {
|
2022-04-14 16:03:17 +02:00
|
|
|
var pathChosen, centerChosen
|
|
|
|
|
|
|
|
if (Array.isArray(atlasAll[atlasIndex].path)) {
|
|
|
|
if (currentPeriod !== defaultPeriod) continue
|
|
|
|
pathChosen = atlasAll[atlasIndex].path
|
|
|
|
centerChosen = atlasAll[atlasIndex].center
|
|
|
|
} else {
|
|
|
|
var validPeriods2 = Object.keys(atlasAll[atlasIndex].path)
|
|
|
|
var chosenIndex
|
|
|
|
|
|
|
|
for (let i in validPeriods2) {
|
|
|
|
let validPeriods = validPeriods2[i].split(', ')
|
|
|
|
for (let j in validPeriods) {
|
|
|
|
let [start, end] = parsePeriod(validPeriods[j])
|
|
|
|
if (isOnPeriod(start, end, currentPeriod)) {
|
|
|
|
chosenIndex = i
|
|
|
|
break
|
2022-04-10 11:11:34 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-14 16:03:17 +02:00
|
|
|
if (chosenIndex) break
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chosenIndex === undefined) continue
|
|
|
|
pathChosen = Object.values(atlasAll[atlasIndex].path)[chosenIndex]
|
|
|
|
centerChosen = Object.values(atlasAll[atlasIndex].center)[chosenIndex]
|
2022-04-10 11:11:34 +02:00
|
|
|
}
|
2022-04-14 16:03:17 +02:00
|
|
|
|
|
|
|
if (pathChosen === undefined) continue
|
|
|
|
|
|
|
|
atlas.push({
|
|
|
|
...atlasAll[atlasIndex],
|
|
|
|
path: pathChosen,
|
|
|
|
center: centerChosen,
|
|
|
|
})
|
2022-04-08 01:11:29 +02:00
|
|
|
}
|
2022-04-10 11:11:34 +02:00
|
|
|
dispatchTimeUpdateEvent(currentPeriod, atlas)
|
2022-04-10 09:03:08 +02:00
|
|
|
if (typeof configObject.timestamp === "number") tooltip.querySelector('p').textContent = new Date(configObject.timestamp*1000).toUTCString()
|
|
|
|
else tooltip.querySelector('p').textContent = configObject.timestamp
|
2022-04-14 10:37:29 +02:00
|
|
|
tooltip.style.left = (((timelineSlider.offsetWidth)*(timelineSlider.value-1)/(timelineSlider.max-1)) - tooltip.offsetWidth/2) + "px"
|
2022-04-10 09:03:08 +02:00
|
|
|
}
|
|
|
|
|
2022-04-14 10:37:29 +02:00
|
|
|
tooltip.parentElement.addEventListener('mouseenter', () => tooltip.style.left = (((timelineSlider.offsetWidth)*(timelineSlider.value-1)/(timelineSlider.max-1)) - tooltip.offsetWidth/2) + "px")
|
2022-04-10 11:11:34 +02:00
|
|
|
|
2022-04-14 10:37:29 +02:00
|
|
|
window.addEventListener('resize', () => tooltip.style.left = (((timelineSlider.offsetWidth)*(timelineSlider.value-1)/(timelineSlider.max-1)) - tooltip.offsetWidth/2) + "px")
|
2022-04-10 09:03:08 +02:00
|
|
|
|
2022-04-14 16:03:17 +02:00
|
|
|
function isOnPeriod(start, end, current = period) {
|
|
|
|
console.log(start, end, current, current >= start && current <= end)
|
|
|
|
return current >= start && current <= end
|
|
|
|
}
|
|
|
|
|
|
|
|
function parsePeriod(periodString) {
|
|
|
|
periodString = periodString + ""
|
|
|
|
// TODO: Support for multiple/alternative types of canvas
|
|
|
|
if (periodString.search('-') + 1) {
|
|
|
|
var [start, end] = periodString.split('-').map(i => parseInt(i))
|
|
|
|
return [start, end]
|
|
|
|
} else {
|
|
|
|
let periodNew = parseInt(periodString)
|
|
|
|
return [periodNew, periodNew]
|
|
|
|
}
|
|
|
|
}
|