Skip to content

Instantly share code, notes, and snippets.

Created April 27, 2017 03:58
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 anonymous/ce323c5545f9447ed8d4d0ce2cfcf1ed to your computer and use it in GitHub Desktop.
Save anonymous/ce323c5545f9447ed8d4d0ce2cfcf1ed to your computer and use it in GitHub Desktop.
// ==UserScript==
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
// @name Instance mute for Mastodon
// @namespace https://mastodon.social/web/*
// @version 0.7
// @description
// @author https://mastodon.social/@yatchi
// @match https://mastodon.social/web/*
// @grant unsafeWindow
// @run-at document-end
// ==/UserScript==
// List the domains to mute here.
var mutedDomains = ['domain1.com', 'domain2.com'];
// List the domains to whitelist here. If there are any entries here, the list of muted domains will be ignored.
var whitelistedDomains = [];
function processStatus(status, whitelisting, re, skipColumnCheck) {
var displayName = status.find('span.display-name').first();
if (displayName.length > 0 && whitelisting === (re.exec(displayName.text()) === null) &&
(skipColumnCheck || $.contains($('div.columns-area > div:last-child').get(0), status.get(0)))) {
status.hide();
}
}
$(document).ready(function () {
if (mutedDomains.length + whitelistedDomains.length > 0) {
var whitelisting = whitelistedDomains.length > 0;
var domains = mutedDomains;
if (whitelisting) {
domains = whitelistedDomains;
}
domains = domains.map(function(str) { return ' @[^@]+@' + str.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&") + '$'; });
if (whitelisting) {
domains.push(' @[^@]+$');
}
var re = new RegExp(domains.join('|'), 'i');
$(document).on('DOMNodeInserted', function(e) {
if (window.location.pathname.endsWith('public')) {
var target = $(e.target);
if (target.hasClass('status')) {
processStatus(target, whitelisting, re);
}
else if (target.hasClass('column')) {
target.find('div.status').each(function() {
processStatus($(this), whitelisting, re, true);
})
}
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment