Skip to content


Script Greasemonkey pour bloquer un utilisateur sur GNT

(NB: exceptionally, this article is written in French because it’s targeted at a French, non-English speaking audience – sorry for the inconvenience)

GNT (Génération Nouvelles Technologies) est un site de news IT. Les news y sont généralement intéressantes, mais les commentaires sont souvent peuplées de trolls. Il est possible de bloquer des utilisateurs, mais il faut être inscrit et abonné. Voici un script qui vous permettra de bloquer des utilisateurs directement via Greasemonkey (pas la peine donc de se connecter et/ou s’abonner). Notez que je mentionne Greasemonkey car c’est l’extension la plus connue, mais si vous êtes sous Chrome/Chromium/Vivaldi/etc, le script marche aussi avec Tampermonkey.
Pour utiliser le script, installez-le puis modifiez la liste des utilisateurs bannis (pour l’exemple j’ai bloqué “Bruno” et “Bruno2”): il suffit de changer ou ajouter des noms dans la liste “configBannedUsers”.

Télécharger le script (installation directe dans Greasemonkey / Tampermonkey)
Source:

/***********
Copyright (c) 2016 PatheticCockroach - https://www.patheticcockroach.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***********/

// ==UserScript==
// @name			GNT Ban Hammer
// @namespace		GNT_Ban_Hammer
// @description		Ignore specified users on GNT
// @version			1
// @encoding		UTF-8
// @include			http*://*.generation-nt.com/*
// @grant			none
// @author			PatheticCockroach - https://www.patheticcockroach.com
// @license			MIT License
// @url				https://notepad.patheticcockroach.com/4262/script-greasemonkey-pour-bloquer-un-utilisateur-sur-gnt/
// ==/UserScript==

// Configure here your list of banned users
let configBannedUsers = ["Bruno","Bruno2"];

const GNT_Ban_Hammer_REPEAT_INTERVAL = 100;
const GNT_Ban_Hammer_REPETITIONS = 30;
const GNT_Ban_Hammer_RESTART_INDEX = 0;
let GNT_Ban_HammerCount = 0;

let hideParentOfComUserDiv = function(comUserDiv, userName = "") {
	console.log("GNT Ban Hammer: blocking user \"" + userName + "\"");
	comUserDiv.parentNode.innerHTML = "User "+userName+" blocked by GNT Ban Hammer";
};
let nodeInnerHTMLContains = function(node,text) {
	return (node.innerHTML.indexOf(text) > -1) || (node.innerHTML == text);
};

let GNT_Ban_Hammer_start = function(){
	console.log('GNT_Ban_Hammer_start running');
	
	// commentaire
	let comUserDivs = document.getElementsByClassName('comm_user');
	for(let comUserDiv of comUserDivs) {
		for(let bannedUser of configBannedUsers) {
			if(nodeInnerHTMLContains(comUserDiv, bannedUser)) {
				hideParentOfComUserDiv(comUserDiv, bannedUser);
			}
		}
	}
	
	// tribune summary
	let tribuneUserSpans = document.getElementsByClassName('tribune-nick');
	for(let tribuneUserSpan of tribuneUserSpans) {
		for(let bannedUser of configBannedUsers) {
			if(nodeInnerHTMLContains(tribuneUserSpan, bannedUser)) {
				hideParentOfComUserDiv(tribuneUserSpan.parentNode, bannedUser);
			}
		}
	}
	
	// tribune full
	let tribuneUserDivs = document.getElementsByClassName('pm_user');
	for(let tribuneUserDiv of tribuneUserDivs) {
		for(let bannedUser of configBannedUsers) {
			if(nodeInnerHTMLContains(tribuneUserDiv, bannedUser)) {
				hideParentOfComUserDiv(tribuneUserDiv, bannedUser);
			}
		}
	}
	
	if (GNT_Ban_HammerCount++ < GNT_Ban_Hammer_REPETITIONS) {
		setTimeout(GNT_Ban_Hammer_start, GNT_Ban_Hammer_REPEAT_INTERVAL);
	} else {
		GNT_Ban_Hammer_armPagination();
	}
};

let GNT_Ban_Hammer_restart = function() {
	console.log('GNT_Ban_Hammer_restart running');
	GNT_Ban_HammerCount = GNT_Ban_Hammer_RESTART_INDEX;
	setTimeout(GNT_Ban_Hammer_start, GNT_Ban_Hammer_REPEAT_INTERVAL);
};

let GNT_Ban_Hammer_armPagination = function() {
	let paginationDiv = document.querySelector('.pagination');
	paginationDiv.onclick = GNT_Ban_Hammer_restart;
	/*
	paginationDiv.innerHTML='';
	let paginationDivInner = document.querySelector('.pagination');
	let paginationLinks = paginationDiv.getElementsByTagName('a');
	for(let paginationLink of paginationLinks) {
		paginationLink.onclick = GNT_Ban_Hammer_restart;
	}
	*/
};

GNT_Ban_Hammer_start();

// the part below is just here as a quick check that there is no runtime error
var input=document.createElement("input");
input.type="button";
input.value="GreaseMonkey Button";
input.onclick = showAlert;
document.body.appendChild(input);
function showAlert() {
    alert("Hello World");
}

Posted in Greasemonkey scripts.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA