Created
February 9, 2014 17:16
-
-
Save jonasbits/8902391 to your computer and use it in GitHub Desktop.
Script for CIRC running on Chrome/Chromium based on https://github.com/flackr/circ/tree/master/example_scripts (password does not persist if you uninstall and install this script)
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
/**********************/ | |
//jslint vars: true // change from block comment to line comment if you want to ignore a jslint option | |
/*jslint sloppy: true */ | |
/*jslint white: true */ | |
/*jslint indent: 2 */ | |
/*jslint debug: true */ | |
/**********************/ | |
/**********************/ | |
/* make jslint happy */ | |
/**********************/ | |
/* change from block comment to line comment when running jslint | |
function setName() {} function setDescription() {} function send() {} function loadFromStorage() {} function updatePasswords() {} function handlePrivateMessage() {} function propagate() {} function shouldAutoIdentify() {} function autoIdentify() {} function nickServPasswordIsVisible() {} function snoopPassword() {} function hideNickServPassword() {} function saveToStorage() {} function getHiddenPasswordText() {} function sendEvent() {} | |
*/ | |
//change above from block comment to line comment when running jslint | |
/******************************/ | |
/* end of making jslint happy */ | |
/******************************/ | |
setName('auto_identify'); | |
setDescription('hides NickServ password and automatically identifies on startup'); | |
send('hook_message', 'privmsg'); | |
loadFromStorage(); | |
// Keeps track of the last NickServ password used in each server. | |
var serverPasswords = {}; | |
this.onMessage = function (e) { | |
if (e.type === 'system' && e.name === 'loaded' && e.args[0]) { | |
updatePasswords(e.args[0]); | |
} else if (e.type === 'message' && e.name === 'privmsg') { | |
handlePrivateMessage(e); | |
} else { | |
propagate(e); | |
} | |
}; | |
var handlePrivateMessage = function (event) { | |
var source = event.args[0], message = event.args[1]; | |
if (source.toLowerCase() !== 'nickserv') { | |
propagate(event); | |
} else if (shouldAutoIdentify(event.context, message)) { | |
propagate(event); | |
autoIdentify(event.context, message); | |
} else if (nickServPasswordIsVisible(message)) { | |
propagate(event, 'none'); | |
snoopPassword(event.context, message); | |
hideNickServPassword(event); | |
} else { | |
propagate(event); | |
} | |
}; | |
var shouldAutoIdentify = function (context, message) { | |
return message.indexOf('nickname is registered') >= 0 && | |
serverPasswords[context.server]; | |
}; | |
var autoIdentify = function (context) { | |
//message is not used - jonasbits | |
var pw = serverPasswords[context.server]; | |
send(context, 'message', 'notice', 'Automatically identifying nickname with NickServ...'); | |
send(context, 'command', 'raw', 'PRIVMSG', 'NickServ', '"identify', pw + '"'); | |
}; | |
var nickServPasswordIsVisible = function (message) { | |
var words = message.split(' '); | |
return words.length === 2 && words[0].toLowerCase() === 'identify'; | |
}; | |
var snoopPassword = function (context, message) { | |
var password = message.split(' ')[1]; | |
serverPasswords[context.server] = password; | |
saveToStorage(serverPasswords); | |
}; | |
var hideNickServPassword = function (event) { | |
var words = event.args[1].split(' '); | |
words[1] = getHiddenPasswordText(words[1].length); | |
event.args[1] = words.join(' '); | |
sendEvent(event); | |
}; | |
var getHiddenPasswordText = function (length) { | |
var hiddenPasswordText = '', i = 0; | |
for (i = 0; i < length; i += 1) { | |
hiddenPasswordText += '*'; | |
} | |
return hiddenPasswordText; | |
}; | |
var updatePasswords = function (loadedPasswords) { | |
var server; | |
for (server in loadedPasswords) { | |
if (loadedPasswords.hasOwnProperty(server)) { | |
if (!serverPasswords[server]) { | |
serverPasswords[server] = loadedPasswords[server]; | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment