From b02ad52f8f4534ba351578b581efad658698bd45 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 11 Feb 2023 16:02:48 -0800 Subject: [PATCH] Externalize links sent in chat --- web/static/js/BareRTC.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/web/static/js/BareRTC.js b/web/static/js/BareRTC.js index 1fec4fb..417c5f3 100644 --- a/web/static/js/BareRTC.js +++ b/web/static/js/BareRTC.js @@ -669,6 +669,9 @@ const app = Vue.createApp({ // Responsive CSS: switch back to chat panel upon selecting a channel. this.openChatPanel(); + + // Edit hyperlinks to open in a new window. + this.makeLinksExternal(); }, hasUnread(channel) { if (this.channels[channel] == undefined) { @@ -957,6 +960,9 @@ const app = Vue.createApp({ this.channels[channel].unread++; } } + + // Edit hyperlinks to open in a new window. + this.makeLinksExternal(); }, scrollHistory() { @@ -1088,6 +1094,19 @@ const app = Vue.createApp({ // Store the user's setting in localStorage. localStorage[`sound:${event}`] = this.config.sounds.settings[event]; }, + + makeLinksExternal() { + window.requestAnimationFrame(() => { + let $history = document.querySelector("#chatHistory"); + // Make all links appearing in chat into external links. + ($history.querySelectorAll("a") || []).forEach(node => { + let href = node.attributes.href, + target = node.attributes.target; + if (href == undefined || target != undefined) return; + node.target = "_blank"; + }); + }) + }, } });