diedVIPs

html knowhow

Counter - automatischer Zähler bei Reload








 script © 2013 by webdesign weisshart

Counter - automatischer Zähler bei Reload

So sieht´s aus



    Quellcode
    <html>

    <head>
    <style type="text/css">Hier nichts</style>
    </head>

    <body >
    <script>
    const hitcounter=function(){
    const StoreFactory=function( name, type ){/* this would usually be in a separate js file */
    'use strict';
    const engine = !type || type.toLowerCase() === 'local' ? localStorage : sessionStorage;
    const set=function( data ){ engine.setItem( name, JSON.stringify( data ) ); };
    const get=function(){ return exists( name ) ? JSON.parse( engine.getItem( name ) ) : false; };
    const remove=function(){ engine.removeItem( name ); };
    const exists=function(){ return engine.getItem( name )==null ? false : true; };
    const create=function(){ if( !exists() ) set( arguments[0] || {} ); };
    return Object.freeze({ set, get, exists, create, remove }); };
    const clickhandler=function(e){ oList.innerText = oSpan.innerText = '';
    let json=oStore.get();
    Object.keys( json ).map( key =>{ let li=document.createElement('li');
    li.innerText=key+' '+json[ key ]
    if( key!='total' ) oList.appendChild( li ) });
    oSpan.innerText='Gesamtaufrufe: '+json.total; };
    let oStore = new StoreFactory( 'urls', 'sessionStorage' );
    oStore.create();
    let data=oStore.get();
    data[ location.href ]=data.hasOwnProperty( location.href ) ? parseInt( data[ location.href ] ) + 1 : 1;
    data.total=data.hasOwnProperty('total') ? parseInt( data.total ) + 1 : 1;
    oStore.set( data );
    let oList=document.querySelector( 'form > ul' );
    let oSpan=document.querySelector( 'form > span' );
    let oBttn=document.querySelector( 'form > input[ type="button"]' );
    oBttn.addEventListener('click', clickhandler ) }
    document.addEventListener( 'DOMContentLoaded', hitcounter );
    </script>
    <form method='post'>
    <ul></ul>
    <span></span>
    <input type='button' value='Zeige die Aufrufe' />
    </form>
    </body>

    </html>




    Kontakt    Datenschutz   Impressum