1- import  {  processOperators  }  from  "./utility " ; 
1+ import  {  processOperators  }  from  "./operators " ; 
22
33// Store a reference to the original getAttribute function 
44const  originalGetAttribute  =  Element . prototype . getAttribute ; 
5+ 
6+ // Map to store attribute details 
57const  attributes  =  new  Map ( ) ; 
68
9+ // Add an event listener for storage events to update attributes 
710window . addEventListener ( "storage" ,  updateAttributes ) ; 
11+ // Custom event to update attributes 
812window . addEventListener ( "updateAttributes" ,  function  ( e )  { 
913	updateAttributes ( e . detail ) ; 
1014} ) ; 
1115
16+ /** 
17+  * Function to update attributes based on specific storage keys 
18+  * @param  {Object } e - The event object containing key and newValue 
19+  */ 
1220function  updateAttributes ( e )  { 
1321	const  keys  =  [ "organization_id" ,  "user_id" ,  "clientId" ,  "session_id" ] ; 
1422	if  ( keys . includes ( e . key ) )  { 
@@ -19,8 +27,24 @@ function updateAttributes(e) {
1927	} 
2028} 
2129
22- // Override the getAttribute function 
30+ /** 
31+  * Custom getAttribute function that processes the attribute value 
32+  * @param  {Element } element - The element from which to get the attribute 
33+  * @param  {string } name - The attribute name 
34+  * @returns  {string } - The processed attribute value 
35+  */ 
36+ function  getAttribute ( element ,  name )  { 
37+ 	if  ( ! ( element  instanceof  Element ) )  { 
38+ 		throw  new  Error ( "First argument must be an Element" ) ; 
39+ 	} 
40+ 	let  value  =  originalGetAttribute . call ( element ,  name ) ; 
41+ 	return  processOperators ( element ,  value ) ; 
42+ } 
43+ 
44+ // Override the getAttribute method on Element prototype 
2345Element . prototype . getAttribute  =  function  ( name )  { 
24- 	let  value  =  originalGetAttribute . call ( this ,  name ) ; 
25- 	return  processOperators ( this ,  value ) ; 
46+ 	return  getAttribute ( this ,  name ) ;  // Use the custom getAttribute function 
2647} ; 
48+ 
49+ // Export the custom getAttribute function 
50+ export  {  getAttribute  } ; 
0 commit comments