Tampermonkey script to extend usability on the Pimax forum

I’ve been on the forum for around a year now, and during that time I have found a few people that have been a little annoying from time to time. So I asked @Heliosurge a few times if there was any way to block or hide someone on the forum.

It turns out that the forum is a little lacking in that capability. So I rolled my own solution that can be used by just about anyone. The only thing it requires is the browser extension Tampermonkey. I would have preferred to tie it into the mute feature of the forum… but alas I could not.

Initially it was very basic, but only I was using it and it was a little buggy. So I improved it, it is very solid now.

Administrators and moderators are clearly marked now, so there isn’t any confusion about that anymore.
The creator of a thread is also clearly marked as the thread owner.
And, the people that have annoyed you are now clearly marked as being a Hidden user. Their comments are hidden from you while showing you that they posted something. You can view what they posted by clicking on their post, and you can click it again to hide it. You simply have to add a username into the array of hidden users at the top of the script and make sure the script is saved and working. You can’t hide Admins/Mods, they might have something important to say. Even if you don’t like it.

All of you are free to look at the IMO rather simple code and critique it. If you have any ideas to improve the functionality or include a new feature, let me now. I will probably add more features as I think of them.

I don’t name who has annoyed me in it, so hopefully that shouldn’t cause any issues.

You can find the script below in the first post, since I can only upload pictures.

Edit: Looks like the script is partially borked in the comment below. I’ll fix it, but it will happen after I get off work.

1 Like

// ==UserScript==
// @name Extend Pimax Forum
// @namespace http://tampermonkey.net/
// @version 1.0
// @description I started off just wanting to hide the comments from some annoying people, but ended up adding additional functionality.
// @author Kopa
// @match http://community.openmr.ai/*
// @grant none
// ==/UserScript==

// To add a user just follow this format var HiddenUsers = [‘username1’,‘username2’,‘username3’,‘username4’];
var HiddenUsers = [‘’];

$(document).ready(function() {
HideUsers();
TagUsers();

$(document).bind("load", function() {
    setTimeout(function() {
        HideUsers();
        TagUsers();
    }, 100);
});

$(document).bind("animationstart", function() {
    setTimeout(function() {
        HideUsers();
        TagUsers();
    }, 200);
});

$(document).bind("scroll", function() {
    setTimeout(function() {
        HideUsers();
        TagUsers();
    }, 100);
});

$(document).bind("click", function(e) {
    setTimeout(function() {
        $(HiddenUsers).each(function(index) {
            var userID = $(e.target).parentsUntil("div.topic-post").last().data().userId;
            if (userID == GetUserId(this)) {
                ShowHideUser(e);
                return;
            }
        });
    }, 100);
});

});

// Tagging functionality
function TagUsers() {
TagAdminMods();
TagTopicOwner();
TagHiddenUser();
}

