Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

View Total Moderation Actions on Moderator Profiles #408

Open
LukeG294 opened this issue Mar 22, 2021 · 1 comment
Open

View Total Moderation Actions on Moderator Profiles #408

LukeG294 opened this issue Mar 22, 2021 · 1 comment
Assignees
Labels
💎 enhancement New feature or request

Comments

@LukeG294
Copy link
Contributor

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

@LukeG294 LukeG294 added the 💎 enhancement New feature or request label Mar 22, 2021
@Alphka
Copy link

Alphka commented Apr 22, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💎 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants