From aded7b1f3885b79476917d88ee6b3021c812aaab Mon Sep 17 00:00:00 2001 From: Xaekai Date: Mon, 11 Jul 2016 22:19:39 -0700 Subject: [PATCH] Allow users to strip images from chat. --- package.json | 2 +- templates/useroptions.pug | 1 + www/js/data.js | 4 +++- www/js/util.js | 15 ++++++++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1af082e3..cc65b03f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.18.6", + "version": "3.18.7", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/templates/useroptions.pug b/templates/useroptions.pug index 0265c25e..cf60900f 100644 --- a/templates/useroptions.pug +++ b/templates/useroptions.pug @@ -113,6 +113,7 @@ mixin us-chat option(value="always") Always +rcheckbox("us-sendbtn", "Add a send button to chat") +rcheckbox("us-no-emotes", "Disable chat emotes") + +rcheckbox("us-strip-image", "Remove images from chat") mixin us-mod #us-mod.tab-pane diff --git a/www/js/data.js b/www/js/data.js index 440b0b38..da23942b 100644 --- a/www/js/data.js +++ b/www/js/data.js @@ -67,6 +67,7 @@ var FILTER_TO = 0; var NO_STORAGE = typeof localStorage == "undefined" || localStorage === null; var SOCKETIO_CONNECT_ERROR_COUNT = 0; var HAS_CONNECTED_BEFORE = false; +var IMAGE_MATCH = /]*?src\s*=\s*['\"]([^'\"]*?)['\"][^>]*?>/gi; function getOpt(k) { var v = NO_STORAGE ? readCookie(k) : localStorage.getItem(k); @@ -120,7 +121,8 @@ var USEROPTS = { secure_connection : getOrDefault("secure_connection", false), show_shadowchat : getOrDefault("show_shadowchat", false), emotelist_sort : getOrDefault("emotelist_sort", true), - no_emotes : getOrDefault("no_emotes", false) + no_emotes : getOrDefault("no_emotes", false), + strip_image : getOrDefault("strip_image", false) }; /* Backwards compatibility check */ diff --git a/www/js/util.js b/www/js/util.js index d2564c40..f67a8cff 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -642,6 +642,7 @@ function showUserOptions() { $("#us-ping-sound").val(USEROPTS.boop); $("#us-sendbtn").prop("checked", USEROPTS.chatbtn); $("#us-no-emotes").prop("checked", USEROPTS.no_emotes); + $("#us-strip-image").prop("checked", USEROPTS.strip_image); $("#us-modflair").prop("checked", USEROPTS.modhat); $("#us-shadowchat").prop("checked", USEROPTS.show_shadowchat); @@ -675,6 +676,7 @@ function saveUserOptions() { USEROPTS.boop = $("#us-ping-sound").val(); USEROPTS.chatbtn = $("#us-sendbtn").prop("checked"); USEROPTS.no_emotes = $("#us-no-emotes").prop("checked"); + USEROPTS.strip_image = $("#us-strip-image").prop("checked"); if (CLIENT.rank >= 2) { USEROPTS.modhat = $("#us-modflair").prop("checked"); @@ -1433,6 +1435,16 @@ function sendVideoUpdate() { /* chat */ +function stripImages(msg){ + if (!USEROPTS.strip_image) { + return msg; + } + return msg.replace(IMAGE_MATCH, function(match,img){ + return CHANNEL.opts.enable_link_regex ? + ''+img+'' : img; + }); +} + function formatChatMessage(data, last) { // Backwards compat if (!data.meta || data.msgclass) { @@ -1452,6 +1464,7 @@ function formatChatMessage(data, last) { if (data.meta.forceShowName) skip = false; + data.msg = stripImages(data.msg); data.msg = execEmotes(data.msg); last.name = data.username; @@ -1519,8 +1532,8 @@ function addChatMessage(data) { if (data.meta.shadow && !USEROPTS.show_shadowchat) { return; } - var div = formatChatMessage(data, LASTCHAT); var msgBuf = $("#messagebuffer"); + var div = formatChatMessage(data, LASTCHAT); // Incoming: a bunch of crap for the feature where if you hover over // a message, it highlights messages from that user var safeUsername = data.username.replace(/[^\w-]/g, '\\$');