Skip to content

Instantly share code, notes, and snippets.

@mohemohe

mohemohe/user.js Secret

Created May 30, 2019 06:43
Show Gist options
  • Save mohemohe/f6a84a08716b1b39093d71af0ae37528 to your computer and use it in GitHub Desktop.
Save mohemohe/f6a84a08716b1b39093d71af0ae37528 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Slack偽装
// @namespace io.plusminus.userscript.slack.fuck
// @version 0.1
// @match https://*.slack.com/*
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js
// ==/UserScript==
const config = {
userId: '',
userName: '',
dummyName: '†真名†',
dummyIcon: 'https://github.com/mohemohe.png',
};
const body = document.querySelector('body');
const mo = new MutationObserver(_.debounce(changes => {
const names = document.querySelectorAll(`.c-message__sender > a[href="/team/${config.userId}"]`);
if (names) {
Array.from(names).forEach(name => {
name.innerHTML = config.dummyName;
});
}
const links = document.querySelectorAll(`.c-member_slug--mention[href="/team/${config.userId}"]`);
if (links) {
Array.from(links).forEach(link => {
link.innerHTML = `@${config.dummyName}`;
});
}
const icons = document.querySelectorAll(`.c-avatar[href="/team/${config.userId}"] > img`);
if (icons) {
Array.from(icons).forEach(icon => {
icon.src = config.dummyIcon;
});
}
const messages = document.querySelectorAll('.c-message__body');
if (messages) {
Array.from(messages).forEach(message => {
message.innerHTML = message.innerHTML.replace(new RegExp(config.userName, 'g'), config.dummyName);
});
}
}), 1000);
mo.observe(body, {
childList: true,
subtree: true,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment