mirror of
https://github.com/osmarks/website
synced 2025-05-06 17:34:11 +00:00
Infipage update
This commit is contained in:
parent
ccd4f72d2d
commit
62eca4af08
@ -41,7 +41,8 @@ const ignorePaths = [
|
|||||||
const shouldRespond = req => {
|
const shouldRespond = req => {
|
||||||
if (req.method !== "GET") { return false } // do not respond to non-GET requests
|
if (req.method !== "GET") { return false } // do not respond to non-GET requests
|
||||||
if (!req.url.startsWith(self.location.origin)) { return false } // do not respond to cross-origin requests
|
if (!req.url.startsWith(self.location.origin)) { return false } // do not respond to cross-origin requests
|
||||||
const path = new URL(req.url).pathname
|
const parsedURL = new URL(req.url)
|
||||||
|
const path = parsedURL.pathname
|
||||||
for (ignorePath of ignorePaths) {
|
for (ignorePath of ignorePaths) {
|
||||||
if (path.startsWith(ignorePath)) { return false }
|
if (path.startsWith(ignorePath)) { return false }
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
title: Infipage
|
title: Infipage
|
||||||
description: Outdoing all other websites with <b>INFINITE PAGES!</b>
|
description: Outdoing all other websites with <b>INFINITE PAGES!</b>
|
||||||
url: /infipage/0
|
url: /infipage/p
|
||||||
---
|
---
|
||||||
<style>
|
<style>
|
||||||
#prev, #next {
|
#prev, #next {
|
||||||
@ -41,6 +41,7 @@ url: /infipage/0
|
|||||||
<script>
|
<script>
|
||||||
Big.PE = Infinity
|
Big.PE = Infinity
|
||||||
Big.DP = 0
|
Big.DP = 0
|
||||||
|
Big.RM = 0
|
||||||
|
|
||||||
// From MDN somewhere
|
// From MDN somewhere
|
||||||
if (!String.prototype.startsWith) {
|
if (!String.prototype.startsWith) {
|
||||||
@ -49,105 +50,12 @@ url: /infipage/0
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!String.prototype.repeat) {
|
// not quite base64 alphabet
|
||||||
String.prototype.repeat = function(times) {
|
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstvuwxyz0123456789-_~.:@"
|
||||||
return new Array(num + 1).join(this);
|
var alphabetMapping = {}
|
||||||
};
|
for (var i = 0; i < alphabet.length; i++) { alphabetMapping[alphabet[i]] = i }
|
||||||
}
|
console.log("alphabet is", alphabet, "chars")
|
||||||
|
var base = Big(alphabet.length)
|
||||||
function encodeRLEArray(input) {
|
|
||||||
var encoding = [];
|
|
||||||
var prev, count, i;
|
|
||||||
for (count = 1, prev = input[0], i = 1; i < input.length; i++) {
|
|
||||||
if (input[i] != prev || count == 35) {
|
|
||||||
encoding.push([count, prev])
|
|
||||||
count = 1
|
|
||||||
prev = input[i]
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
encoding.push([count, prev])
|
|
||||||
return encoding
|
|
||||||
}
|
|
||||||
|
|
||||||
function encodeRLEString(rleArr) {
|
|
||||||
var out = ""
|
|
||||||
rleArr.forEach(function(pair) {
|
|
||||||
out += pair[0].toString(36) + pair[1]
|
|
||||||
})
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
/*function encodeRLEString2(rleArr) {
|
|
||||||
var out = ""
|
|
||||||
rleArr.forEach(function(pair) {
|
|
||||||
var count = pair[0]
|
|
||||||
var char = pair[1]
|
|
||||||
if (count !== 1) {
|
|
||||||
out += "." + count.toString(36) + char
|
|
||||||
} else {
|
|
||||||
out += char
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return out
|
|
||||||
}*/
|
|
||||||
|
|
||||||
function decodeRLEArray(arr) {
|
|
||||||
var out = ""
|
|
||||||
arr.forEach(function(pair) {
|
|
||||||
out += pair[1].repeat(pair[0])
|
|
||||||
})
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
function decodeRLEPair(r) {
|
|
||||||
return [ parseInt(r[0], 36), r[1] ]
|
|
||||||
}
|
|
||||||
|
|
||||||
function decodeRLEString(str) {
|
|
||||||
var results = []
|
|
||||||
var re = /[0-9a-z][0-9A-Za-z_-]/g
|
|
||||||
var match
|
|
||||||
while (match = re.exec(str)) {
|
|
||||||
results.push(decodeRLEPair(match[0]))
|
|
||||||
}
|
|
||||||
return results
|
|
||||||
}
|
|
||||||
|
|
||||||
function encodeRLE(str) {
|
|
||||||
return encodeRLEString(encodeRLEArray(str))
|
|
||||||
}
|
|
||||||
|
|
||||||
function decodeRLE(str) {
|
|
||||||
return decodeRLEArray(decodeRLEString(str))
|
|
||||||
}
|
|
||||||
|
|
||||||
function b64e(str) {
|
|
||||||
return btoa(str).replace(/\+/g, "_").replace(/\//g, "-")
|
|
||||||
}
|
|
||||||
|
|
||||||
function b64d(b64) {
|
|
||||||
return atob(b64.replace(/_/g, "+").replace(/\-/g, "/"))
|
|
||||||
}
|
|
||||||
|
|
||||||
var base = Big(256)
|
|
||||||
var basediv2 = base.div(2)
|
|
||||||
|
|
||||||
function addEncoding(arr, func) {
|
|
||||||
return arr.concat(arr.map(func))
|
|
||||||
}
|
|
||||||
|
|
||||||
function findShortest(arr) {
|
|
||||||
return arr.reduce(function(prev, now) {
|
|
||||||
if (typeof prev === "string") {
|
|
||||||
return now.length < prev.length ? now : prev
|
|
||||||
} else {
|
|
||||||
return now
|
|
||||||
}
|
|
||||||
}, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
function encodeBignum(b) {
|
function encodeBignum(b) {
|
||||||
var out = ""
|
var out = ""
|
||||||
@ -157,38 +65,28 @@ url: /infipage/0
|
|||||||
var byte = 0
|
var byte = 0
|
||||||
while (!curr.eq(0)) {
|
while (!curr.eq(0)) {
|
||||||
var now = curr.mod(base)
|
var now = curr.mod(base)
|
||||||
out += String.fromCharCode(+now)
|
out += alphabet[+now]
|
||||||
// Attempt to emulate an actual bitshift
|
|
||||||
curr = curr.div(base)
|
curr = curr.div(base)
|
||||||
if (now.gte(basediv2)) { curr = curr.minus(1) }
|
|
||||||
}
|
}
|
||||||
var start = b.s === -1 ? "n" : "p"
|
var start = b.s === -1 ? "n" : "p"
|
||||||
var b64 = start + b64e(out)
|
return start + out
|
||||||
var decimal = b.toString()
|
|
||||||
var possibilities = [b64, decimal]
|
|
||||||
possibilities = addEncoding(possibilities, function(x) { return "r" + encodeRLE(x) })
|
|
||||||
return findShortest(possibilities)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function decodeBignum(str) {
|
function decodeBignum(str) {
|
||||||
if (str.startsWith("r")) {
|
|
||||||
return decodeBignum(decodeRLE(str.substring(1)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// If string is not tagged with its sign, it's just a regular number
|
// If string is not tagged with its sign, it's just a regular number
|
||||||
|
// backward compatibility only
|
||||||
if (!str.startsWith("n") && !str.startsWith("p")) {
|
if (!str.startsWith("n") && !str.startsWith("p")) {
|
||||||
return Big(str)
|
return Big(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
var start = str.substring(0, 1)
|
var start = str.substring(0, 1)
|
||||||
|
|
||||||
var bin = b64d(str.substring(1))
|
var main = str.substring(1)
|
||||||
var out = Big(0)
|
var out = Big(0)
|
||||||
// Split string into bytes
|
var bvals = main.split("").map(function(x) { return alphabetMapping[x] })
|
||||||
var bytes = bin.split("").map(function(x) { return x.charCodeAt(0) })
|
// Add each char's value to string, multiplied by the base to the power of its position in string
|
||||||
// Add each byte to string, multiplied by 2 ^ its position in string
|
bvals.forEach(function(val, position) {
|
||||||
bytes.forEach(function(byte, exponent) {
|
var thisByte = Big(val).times(base.pow(position))
|
||||||
var thisByte = Big(byte).times(base.pow(exponent))
|
|
||||||
out = out.plus(thisByte)
|
out = out.plus(thisByte)
|
||||||
})
|
})
|
||||||
if (start === "n") { out = out.times(-1) }
|
if (start === "n") { out = out.times(-1) }
|
||||||
@ -200,7 +98,7 @@ url: /infipage/0
|
|||||||
var prev = document.querySelector("#prev"), next = document.querySelector("#next"), count = document.querySelector("#pagecount"), main = document.querySelector("#main"), error = document.querySelector("#error")
|
var prev = document.querySelector("#prev"), next = document.querySelector("#next"), count = document.querySelector("#pagecount"), main = document.querySelector("#main"), error = document.querySelector("#error")
|
||||||
function loadPage() {
|
function loadPage() {
|
||||||
try {
|
try {
|
||||||
var afterSlash = /infipage\/([A-Za-z0-9_=-]+)/.exec(window.location.pathname)[1]
|
var afterSlash = /infipage\/([A-Za-z0-9_=-]*)/.exec(window.location.pathname)[1]
|
||||||
page = decodeBignum(afterSlash)
|
page = decodeBignum(afterSlash)
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.warn("Page Number Decode Failure")
|
console.warn("Page Number Decode Failure")
|
||||||
@ -217,12 +115,13 @@ url: /infipage/0
|
|||||||
}
|
}
|
||||||
prev.href = encodeBignum(page.minus(1))
|
prev.href = encodeBignum(page.minus(1))
|
||||||
next.href = encodeBignum(page.plus(1))
|
next.href = encodeBignum(page.plus(1))
|
||||||
pagecount.innerText = "Page " + page.toString()
|
pagecount.innerText = "Page " + pageString
|
||||||
}
|
}
|
||||||
loadPage()
|
loadPage()
|
||||||
if ("ontouchstart" in window) { main.classList.add("mobile") }
|
if ("ontouchstart" in window) { main.classList.add("mobile") }
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
// interface with arbitrary points
|
||||||
window.addEventListener("load", function() {
|
window.addEventListener("load", function() {
|
||||||
if ("points" in window) {
|
if ("points" in window) {
|
||||||
console.log("running update")
|
console.log("running update")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user