seahindeniz / BrainlyTools_Extension

A toolbox for exclusive users of Brainly. It enhances Brainly and provides tools to do fast and massive actions and much more..
https://sahin.in/BrainlyTools
MIT License
1 stars 0 forks source link

View Total Moderation Actions on Moderator Profiles #408

Open LukeG294 opened 3 years ago

LukeG294 commented 3 years ago

Is your feature request related to a problem? Please describe. No, this is not related to a problem.

Describe the solution/idea you'd like A counter for the extension that shows how many actions a moderator has of all time on their profile.

Describe expected outcome from your solution An easy way to see how many actions have been performed by visiting the profile page with the extension.

image

https://brainly.com/profile/LukeG1-16118329

Alphka commented 3 years ago

Hi Sahin, I think this code can help you with the enhancement

class Actions {
    constructor(moderatorID){
        this.actionsUrl = `${window.document.location.origin}/moderation_new/view_moderator/${moderatorID}/page:99999`

        this.Init().then(() => console.log({
            "User": this.userNick,
            "Total actions": this.totalActions || 0
        })).catch(console.error)
    }

    async Init(){
        this.response = await this.requestPage()
        this.responseText = await this.response.text()
        this.responseHTML = new DOMParser().parseFromString(this.responseText, "text/html")
        this.userNick = this.responseHTML.querySelector("h1.alignCenter.marginTop.marginBottom > a.nick").innerText

        this.actionsElements = this.responseHTML.querySelector("div.numbers > span.current")
        if(!this.actionsElements) return

        this.totalPages = Number(this.actionsElements.innerText)
        this.lastPageTotalActions = this.responseHTML.querySelectorAll(".activities > tbody > tr").length
        this.totalActions = (this.totalPages - 1) * 15 + this.lastPageTotalActions
    }

    async requestPage(){
        let response = await fetch(this.actionsUrl, {
            redirect: "manual",
            method: "GET",
            credentials: "include"
        })

        if(!response || [0, 302].includes(response.status)) throw "You cannot view this moderator's actions"
        if(!response.ok && response.status != 200) throw "Request failed"
        return response
    }
}

To execute the code, just paste this in console (inside a brainly's page), and type new Actions(moderatorID) to view how many actions the moderator has.

It should work this way: image