Skip to content

Instantly share code, notes, and snippets.

@unarist
Last active November 14, 2019 16:38
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 unarist/60d3cea2a4ac37f8e302209df6d170f6 to your computer and use it in GitHub Desktop.
Save unarist/60d3cea2a4ac37f8e302209df6d170f6 to your computer and use it in GitHub Desktop.
Mastodon - PII spoiler
// ==UserScript==
// @name Mastodon - PII spoiler
// @namespace https://github.com/unarist/
// @version 0.3.0
// @description Hide sensitive information on admin page
// @author unarist
// @downloadURL https://gist.github.com/unarist/60d3cea2a4ac37f8e302209df6d170f6/raw/mastodon-pii-spoiler.user.js
// @match https://*/admin/accounts/*
// @match https://*/admin/accounts?*
// @grant none
// @noframes
// ==/UserScript==
(function() {
'use strict';
const patterns = [
/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/, // email
/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/, // v4 addr
/^(?:[0-9a-fA-F]{0,4}:)+[0-9a-fA-F]{0,4}[\d\.]*$/, // v6 addr (w/ v4)
];
const regex = new RegExp('^(?:' + patterns.map(pattern => pattern.source).join(')|(') + ')$', 'g');
const onClick = e => e.target.textContent = e.target.dataset.originalValue;
for (const node of document.querySelectorAll('td')) {
const text = node.textContent.trim();
if (regex.test(text)) {
node.dataset.originalValue = text;
node.textContent = '<click to show>';
node.addEventListener('click', onClick);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment