Last active
November 1, 2019 16:24
-
-
Save disjukr/3519dc1b0381db383defed2705b02ecc to your computer and use it in GitHub Desktop.
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 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