-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.user.js
More file actions
33 lines (32 loc) · 1.42 KB
/
basic.user.js
File metadata and controls
33 lines (32 loc) · 1.42 KB
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
// ==UserScript==
// @name Add edit post button - basic
// @version 1.1
// @author ShlomoCode
// @match *://*/*
// @description Add edit post button for own posts (for admin - for all posts) for nodebb forums
// ==/UserScript==
if (typeof $ === 'function' && typeof app === 'object' && app?.user?.uid) {
async function addEditButtonForPosts () {
const [translator] = await app.require(['translator']);
const editButtonTitle = await translator.translate('[[topic:edit]]');
const posts = $(app.user.isGlobalMod || app.user.isAdmin ? '[component="post"]' : '.self-post').not('.edit-button-was-added');
for (const post of posts) {
const pid = parseInt($(post).attr('data-pid'), 10);
const pHeader = $(post).find('.post-header');
const editButton = $('<button>')
.addClass('fa fa-fw fa-pencil')
.css({ background: 'none', border: 'none' })
.tooltip({
title: editButtonTitle,
placement: 'top',
trigger: 'hover'
})
.click(() => {
$(window).trigger('action:composer.post.edit', { pid });
});
pHeader.append(editButton);
$(post).addClass('edit-button-was-added');
}
}
$(window).on('action:posts.loaded action:topic.loaded', addEditButtonForPosts);
}