Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active January 2, 2016 14:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rlemon/7460953 to your computer and use it in GitHub Desktop.
Save rlemon/7460953 to your computer and use it in GitHub Desktop.
WELCOME USER USERSCRIPT Yissss
// ==UserScript==
// @name WELCOME USER
// @author Robert Lemon
// @version 1.1
// @namespace
// @description Adds a welcome button to the chat.
// @include http://chat.stackoverflow.com/rooms/*
// ==/UserScript==
function exec(fn) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = '(' + fn + ')();';
document.body.appendChild(script); // run the script
}
window.addEventListener("load", function () {
// script injection
exec(function () {
var btn = $('<button class="button" style="margin-left: 2px;">Welcome</button>'),
room = document.forms[0].elements.room.value;
btn.on('click', function () {
var modal = $('<div><h4>Welcome Whom?</h4></div>'),
$users = $('#present-users:not(.more)').clone();
modal.append($users).addClass('popup room-popup').css({
bottom: btn.position().top,
left: btn.position().left
}).on('click', function (e) {
if( e.target.className === 'more' ) {
return;
}
$('#input').val("@" + (e.target.title.replace(/ /g, '')) + " Welcome to the " + $('#roomname').text() + " chat! " + $('#roomdesc').text());
$('#sayit-button').click();
modal.remove();
return false;
});
$(document.body).append(modal);
return false;
});
$('#chat-buttons').append(btn);
});
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment