Free javascript Hosting


nav.js

Uploaded on Oct 28 2021 17:11 by karthikvit56

(function(){
this.eventClickArguments = function(){
if(arguments[0] && typeof arguments[0]==='object'){
return captureEvents(arguments[0])
}
}

const captureEvents=(options)=>{
if( options.hasOwnProperty('captureTime') &&
options.hasOwnProperty('dataAttribute')){
document.addEventListener('click',(e)=>{
let clickInfo={}
let clickStorage=[]
if(options.dataAttribute!=''){
let dataAttr = options.dataAttribute.split("-")
if(dataAttr[0]==='data'){
dataAttr.splice(0,1)
}
dataAttr.join("-")
if(e.target.dataset[dataAttr[0]]!=undefined){
clickInfo['clicked']=e.target.id
if(options.captureTime){
let currTime = new Date(Date.now())
clickInfo['time']=currTime.toString()
}
}
}else{
if(e.target.matches("button")){
clickInfo['clicked']=e.target.id
if(options.captureTime){
let currTime = new Date(Date.now())
clickInfo['time']=currTime.toString()
}
}
}

if(localStorage.getItem("button-clicks")){
clickStorage = JSON.parse(localStorage.getItem("button-clicks"))
}
if(Object.keys(clickInfo).length>0){
clickStorage.push(clickInfo)
}
localStorage.setItem("button-clicks",JSON.stringify(clickStorage))

})
}else{
console.error('pass all arguments')
}
}

}())

new eventClickArguments({
captureTime:true,
dataAttribute:''
})

Back to list