plugins: HFS.elementToEntry
Massimo Melina committed
Aug 10, 2025 at 23:43 UTC
d1971f69b82a837d4e86e6fdae3692c4fd475ef2
4 files changed
+17
-9
dev-plugins.md
+5
-3
@@ -447,8 +447,9 @@ In frontend you will have access to the `HFS` object of the global scope, which
447
- `textSortCompare(a: string, b: string): number` the function HFS will use for text sorting.
448
Returns a negative if `a` must go before `b`, a positive if `b` must go before `a`, or zero they have same order.
449
It's exposed for you to use, or to overwrite if you need.
450
+- `elementToEntry(el: HTMLElement): DirEntry | undefined` given a DOM element, returns the DirEntry associated to it, if any.
451
451
-The following properties are accessible only immediately at top-level; don't call it later in a callback.
452
+- The following properties are accessible only immediately at top-level; don't call it later in a callback.
453
- `getPluginConfig()` returns object of all config keys that are declared frontend-accessible by this plugin.
454
- `getPluginPublic()` returns plugin's public folder, with final slash. Useful to point to public files.
455
@@ -1042,5 +1043,6 @@ If you want to override a text regardless of the language, use the special langu
1043
- HFS.isShowSupported
1044
- 12.6 (v0.57.6)
1045
- HFS.textSortCompare
1045
-- 12.7 (v0.57.10)
1046
- - api.onServer
\ No newline at end of file
1046
+- 12.8 (v0.57.10)
1047
+ - api.onServer
1048
+ - HFS.elementToEntry
\ No newline at end of file
frontend/src/BrowseFiles.ts
+4
-5
@@ -1,12 +1,11 @@
1
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3
import { Link, useNavigate } from 'react-router-dom'
4
-import { createElement as h, Fragment, memo, MouseEvent, useCallback, useEffect, useMemo, useRef, useState,
5
- useId} from 'react'
6
-import { useEventListener, useMediaQuery, useWindowSize } from 'usehooks-ts'
4
import {
8
- domOn, ErrorMsg, hIcon, onlyTruthy, prefix, isMac, isCtrlKey, hfsEvent, formatTimestamp
9
-} from './misc'
5
+ createElement as h, Fragment, memo, MouseEvent, useCallback, useEffect, useMemo, useRef, useState, useId
6
+} from 'react'
7
+import { useEventListener, useMediaQuery, useWindowSize } from 'usehooks-ts'
8
+import { domOn, ErrorMsg, hIcon, onlyTruthy, prefix, isMac, isCtrlKey, hfsEvent, formatTimestamp } from './misc'
9
import { Checkbox, CustomCode, Bytes, iconBtn, Spinner } from './components'
10
import { Head } from './Head'
11
import { DirEntry, state, useSnapState } from './state'
frontend/src/misc.ts
+7
@@ -114,6 +114,13 @@ Object.assign(getHFS(), {
114
return apiCall(cross.PLUGIN_CUSTOM_REST_PREFIX + name, ...rest)
115
},
116
html: (html: string) => h(Html, {}, html),
117
+ elementToEntry(el: any) {
118
+ if (!(el instanceof HTMLElement)) return
119
+ const a = el.closest('li')?.querySelector('.link-wrapper a')
120
+ if (!(a instanceof HTMLAnchorElement)) return
121
+ try { return _.find(state.list, { uri: new URL(a.href).pathname }) }
122
+ catch {}
123
+ },
124
})
125
126
export function operationSuccessful() {
src/const.ts
+1
-1
@@ -9,7 +9,7 @@ import { formatTimestamp } from './cross'
9
import { argv } from './argv'
10
export * from './cross-const'
11
12
-export const API_VERSION = 12.7
12
+export const API_VERSION = 12.8
13
export const COMPATIBLE_API_VERSION = 1 // while changes in the api are not breaking, this number stays the same, otherwise it is made equal to API_VERSION
14
15
// you can add arguments with this file, currently used for the update process on mac/linux