From 4a041db6b776f513299a89205a5291c4e4b726ff Mon Sep 17 00:00:00 2001 From: flamergamer1234 <31465218+flamergamer1234@users.noreply.github.com> Date: Wed, 25 Jul 2018 10:05:18 -0400 Subject: [PATCH] implement #1 number 3 --- css/master.css | 9 +++++++++ js/app.js | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/css/master.css b/css/master.css index 07a1d1bc..94deaeed 100644 --- a/css/master.css +++ b/css/master.css @@ -29,6 +29,15 @@ left: 64%; } +a { + color: #0096cf; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + #spinningKiwi { -webkit-animation: spin 3s infinite linear; } diff --git a/js/app.js b/js/app.js index 2a82b4f9..da2f74c3 100644 --- a/js/app.js +++ b/js/app.js @@ -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) { @@ -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) { @@ -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); }); } @@ -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 '' + url + ''; + }) + // or alternatively + // return text.replace(urlRegex, '$1') +} + function options(type, content) { switch(type) { case 'username':