Skip to content

Instantly share code, notes, and snippets.

@dpedu
Created January 4, 2019 15:42
Show Gist options
  • Save dpedu/32870848d0b67f95a693e1e17eb6b716 to your computer and use it in GitHub Desktop.
Save dpedu/32870848d0b67f95a693e1e17eb6b716 to your computer and use it in GitHub Desktop.
Meme text userscript for IRCCloud
// ==UserScript==
// @name mirccloud.meme.user.js
// @namespace https://github.com/dpedu/mirccloud
// @description Meme Text for IRCCloud
// @downloadURL https://raw.githubusercontent.com/dpedu/mirccloud/master/mirccloud.meme.user.js
// @version 0.1
// @match https://www.irccloud.com/*
// @noframes
// @grant none
// ==/UserScript==
COMMAND = '/meme';
function checkCommand(inputData) {
if(inputData.startsWith(COMMAND)) {
return inputData.substring(COMMAND.length + 1).toUpperCase()
}
return false;
}
(function() {
function init() {
var context = window.SESSIONVIEW.mainArea.current.input.__proto__.say;
window.SESSIONVIEW.mainArea.current.input.__proto__.say = function(inputData) {
var data = checkCommand(inputData);
if (data === false) {
context.apply(this, [inputData]);
} else {
this.clear();
var output = []
var last = false;
for(var i=0;i<data.length;i++) {
var ccode = data.charCodeAt(i)
if(65 <= ccode && ccode <= 90 && last) { // randBool()
output.push(String.fromCharCode(ccode + 32));
} else output.push(data[i]);
last = !last;
}
context.apply(this, [output.join('')]);
}
};
}
(function checkSession() {
if (window.hasOwnProperty('SESSION')) {
if (window.SESSION.initialized) {
init();
} else {
window.SESSION.bind('init', function() {
init();
});
}
} else {
window.setTimeout(checkSession, 100);
}
})();
})();
function randChoice(choices) {
return choices[Math.floor(Math.random() * choices.length)];
}
function randBool() {
return randChoice([true, false])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment