Brainly Filter by Points

Hides questions that award below a certain number of points.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Brainly Filter by Points
// @namespace	tacheometry
// @match        *://*brainly.pl/*
// @match        *://*znanija.com/*
// @match        *://*brainly.lat/*
// @match        *://*brainly.com.br/*
// @match        *://*nosdevoirs.fr/*
// @match        *://*eodev.com/*
// @match        *://*brainly.ro/*
// @match        *://*brainly.co.id/*
// @match        *://*brainly.in/*
// @match        *://*brainly.ph/*
// @match        *://*brainly.com/*
// @grant       GM.getValue
// @grant       GM.setValue
// @grant       GM.registerMenuCommand
// @license     MIT
// @version     1.0
// @author      tacheometry
// @description Hides questions that award below a certain number of points.
// ==/UserScript==

(function () {
	"use strict";

	const KEY_NAME = "MinimumQuestionAward";
	const scanQuestions = async () => {
		const minPoints = await GM.getValue(KEY_NAME, 10);

		for (const pointsCounter of document.querySelectorAll(
			"[data-testid='points_counter']"
		)) {
			const number = parseInt(pointsCounter.innerText);
			if (number >= minPoints) continue;

			const parent =
				pointsCounter.closest("[data-testid='feed-item']") ??
				pointsCounter.closest(
					"[data-testid='answering_feed_question_list_item']"
				);
			if (!parent) continue;

			parent.remove();
		}
	};

	const observer = new MutationObserver(scanQuestions);
	scanQuestions();
	observer.observe(document, {
		childList: true,
		subtree: true,
		attributes: false,
	});

	GM.registerMenuCommand(
		"Change minimum award filter",
		() => {
			const result = prompt(
				"Set minimum points awarded for a question to be shown:"
			);
			if (result) GM.setValue(KEY_NAME, parseInt(result));
		},
		{
			id: "minAwardChangeButton",
		}
	);
})();