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:
@@ -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)
|
||||
|
||||
18
src/site/html/static/js/quota.js
Normal file
18
src/site/html/static/js/quota.js
Normal 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}
|
||||
Reference in New Issue
Block a user