File tree Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Original file line number Diff line number Diff line change
1
+ // Store a reference to the original getAttribute function
2
+ const originalGetAttribute = Element . prototype . getAttribute ;
3
+
4
+ // Override the getAttribute function
5
+ Element . prototype . getAttribute = function ( name ) {
6
+ let value = originalGetAttribute . call ( this , name ) ;
7
+
8
+ if ( value === '$organization_id' )
9
+ value = localStorage . getItem ( 'organization_id' )
10
+ else if ( value === '$user_id' )
11
+ value = localStorage . getItem ( 'user_id' )
12
+ else if ( value === '$clientId' )
13
+ value = localStorage . getItem ( 'clientId' )
14
+ else if ( value === '$session_id' )
15
+ value = localStorage . getItem ( 'session_id' )
16
+ else if ( typeof value === 'string' ) {
17
+ if ( value . startsWith ( '$search' ) ) {
18
+ const searchParams = new URLSearchParams ( window . location . search ) ;
19
+ if ( value . includes ( '.' ) ) {
20
+ value = searchParams . get ( value . split ( '.' ) [ 1 ] ) ;
21
+ } else {
22
+ const paramsObject = { } ;
23
+
24
+ // Iterate over all key-value pairs and add them to the object
25
+ for ( const [ key , value ] of searchParams ) {
26
+ paramsObject [ key ] = value ;
27
+ }
28
+ value = paramsObject
29
+ }
30
+
31
+ } else if ( [
32
+ '$href' ,
33
+ '$origin' ,
34
+ '$protocol' ,
35
+ '$host' ,
36
+ '$hostname' ,
37
+ '$port' ,
38
+ '$pathname' ,
39
+ '$hash'
40
+ ] . includes ( value ) ) {
41
+ value = window . location [ value . substring ( 1 ) ]
42
+ }
43
+ }
44
+
45
+ return value ;
46
+ } ;
47
+
Original file line number Diff line number Diff line change 22
22
23
23
import { setValue } from './setValue' ;
24
24
import { getValue } from './getValue' ;
25
+ import { getAttribute } from './getAttribute' ;
25
26
26
-
27
- export default { getValue, setValue }
27
+ export default { getValue, setValue, getAttribute }
You can’t perform that action at this time.
0 commit comments