1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2025-12-14 18:45:06 +00:00

Add request quota system

This commit is contained in:
Cadence Ember
2020-07-23 00:58:21 +12:00
parent 2095be2742
commit 112d9cc90e
17 changed files with 253 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
import {ElemJS, q} from "./elemjs/elemjs.js"
import {quota} from "./quota.js"
class FreezeWidth extends ElemJS {
freeze(text) {
@@ -79,6 +80,7 @@ class NextPage extends FreezeWidth {
const type = this.element.getAttribute("data-type")
return fetch(`/fragment/user/${this.element.getAttribute("data-username")}/${this.nextPageNumber}?type=${type}`).then(res => res.text()).then(text => {
quota.change(-1)
q("#next-page-container").remove()
this.observer.disconnect()
q("#timeline").insertAdjacentHTML("beforeend", text)

View File

@@ -0,0 +1,18 @@
import {ElemJS, q} from "./elemjs/elemjs.js"
class Quota extends ElemJS {
constructor() {
super(q("#quota"))
this.value = +this.element.textContent
}
change(difference) {
this.value += difference
this.value = Math.max(0, this.value)
this.text(this.value)
}
}
const quota = new Quota()
export {quota}