Skip to content

Instantly share code, notes, and snippets.

@disjukr
Last active November 1, 2019 16:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disjukr/3519dc1b0381db383defed2705b02ecc to your computer and use it in GitHub Desktop.
Save disjukr/3519dc1b0381db383defed2705b02ecc to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name langdev irccloud
// @namespace http://0xABCDEF.com/userscript/irccloud/langdev
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.irccloud.com/*
// @grant none
// ==/UserScript==
(function () {
const botNames = ['[]', 'LangDev', 'slairck'];
function nicknameColor(nickname) {
let hash = 0;
for (let i = 0; i < nickname.length; ++i) {
hash += nickname.charCodeAt(i);
}
return `#${ parseInt(((hash + 0x10) * 99999).toString(16).substr(0, 6), 16) & 0x8f8f8f }`;
}
setInterval(() => {
const $currentChannelContainer = $('.buffercontainer.channel:not(.buffercontainer--hidden)');
const channelLabel = $('.bufferHeading .bufferlabel', $currentChannelContainer).text();
if (channelLabel === '#langdev') {
$('.message', $currentChannelContainer).each(function () {
const $message = $(this);
const $nickname = $message.find('[role=button]');
if (botNames.indexOf($nickname.text()) === -1) return;
if ($message.data('nickpatch')) return;
$message.data('nickpatch', true);
const $content = $message.find('.content');
const firstNode = $content[0].childNodes[0];
const match = /^\s*<(.*?)> (.*)/.exec(firstNode.textContent);
if (match) {
const [_, nickname, text] = match;
firstNode.textContent = text;
$nickname.text(nickname);
$nickname.css('color', nicknameColor(nickname));
}
});
}
}, 500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment