source: t29-www/shared/js/counter.js @ 559

Last change on this file since 559 was 157, checked in by sven, 14 years ago
  • Counter fuer deutsche Startseite: Primuzahl als d/dt Besucher/Tag

-- sven@t29

File size: 2.6 KB
Line 
1/**
2 * Heuristischer JavaScript-Counter fuer technikum29.de, v5.8,
3 * selbstgeschrieben.
4 * (Ziffern von http://www.digitmania.holowww.com/odometer.html)
5 *
6 * Auf Wunsch von Heribert, 10.07.2009
7 *
8 * Sven Koeppel
9 **/
10
11// Allgemeine... Parameter:
12
13// bei stand wird die Bildkomposition eingesetzt
14var t29_counter_text = function(stand){
15        var s = "<div style='color:grey'>";
16        s += "<p class='center'><span style='border: 1px solid grey; padding: 5px; font-family: monospace; letter-spacing: 3px; color: grey;'>"+stand+"</span></p>";
17        s += "<p>Besucher seit 2004</p>";
18        s += "</div>";
19        return s;
20}
21
22// Zeug zum zurueckgeben fuer eine Zahl
23var t29_counter_image = function(digit) {
24        // variante 1: Per CSS holen (elegant)
25        return "<span class='digit"+digit+"'>"+digit+"</span>";
26
27        // variante 2: selbst composen (schnell)
28        //return "<img src='/shared/js/counter-digits/"+digit+"A.GIF' alt='"+digit+"' />";
29        //return "<img src='http://svenk.homeip.net/tmp/"+digit+"SBRS.GIF' />";
30}
31
32var t29_counter_get_value = function() {
33        // Anfangswerte, von denen hochgerechnet wird
34        var seed = 142735; // geschaetzt am 11.07.09...
35        var seed_date = new Date(2009, 6, 8); // achtung, zaehlt ab 0=Januar, 8=9. tag
36        var hits_per_day = 211;
37
38        // Sehr simple Annahme: Linear verteilt hits_per_day Benutzer pro
39        // Tag dazu... also dann einfach:
40        var now = new Date();
41        var one_day = 60*60*24*1000; // Millisekunden an einem Tag
42
43        // Time.getTime() gibt ms seit der Epoche zurueck
44        var days_since_seed = Math.max( /* min: falls seed_date in Zukunft */
45                ( now.getTime() - seed_date.getTime() ) / one_day,
46                0
47        );
48
49        // und hier die simple interpolation, als lineare Funktion
50        return Math.round(seed + hits_per_day * days_since_seed);
51}
52
53// hier beginnt dann das richtige Programm:
54
55// unobstructives onload-Anheften
56var t29_counter_old_onload = window.onload;
57window.onload = function(){
58        if (typeof(t29_counter_old_onload)=="function")
59                t29_counter_old_onload();
60
61        // print data
62        counter_text = "";
63        snumber = t29_counter_get_value().toString();
64        tausender_trennzeichen = '.';
65        for(x = 0; x < snumber.length; x++) {
66                s = snumber.charAt(x);
67                if(x != 0 && (x % 3 == 0) ) {
68                        counter_text += t29_counter_image(tausender_trennzeichen);
69                }
70                counter_text += t29_counter_image(s);
71        }
72       
73        counterBox = t29_counter_text(counter_text);
74
75        // inject counterBox
76        footnode_id = 'sidebar-footnote';
77        if( document.getElementById(footnode_id) ) {
78                document.getElementById(footnode_id).innerHTML += counterBox;
79        } else {
80                contentNode = document.getElementById('content');
81                contentNode.innerHTML += "<div id='"+footnode_id+"'>"+counterBox+"</div>";
82        }
83};
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License