-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbbPress-TopicHighlighter.user.js
55 lines (53 loc) · 2.75 KB
/
bbPress-TopicHighlighter.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ==UserScript==
// @name Topic Highlighter for bbPress / WordPress.com Forums
// @namespace https://emc.code.blog
// @version 1.0
// @description Add a colored flag to each post which matches a list of keywords
// @author Ethan Christensen
// @match https://wordpress.com/forums/*
// @grant none
// @updateURL https://raw.githubusercontent.com/ethanchristensen01/Ethan-Snippets/master/bbPress-TopicHighlighter.user.js
// @downloadURL https://raw.githubusercontent.com/ethanchristensen01/Ethan-Snippets/master/bbPress-TopicHighlighter.user.js
// ==/UserScript==
(function() {
'use strict';
// case insensitive contains selector by Highway of Life (https://stackoverflow.com/questions/8746882/jquery-contains-selector-uppercase-and-lower-case-issue)
jQuery.expr[':'].icontains = function(a, i, m) {
return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
};
class Topic {
constructor(color, keywords) {
this.color = color;
this.keywords = keywords;
}
query(searchClass) {
let selectors = this.keywords.map(topic => `${searchClass}:icontains('${topic}')`).join(', ');
return jQuery(`${selectors}`);
}
highlight(searchClass, parentClass) {
let query = this.query(searchClass);
let color = this.color;
query.each(
function() {
//in case we decide to add class instead of changing css: jQuery(this).closest('.topic').classList.add(this.topicClass);
jQuery(this).closest(parentClass).css("border-left", `5px solid ${color}`);
}
);
}
}
/*
Change colors and keywords for each priority here
*/
const Topics = [
/* last is most important */
/* .org probably or atomic */ new Topic('#ffea00', ['plugin', 'offline', 'error', 'host', 'godaddy']),
/* customization */ new Topic('#0099FF', ['theme', 'customi', 'design', 'widget', 'color', 'menu', 'tab', 'css', 'header', 'template', 'editor', 'font']),
/* JPOP, WOO */ new Topic('#66CC33', ['jet', 'woo', 'grav', 'vault', 'akismet', 'spam', 'avatar', 'export', 'import']),
/* accounts, TOS, etc */ new Topic('#ff9d00', ['account', 'hara', 'abuse', 'harra', 'login', 'log in', 'suspend', 'report', 'ads', 'application', 'conf', 'password', 'access', 'old', 'restor', 'recover', 'deleted']),
/* domains and billing */ new Topic('#CC0055', ['dns', 'domain', 'cancel', 'refund', 'bill', 'charge', 'url', 'postal', 'pay', 'renew', 'plan', 'currency', 'west', 'wwd'])
]
for(var topicIndex in Topics){
let topic = Topics[topicIndex];
topic.highlight('.bbp-topic-title', '.topic');
}
})();