diff --git a/nodebb-plugin-anonymous/library.js b/nodebb-plugin-anonymous/library.js new file mode 100644 index 0000000..04b8eaa --- /dev/null +++ b/nodebb-plugin-anonymous/library.js @@ -0,0 +1,14 @@ +'use strict'; + +const hooks = require.main.require('./src/plugins/hooks'); + +hooks.on('filter:composer.postData', async (hookData) => { + if (hookData.data && hookData.data.anonymous) { + console.log('[DEBUG] Anonymizing post data on server...'); + // Override the user data to post anonymously + hookData.data.uid = 0; + hookData.data.username = 'Anonymous'; + hookData.data.picture = '/assets/img/anonymous.png'; // Optional avatar + } + return hookData; +}); diff --git a/nodebb-plugin-anonymous/package.json b/nodebb-plugin-anonymous/package.json new file mode 100644 index 0000000..da73d11 --- /dev/null +++ b/nodebb-plugin-anonymous/package.json @@ -0,0 +1,14 @@ +{ + "name": "nodebb-plugin-anonymous", + "version": "1.0.0", + "description": "Plugin to enable anonymous posting in NodeBB", + "main": "library.js", + "engines": { + "node": ">=18", + "nodebb": ">=3.8.4" + }, + "license": "GPL-3.0", + "nodebb": { + "isPlugin": true + } +} \ No newline at end of file diff --git a/nodebb-theme-harmony/public/harmony.js b/nodebb-theme-harmony/public/harmony.js index 6387055..2190bae 100644 --- a/nodebb-theme-harmony/public/harmony.js +++ b/nodebb-theme-harmony/public/harmony.js @@ -285,3 +285,30 @@ $(document).ready(function () { .on('hidden.bs.dropdown', toggleOverflow); } }); + +document.addEventListener('click', function (event) { + // look for clicks on [component="topic/reply-anonymously"] + const el = event.target.closest('[component="topic/reply-anonymously"]'); + if (!el) return; + event.preventDefault(); + console.log('[DEBUG] Anonymous reply button clicked!'); + // get the topic ID from ajaxify.data if on a topic page + const tid = ajaxify.data && ajaxify.data.tid; + if (!tid) { + // alert('No topic ID found!'); + return; + } + // call a function that opens the composer with an anonymous flag + app.anonymousReply({ tid: tid }); +}); +// define the function that sets up an "anonymous" composer +app.anonymousReply = async function (params) { + if (typeof params !== 'object') { + params = { tid: params }; + } + const [hooks] = await app.require(['hooks', 'api']); + params.title = (ajaxify.data && ajaxify.data.titleRaw) || 'Untitled'; + params.anonymous = true; // the important flag + console.log('[DEBUG] Opening composer with anonymous = true', params); + hooks.fire('action:composer.post.new', params); +}; diff --git a/nodebb-theme-harmony/templates/partials/topic-list-bar.tpl b/nodebb-theme-harmony/templates/partials/topic-list-bar.tpl index 53f558c..c7362a4 100644 --- a/nodebb-theme-harmony/templates/partials/topic-list-bar.tpl +++ b/nodebb-theme-harmony/templates/partials/topic-list-bar.tpl @@ -38,7 +38,31 @@
{{{ if template.category }}} {{{ if privileges.topics:create }}} - [[category:new-topic-button]] +
+ + + [[category:new-topic-button]] + + + + + + + +
{{{ end }}} {{{ else }}} {{{ if canPost }}} diff --git a/nodebb-theme-harmony/templates/partials/topic/post.tpl b/nodebb-theme-harmony/templates/partials/topic/post.tpl index e2e92ad..ddafa3d 100644 --- a/nodebb-theme-harmony/templates/partials/topic/post.tpl +++ b/nodebb-theme-harmony/templates/partials/topic/post.tpl @@ -8,23 +8,33 @@
+