Skip to content

Commit

Permalink
updates and shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolf Van Herreweghe committed Aug 10, 2015
1 parent 3c00ff6 commit 38ef9e9
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 13 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Hack.Chat Enhancement suite",
"version": "0.0.3",
"name": "Hack.Chat Enhancement kit",
"version": "0.0.4",
"manifest_version": 2,
"description": "Adds various functions to Hack.Chat - made by ToastyStoemp",
"homepage_url": "https://github.com/ToastyStoemp",
Expand Down
1 change: 1 addition & 0 deletions src/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ function injectScript(file) {
s.setAttribute('src', file);
document.body.appendChild(s);
}

injectScript(chrome.extension.getURL('./src/main.user.js'));
89 changes: 78 additions & 11 deletions src/main.user.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
var messageSound = new Audio('https://www.freesound.org/people/bubaproducer/sounds/107156/download/107156__bubaproducer__button-9-funny.wav');
var notifySound = new Audio('https://www.freesound.org/people/JustinBW/sounds/80921/download/80921__justinbw__buttonchime02up.wav');

var sidebar = document.getElementById("sidebar-content");

var para = document.createElement("p");
Expand All @@ -10,6 +13,16 @@ para.appendChild(text);
sidebar.appendChild(para);
sidebar.insertBefore(para, sidebar.childNodes[4]);

para = document.createElement("p");
var SoundCheckbox = document.createElement("INPUT");
SoundCheckbox.type = "checkbox";
SoundCheckbox.checked = true;
text = document.createTextNode("Sound");
para.appendChild(SoundCheckbox);
para.appendChild(text);
sidebar.appendChild(para);
sidebar.insertBefore(para, sidebar.childNodes[5]);

para = document.createElement("p");
var btn = document.createElement("BUTTON");
btn.appendChild(document.createTextNode("Ignore User"));
Expand All @@ -23,7 +36,19 @@ btn.onclick = function() {
};
para.appendChild(btn);
sidebar.appendChild(para);
sidebar.insertBefore(para, sidebar.childNodes[5]);
sidebar.insertBefore(para, sidebar.childNodes[6]);

para = document.createElement("p");
btn = document.createElement("BUTTON");
btn.appendChild(document.createTextNode("Call Mod"));
btn.onclick = function() {
send({cmd: 'chat', nick: myNick, text: '.callMod ' + prompt("Enter name of suspect") + ' ' + prompt("Enter reason")});
btn.disabled = true;
setTimeout(function(){ btn.disabled = false; }, 30000);
};
para.appendChild(btn);
sidebar.appendChild(para);
sidebar.insertBefore(para, sidebar.childNodes[7]);

if (pushMessageOrig)
pushMessage = pushMessageOrig;
Expand All @@ -32,11 +57,33 @@ var pushMessageOrig = pushMessage;
var yourNick = myNick.split("#")[0];
pushMessage = function(args) {
pushMessageOrig(args);
var msg = args.text;
if (msg.indexOf("invited you to ?") != -1) {
var nick = msg.substr(0, msg.indexOf(' '));
var channel = msg.substr(msg.indexOf('?') + 1, 8);
notifyMe(nick + " invited you", "Click here to accept.", false, channel);
}
if (args.nick != "*") {
var msg = args.text;
if (msg.indexOf(yourNick) != -1 && !document.hasFocus())
if (msg.indexOf('.callMod') != -1) {
if (canCallMod) {
send({
cmd: 'chat',
nick: myNick,
text: '@' + args.nick + ' I have been alarmed'
});
var begin = msg.indexOf(' ') + 1;
var end = msg.indexOf(' ', begin);
var suspectlength = end - begin;
var suspect = msg.substr(begin, suspectlength);
_callMod(args.nick, suspect, msg.substr(end, msg.length - end));
}
}
if (msg.indexOf(yourNick) != -1 && !document.hasFocus()) {
if (NotCheckbox.checked)
notifyMe(args.nick, args.text);
notifyMe(args.nick + " mentioned you", args.text, false);
} else
if (SoundCheckbox.checked)
messageSound.play();
}
if (document.hasFocus()) {
window.unread = 0;
Expand All @@ -55,7 +102,7 @@ window.onfocus = function() {
window.updateTitle();
}

function notifyMe(sender, text) {
function notifyMe(title, text, sound, channel) {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chrome.');
return;
Expand All @@ -64,21 +111,41 @@ function notifyMe(sender, text) {
if (Notification.permission !== "granted")
Notification.requestPermission();
else
_notifiyMe(sender, text);
_notifiyMe(title, text, sound, channel);
}

function _notifiyMe(sender, text) {
var not = new Notification(sender + " mentioned you", {
function _notifiyMe(title, text, sound, channel) {
if (SoundCheckbox.checked)
notifySound.play();
var Channel = channel;
var not = new Notification(title, {
body: text,
icon : 'http://i.imgur.com/44B3G6a.png'
icon: 'http://i.imgur.com/44B3G6a.png'
});


not.onclick = function() {
window.focus()
if (Channel) {
console.log(Channel);
window.open('https://hack.chat/?' + Channel, '_blank');
} else
window.focus()
};
setTimeout(function() {
not.close();
notifications.splice(notifications.indexOf(not), 1);
}, 4000);
}, 8000);
notifications.push(not);
}


// $\color{orange}{\large{Hack.Chat \space chrome \space extension}} \space \color{lightblue}{0.0.3}$
// $made \space by \space \color{cyan}{ToastyStoemp}$
// download here: https://db.tt/8ErFlCcq
// just drag and drop in: chrome://extensions/
//
// A quick reminder that there is a chrome extension for hack.chat;
// This extension adds notification upon your name being mentioned (@nick),
// and adds the user ignore GUI button in the sidebar :)
//
// More to come!
9 changes: 9 additions & 0 deletions style/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.me {
.text, .nick {
color: @base0D !important;
}
}

.nick {
color: @base09 !important;
}

0 comments on commit 38ef9e9

Please sign in to comment.