function TagAdminMods() {
var moderators = $(“span.moderator”);
$(moderators).each(function(index) {
if (!$(this).hasClass(“admin”)) {
if (!$(this).find(“span”).hasClass(“modtag”)) {
$(this).append(“<span class=‘modtag’ style=‘border:1px solid #BCC6CC; border-radius:10px; background-color:#808080; color:#FFF; margin-left:auto; padding-left:10px; margin-left:5px;’>Moderator</span>”);
}
}
else {
if (!$(this).find(“span”).hasClass(“admintag”)) {
$(this).append(“<span class=‘admintag’ style=‘border:1px solid #D4A017; border-radius:10px; background-color:#808080; color:#FFF; margin-left:auto; padding-left:10px; margin-left:5px;’>Administrator</span>”);
}
}
});
}

function TagTopicOwner() {
var owner = $(“.topic-owner”);
$(owner).each(function(index) {
if (!$(this).find(“span.username”).find(“span”).hasClass(“topicownertag”)) {
$(this).find(“span.username”).append(“<span class=‘topicownertag’ style=‘border:1px solid #D3D3D3; border-radius:10px; background-color:#008000; color:#FFF; margin-left:auto; padding-left:10px; margin-left:5px;’>Owner</span>”);
}
});
}

function TagHiddenUser() {
$(HiddenUsers).each(function(index) {
var currentUserId = GetUserId(this);
var currentUser = $(“[data-user-id='” + currentUserId + “']”);
if (!$(currentUser).find(“span.username”).hasClass(“moderator”))
{
$(currentUser).find(“span.username”).addClass(“hiddenuser”);
$(currentUser).each(function(subIndex) {
if (!$(this).find(“span.hiddenuser > span”).hasClass(“hiddentag”)) {
$(this).find(“span.hiddenuser”).append(“<span class=‘hiddentag’ style=‘border:1px solid #D3D3D3; border-radius:10px; background-color:#FF0000; color:#FFF; margin-left:auto; padding-left:10px; margin-left:5px;’>Hidden User</span>”);
}
});
}
});
}
// End Tagging functionality

// Hide specified users functionality
function HideUsers() {
$(HiddenUsers).each(function(index) {
HideUser(this);
});
}

function HideUser(userName) {
var currentUserId = GetUserId(userName);
var currentUser = $(“[data-user-id='” + currentUserId + “']”);
if (!$(currentUser).find(“span.username”).hasClass(“moderator”))
{
$(currentUser).each(function(index) {
if (!$(this).find(“div.cooked”).hasClass(“postshown”)) {
$(this).find(“div.cooked”).attr(“style”, “height: 0px !important;”);
}
var plusTag = $(this).find(“div.regular > div.plus”);
if (plusTag.length == 0) {
$(this).find(“div.regular”).prepend(“<div id=‘" + currentUserId + "’ class=‘plus fa fa-plus’ style=‘height: 15px !important; width: 175px; border:1px solid #D3D3D3; border-radius:10px; padding:5px; background-color:red; color: #FFF;’><span style=‘padding-left:10px; font-weight:bold;’>Show post content</span></div>”);
}
});
}
}

function ShowHideUser(e) {
var userID = e.target.id;
var postId = $(e.target).parentsUntil(“div.topic-post”).last().data().postId;
var currentPost = $(“[data-post-id='” + postId + “']”);
if ($(currentPost).find(“span.username”).hasClass(“hiddenuser”)) {
if ($(currentPost).find(“div.regular > div.cooked”).hasClass(“postshown”)) {
$(currentPost).find(“div.regular > div.plus”).addClass(“fa-plus”).removeClass(“fa-minus”);
$(currentPost).find(“div.regular > div.plus > span”).html(“Show post content”);
$(currentPost).find(“div.regular > div.cooked”).removeClass(“postshown”);
$(currentPost).find(“div.regular > div.cooked”).attr(“style”, “height: 0px !important;”);
}
else {
$(currentPost).find(“div.regular > div.plus”).addClass(“fa-minus”).removeClass(“fa-plus”);
$(currentPost).find(“div.regular > div.plus > span”).html(“Hide post content”);
$(currentPost).find(“div.regular > div.cooked”).addClass(“postshown”);
$(currentPost).find(“div.regular > div.cooked”).attr(“style”, “height: 100%;”);
}
}
}

function GetUserId(userName) {
var currentUser = $(“span.username > a[data-user-card='” + userName + “']”);
if (currentUser.length > 0)
return $(currentUser).parentsUntil(“div.topic-post”).last().data().userId;
return 0;
}
// End Hide specified users functionality

2 Likes

Cool. This doesn’t work for mobile browsers I suppose?

1 Like

It should work for Android as the extension is available for it.

1 Like

So there was an issue where the forum totally borked the html tags that get injected into the site.
This broke the script, sadly I didn’t catch it very quickly. I was tired and it was the weekend…
I fixed said formatting… sometimes WYSIWYGs are a pain in the… well… hopefully you get what I’m saying.

Give it a try folks. I’ll attach a few pictures for those of you still on the fence.

1 Like

Here are the screenshots. @acegamer is cool, I was using them as an example for the Hidden User functionality.

https://imgur.com/unN656r

https://imgur.com/aIcrNfR

https://imgur.com/HeBRHbq