Random improvements

This commit is contained in:
osmarks 2020-05-02 09:19:04 +01:00
parent 40e6916a9b
commit f86c12e16a
2 changed files with 17 additions and 4 deletions

View File

@ -22,7 +22,7 @@ if ("serviceWorker" in navigator) {
}
// https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
const hash = function(str, seed = 0) {
const hashString = function(str, seed = 0) {
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed
for (let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i)
@ -34,7 +34,7 @@ const hash = function(str, seed = 0) {
return 4294967296 * (2097151 & h2) + (h1>>>0)
}
const colHash = (str, saturation = 100, lightness = 70) => `hsl(${hash(str) % 360}, ${saturation}%, ${lightness}%)`
const colHash = (str, saturation = 100, lightness = 70) => `hsl(${hashString(str) % 360}, ${saturation}%, ${lightness}%)`
// Arbitrary Points code, wrapped in an IIFE to not pollute the global environment much more than it already is
window.points = (() => {
@ -110,6 +110,12 @@ window.points = (() => {
conditions: "posting a comment",
points: 30.5,
description: "You (probably, the detection isn't 100% accurate) posted a comment! Enjoy expressing your opinion (or random meaningless message) to random internet people!"
},
aprilFools: {
title: "April Folly",
conditions: "visiting on April Fools' Day",
description: "Enjoy being... April Fooled? Good luck getting this, speedrunners.",
points: 16.0303
}
}
@ -245,6 +251,11 @@ window.points = (() => {
if (metrics.get("pagesVisited") > 64) {
unlockAchievement("pagesVisited64")
}
const now = new Date()
if (now.getUTCMonth() === 3 && now.getUTCDate() === 1) {
//if (now.getUTCMonth() === 2 && now.getUTCDate() === 22) {
unlockAchievement("aprilFools")
}
})
setInterval(() => {

View File

@ -35,7 +35,9 @@ self.addEventListener("activate", event => {
const ignorePaths = [
"/isso",
"/infipage"
"/infipage",
"/wsthing",
"/random-stuff"
]
const shouldRespond = req => {
@ -85,4 +87,4 @@ self.addEventListener("fetch", event => {
if (shouldRespond(event.request)) {
event.respondWith(getResponse(event.request))
}
})
})