Skip to content

Commit

Permalink
add setting to make all spoilers visible
Browse files Browse the repository at this point in the history
  • Loading branch information
SmCTwelve committed Jul 6, 2019
1 parent a7e0a59 commit 0fb1032
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const settingsdefault = new Map([
['hidensfw', false],
['animateforever', true],
['formatter-green', true],
['formatter-emote', true]
['formatter-emote', true],
['showspoilers', false]
]);
const commandsinfo = new Map([
['help', {desc: 'Helpful information.'}],
Expand Down
10 changes: 6 additions & 4 deletions assets/chat/js/formatters.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UserFeatures from './features';
import {GENERIFY_OPTIONS, HALLOWEEN_RANDOM_EFFECTS, HALLOWEEN_RANDOM_DELAYS, HALLOWEEN_BLACKLIST, HAT_BLACKLIST, HAT_SPECIAL_BLACKLIST} from './const'
//import Chat from './chat';


/** @var Array tlds */
Expand Down Expand Up @@ -256,7 +257,8 @@ class CodeFormatter {
}
}

function stringSpoilerParser(str) {
function stringSpoilerParser(str, visible) {
var classes = visible ? 'spoiler visible' : 'spoiler';
var indexOne = str.indexOf('||');
if (indexOne !== -1) {
var afterTag = str.substring(indexOne + 2);
Expand All @@ -265,16 +267,16 @@ function stringSpoilerParser(str) {
var betweenTags = afterTag.substring(0, indexTwo);
var subString = RegExp('^\\s*$').test(betweenTags)
? str.substring(0, indexOne) + '||||'
: str.substring(0, indexOne) + `<span class="spoiler">${betweenTags.trim()}</span>`;
str = subString + stringSpoilerParser(afterTag.substring(indexTwo + 2));
: str.substring(0, indexOne) + `<span class="${classes}">${betweenTags.trim()}</span>`;
str = subString + stringSpoilerParser(afterTag.substring(indexTwo + 2), visible);
}
}
return str;
}

class SpoilerFormatter {
format(chat, str, message = null) {
return stringSpoilerParser(str);
return stringSpoilerParser(str, chat.settings.get('showspoilers'));
}
}

Expand Down
5 changes: 5 additions & 0 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ <h4>Messages</h4>
<input name="animateforever" type="checkbox" /> Loop animated emotes forever
</label>
</div>
<div class="form-group checkbox">
<label title="Always show spoilers">
<input name="showspoilers" type="checkbox" /> Always show spoilers
</label>
</div>
<div class="form-group">
<label for="showremoved">Banned messages</label>
<select class="form-control" id="showremoved" name="showremoved">
Expand Down

0 comments on commit 0fb1032

Please sign in to comment.