NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Toggle Comments
// @namespace http://tampermonkey.net/
// @version 1.02
// @description Allows toggling comments on episodes
// @copyright 2018, gazza911 (https://openuserjs.org/users/gazza911)
// @license MIT
// @match http://www.tvmaze.com/episodes/*
// @match https://www.tvmaze.com/episodes/*
// @updateURL https://openuserjs.org/meta/gazza911/Toggle_Comments.meta.js
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
$(`<style>
.hiddenComment {
filter: blur(5px);
}
.block {
color: grey;
cursor: pointer;
}
</style>`).appendTo("head");
var bannedList = [];
var banned = GM_getValue("tvmaze-bannedUsers");
if (banned !== undefined) {
bannedList = JSON.parse(banned);
}
var comments = {};
var blockIcon = "<i class='block fa fa-lg fa-lock'></i>";
$("#comment-listview div article.comment .row section").each(function() {
var $header = $(this).children("header:first");
var username = $header.children("a:first").text();
var $comment = $(this).children("article:first");
$header.append(blockIcon);
var $block = $header.find(".block");
$block.attr("title", "Block all of " + username + "'s comments");
if ($.inArray(username, bannedList) > -1)
{
$comment.toggleClass("hiddenComment");
$header.toggleClass("blockedUser");
$block.toggleClass("fa-lock fa-unlock-alt");
$block.attr("title", "Un-Block all of " + username + "'s comments");
}
if (comments[username] === undefined) {
comments[username] = [];
}
comments[username].push($(this));
});
$("article.hiddenComment").mousedown(function() {
$(this).removeClass("hiddenComment");
});
$(".block").click(function() {
var currentlyBlocked = $(this).hasClass("fa-unlock-alt");
var username = $(this).parent().children("a:first").text();
$(comments[username]).each(function() {
var $header = $(this).children("header:first");
var $comment = $(this).children("article:first");
var $block = $header.find(".block");
if (!currentlyBlocked || $comment.hasClass("hiddenComment")) {
$comment.toggleClass("hiddenComment");
}
$header.toggleClass("blockedUser");
$block.toggleClass("fa-lock fa-unlock-alt");
$block.attr("title", (!currentlyBlocked ? "Un-" : "") + "Block all of " + username + "'s comments");
});
if (currentlyBlocked) {
var index = bannedList.indexOf(username);
bannedList.splice(index, 1);
}
else {
bannedList[bannedList.length] = username;
}
GM_setValue("tvmaze-bannedUsers", JSON.stringify(bannedList));
});