Last active
November 14, 2019 16:38
-
-
Save unarist/60d3cea2a4ac37f8e302209df6d170f6 to your computer and use it in GitHub Desktop.
Mastodon - PII spoiler
This file contains hidden or 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== | |
// @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