Skip to content
This repository has been archived by the owner on Dec 19, 2020. It is now read-only.

Commit

Permalink
implement #1 number 3
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiAurori committed Jul 25, 2018
1 parent dd82b23 commit 4a041db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions css/master.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
left: 64%;
}

a {
color: #0096cf;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

#spinningKiwi {
-webkit-animation: spin 3s infinite linear;
}
Expand Down
20 changes: 20 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ function load(token) {
});
});

// Open all links in external browser
let shell = require('electron').shell
document.addEventListener('click', function (event) {
if (event.target.tagName === 'A' && event.target.href.startsWith('http')) {
event.preventDefault()
shell.openExternal(event.target.href)
}
})

bot.on('message', (m) => {
if (selectedChan) {
if (m.channel.id == selectedChan.id) {
Expand Down Expand Up @@ -175,6 +184,7 @@ function load(token) {

let content = document.createTextNode(m.cleanContent);
text.appendChild(content);
text.innerHTML = urlify(text.innerHTML);
text.id = 'messageText';
div.appendChild(text);
if (scroll == true) {
Expand Down Expand Up @@ -471,6 +481,7 @@ function channelSelect(c, name) {
let content = document.createTextNode(m.cleanContent);
text.appendChild(content);
text.id = 'messageText';
text.innerHTML = urlify(text.innerHTML);
div.appendChild(text);
});
}
Expand Down Expand Up @@ -644,6 +655,15 @@ function changeUname() {
document.getElementById("usernameBox").value = '';
}

function urlify(text) {
var urlRegex = /(https?:\/\/[^\s]+)/g;
return text.replace(urlRegex, function(url) {
return '<a href="' + url + '" target="_blank">' + url + '</a>';
})
// or alternatively
// return text.replace(urlRegex, '<a href="$1">$1</a>')
}

function options(type, content) {
switch(type) {
case 'username':
Expand Down

0 comments on commit 4a041db

Please sign in to comment.