Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Added a feature that highlights posts with red border that contains words/phrases from a list #38

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/_locales/en_US/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,11 @@
},
"playMessageSounds":{
"message": "Play sound messages"
},
"highlightPostIfPersonSaysSomething":{
"message": "Highlight posts with these words"
},
"highlightPostIfPersonSaysSomethingDescription":{
"message": "Put a word or phrase on each line:"
}
}
1 change: 1 addition & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"scripts/kindling.emoji.js",
"scripts/kindling.sounds.js",
"scripts/kindling.highlight.js",
"scripts/kindling.highlightpostifpersonsayssomething.js",
"scripts/kindling.messagefilter.js",
"scripts/kindling.avatars.js",
"scripts/kindling.notificationpublisher.js",
Expand Down
9 changes: 9 additions & 0 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@
<label class="cb-disable selected"><span>{off}</span></label>
<label for="playMessageSounds" class="description">{playMessageSounds}</label>
</p>
<p class="field switch" id="highlightPostIfPersonSaysSomething" data-dependents="#highlightPostWordList">
<label class="cb-enable"><span>{on}</span></label>
<label class="cb-disable selected"><span>{off}</span></label>
<label for="highlightPostIfPersonSaysSomething" class="description">{highlightPostIfPersonSaysSomething}</label>
</p>
<div id="highlightPostWordList">
<p>{highlightPostIfPersonSaysSomethingDescription}</p>
<textarea rows="5" cols="30"></textarea>
</div>
</div>
</div>
<div class="panel">
Expand Down
1 change: 1 addition & 0 deletions src/scripts/kindling.background.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ kindling.module(function () {
initOption('useLargeAvatars', 'false');
initOption('minimalInterface', 'false');
initOption('expandAbbreviations', 'true');
initOption('highlightPostIfPersonSaysSomething', 'false');
initOption('htmlNotifications', 'true');
initOption('playMessageSounds', 'true');
initOption('showAvatarsInNotifications', localStorage.showAvatars === 'false' ? 'false' : 'true');
Expand Down
40 changes: 40 additions & 0 deletions src/scripts/kindling.highlightpostifpersonsayssomething.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
kindling.module(function () {
'use strict';

function resetPostBorders(){
$('#chat-wrapper div').css("border", "");
}

function changePostsBorder(wordList, borderStyle){
if(wordList == "") return;

var words = wordList.split('\n');
for(var i = 0; i < words.length; i++){
$('#chat-wrapper div:contains(' + words[i] + ')').css("border", borderStyle);
}
}

function highlightPostIfPersonSaysSomething(e, options, username) {

if(options.highlightPostIfPersonSaysSomething === 'true'){
changePostsBorder(options.highlightPostWordList, "9px solid red");
}

}

function onOptionsChanged(e, options) {

resetPostBorders();

if(options.highlightPostIfPersonSaysSomething === 'true'){
changePostsBorder(options.highlightPostWordList, "9px solid red")
}
}

return {
init: function () {
$.subscribe('newMessage', highlightPostIfPersonSaysSomething);
$.subscribe('optionsChanged', onOptionsChanged);
}
};
}());
23 changes: 22 additions & 1 deletion src/scripts/kindling.options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ kindling.module(function () {
'showAvatarsInChat',
'useLargeAvatars',
'playMessageSounds',
'useDifferentTheme'
'useDifferentTheme',
'highlightPostIfPersonSaysSomething'
];

function getMessages() {
Expand Down Expand Up @@ -73,6 +74,22 @@ kindling.module(function () {
onOptionChanged();
}

function onHighlightPostWordListChanged() {
var wordList = $('#highlightPostWordList textarea').val().split("\n");
wordList = removeEmptiesFromWordList(wordList);
localStorage.highlightPostWordList = wordList.join("\n");
onOptionChanged();
}

function removeEmptiesFromWordList(originalArray){
var i = 0;

while(i < originalArray.length)
originalArray[i] === "" ? originalArray.splice( i, 1 ) : i++;

return originalArray;
}

function onToggle(e) {
var option = $(e.currentTarget).attr('for');
var value = localStorage[option];
Expand All @@ -94,6 +111,8 @@ kindling.module(function () {

$('#themeColor input[title=' + localStorage.themeColor + ']').attr('checked', true);

$('#highlightPostWordList textarea').val(localStorage.highlightPostWordList);

var notificationTimeoutSlider = document.getElementById('notificationTimeout');
notificationTimeoutSlider.value = localStorage.notificationTimeout;
onNotificationTimeoutChanged();
Expand All @@ -117,6 +136,8 @@ kindling.module(function () {

$('#themeColor').change(onThemeColorChanged);

$('#highlightPostWordList').change(onHighlightPostWordListChanged);

initOptions();
}
};
Expand Down