forked from BenLubar/nodebb-plugin-user-css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (36 loc) · 1.16 KB
/
index.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
const db = require.main.require('./src/database');
const validator = require('validator');
const plugin = module.exports;
async function getCustomCSS(uid) {
if (!uid) {
return '';
}
return await db.getObjectField('user:' + uid + ':settings', 'customCSS') || '';
}
plugin.addCustomSetting = function (data) {
const customCSS = data.settings.customCSS || '';
data.customSettings.push({
'title': 'Custom CSS',
'content': '<textarea data-property="customCSS" class="form-control" type="textarea">' + validator.escape(customCSS) + '</textarea><p class="help-block">Requires a refresh to take effect.</p>'
});
return data;
};
plugin.filterUserSaveSettings = async function (hookData) {
hookData.settings.customCSS = hookData.data.customCSS || '';
return hookData;
};
plugin.filterUserGetSettings = function(hookData) {
hookData.settings.customCSS = hookData.settings.customCSS || '';
return hookData;
};
plugin.renderHeader = async function(data) {
if (!data.req.uid) {
return data;
}
const customCSS = await getCustomCSS(data.req.uid);
if (customCSS) {
data.templateValues.useCustomCSS = true;
data.templateValues.customCSS += customCSS;
}
return data;
};