plugin/download-counter: option to show counter in file menu instead of list
Massimo Melina committed
Apr 3, 2023 at 11:34 UTC
eeae013af19002d319197bec1c6dac6fc6527730
2 files changed
+14
-4
plugins/download-counter/plugin.js
+7
-3
@@ -1,6 +1,10 @@
1
-exports.description = "Counts downloads for each file, and displays the total in the list"
2
-exports.version = 3.1 // removed "hits" word
3
-exports.apiRequired = 3
1
+exports.description = "Counts downloads for each file, and displays the total in the list or file menu"
2
+exports.version = 4 // config.where
3
+exports.apiRequired = 6
4
+
5
+exports.config = {
6
+ where: { frontend: true, type: 'select', options: ['list', 'menu'] }
7
+}
8
9
exports.init = async api => {
10
const _ = api.require('lodash')
plugins/download-counter/public/main.js
+7
-1
@@ -1,2 +1,8 @@
1
+const inMenu = HFS.plugins['download-counter'].where === 'menu'
2
HFS.onEvent('additionalEntryProps', ({ entry: { hits } }, { t }) =>
2
- hits && `<span class="download-counter" title="${t`download counter`}">${hits}</span>`)
3
+ hits && !inMenu && `<span class="download-counter" title="${t`download counter`}">${hits}</span>`)
4
+
5
+HFS.onEvent('fileMenu', ({ entry, props }) => {
6
+ if (inMenu && !entry.isFolder)
7
+ props.push(["Downloads", entry.hits || 0])
8
+})
\ No newline at end of file