Created
April 27, 2017 03:58
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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