Brainly Filter by Points

Hides questions that award below a certain number of points.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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",
		}
	);
})();