Skip to content

Instantly share code, notes, and snippets.

@calebdoxsey
Created August 26, 2013 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calebdoxsey/6341518 to your computer and use it in GitHub Desktop.
Save calebdoxsey/6341518 to your computer and use it in GitHub Desktop.
Ignore button for ricochet
// ==UserScript==
// @name Ricochet Ignore Button
// @namespace http://www.doxsey.net
// @version 1.0
// @description ignore users
// @match http://ricochet.com/*
// @copyright 2013, Caleb Dioxsey
// ==/UserScript==
$(function() {
var ignored = JSON.parse(localStorage.getItem("GM-ignored") || "{}");
function ignore(author) {
ignored[author] = true;
localStorage.setItem("GM-ignored", JSON.stringify(ignored));
refresh();
}
function unignore(author) {
delete ignored[author];
localStorage.setItem("GM-ignored", JSON.stringify(ignored));
refresh();
}
function show($el) {
$el.css("opacity", 1);
$el.find(".body, .action-links, .profile-image").show();
$el.find(".show-ignored, .unignore").remove();
}
function hide($el) {
$el.css("opacity", 0.5);
$el.find(".body, .action-links, .profile-image").hide();
$el.find(".author").after([
'<a href="#show" class="show-ignored"> · Show</a> ',
'<a href="#unignore" class="unignore"> · Unignore</a> ',
].join(""));
}
function refresh() {
$("div.comment").each(function() {
if (ignored[$(this).attr("author_id")]) {
hide($(this));
} else {
show($(this));
}
});
}
$(".action-links ul").append([
'<li>· <a href="#ignore" class="ignore">Ignore</a></li>'
].join(""));
$("body")
.on("click", ".ignore", function(evt) {
evt.preventDefault();
ignore($(this).closest("[author_id]").attr("author_id"));
})
.on("click", ".unignore", function(evt) {
evt.preventDefault();
unignore($(this).closest("[author_id]").attr("author_id"));
})
.on("click", ".show-ignored", function(evt) {
evt.preventDefault();
show($(this).closest(".comment"));
});
refresh();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment