]> git.deb.at Git - deb/hackedgotchi.git/blob - www/common/hide.js
Add new derivative Kali Linux
[deb/hackedgotchi.git] / www / common / hide.js
1 /* Log to the console if we can: firebug firefox extension will view these */
2 function log( txt)
3 {
4    if (  window.console && window.console.log )
5    {
6      window.console.log( txt );
7    }
8 }
9
10 /* create a cookie */
11 function createCookie(name,value,days)
12 {
13    var expires = "";
14    if (days)
15    {
16       var date = new Date();
17       date.setTime(date.getTime()+(days*24*60*60*1000));
18       expires = "; expires="+date.toGMTString();
19    }
20    document.cookie = name+"="+value+expires+"; path=/";
21    log( "Created cookie: " + document.cookie );
22 }
23
24 /* read a cookie */
25 function readCookie(name)
26 {
27    var nameEQ = name + "=";
28    var ca = document.cookie.split(';');
29    for(var i=0;i < ca.length;i++)
30    {
31       var c = ca[i];
32       while (c.charAt(0)==' ')
33          c = c.substring(1,c.length);
34
35       if (c.indexOf(nameEQ) == 0)
36          return c.substring(nameEQ.length,c.length);
37    }
38    return null;
39 }
40
41 /* erase a cookie */
42 function eraseCookie(name)
43 {
44     log( "erasingCookie" );
45     createCookie(name,"",-1); 
46 }
47
48 /* exclude entries from the same domain as the given URL */
49 function exclude( site )
50 {
51     log( "Excluding: " + site );
52
53     domain = site.match( /:\/\/(\.*)([^/:]+)/ );
54     domain = domain[2]?domain[2]:'';
55
56     var val=readCookie('excludes');
57     if ( !val )
58     { 
59         val = '';
60     }
61     if ( val.length > 0 )
62     {
63        val = val + ",";
64     }
65     val = val + domain
66     createCookie('excludes',val, 10);
67 }
68
69 /* un-exclude host */
70 function show( site )
71 {
72     domain = site.match( /:\/\/(\.*)([^/:]+)/ );
73     domain = domain[2]?domain[2]:'';
74
75     log( "Showing " + site );
76
77     /* get the cookie */
78     var val=readCookie('excludes');
79     if ( !val ) { val = ''; }
80
81     /* new cookie value */
82     var n = '';
83
84     hosts=val.split( ',' );
85     for( var i=0 ; i < hosts.length; i++ )
86     {
87       /* the currently excluded host isn't the one we're to show now - so keep it */
88       if ( hosts[i] != domain )
89       {
90           if ( n.length > 0 ) { n = n + ',' ; }
91           n += hosts[i];
92       }
93       else
94       {
95          /* the currently excluded host is now supposed to be visible.. */
96           c = getElementsByClassNamePrefix( hosts[i] );
97           for ( var j = 0; j < c.length; j++ )
98           {
99               showDiv(c[j].id );
100               showInlineDiv( ( c[j].id + "_hide" ) )
101               hideDiv( ( c[j].id + "_show" ) )
102           }
103       }
104     }
105     /* set new cookie */
106     createCookie('excludes',n, 10);
107 }
108
109 /* avoid excluding any sites : clear the cookie */
110 function excludeNone()
111 {
112     eraseCookie( 'excludes' );
113     window.location.reload();
114     hideDiv( 'unhide-all' );
115 }
116
117 /* hide the given div, if possible */
118 function hideDiv( id ) {
119     i = document.getElementById(id);
120     if ( i )
121     {
122         log( "Setting div " + id + " -> display:none;" );
123         i.style.display="none";
124     }
125 }
126
127 /* show the given div */
128 function showDiv( id ) {
129     i = document.getElementById(id);
130     if ( i )
131     {
132         log( "Setting div " + id + " -> display:block;" );
133         i.style.display="block";
134     }
135 }
136 function showInlineDiv( id ) {
137     i = document.getElementById(id);
138     if ( i )
139     {
140         log( "Setting div " + id + " -> display:inline;" );
141         i.style.display="inline";
142     }
143 }
144
145 /* get elements with a class starting with the given name */
146 function getElementsByClassNamePrefix(classname) {
147          var els = document.getElementsByTagName("*");
148          var c = new RegExp("/b^|" + classname  );
149          final = new Array();
150          var n=0;
151          for (var i=0; i < els.length; i++) {
152               if (els[i].className) {
153                    if(c.test(els[i].className)) {
154                    final[n] = els[i];
155                    n++;
156                    }
157               }
158          }
159          return final;
160 }
161
162 /* hide all the hosts we're supposed to */
163 function hideHosts()
164 {
165      var excl=readCookie( 'excludes');
166      if ( ! excl ) { excl='' ; }
167      hosts=excl.split( ',' );
168
169      for ( var i = 0; i < hosts.length; i++ )
170      {
171           // ok so we have a host.  should we hide it?
172           if ( hosts[i] )
173           {
174               c = getElementsByClassNamePrefix( hosts[i] );
175               for ( var j = 0; j < c.length; j++ )
176               {
177                   hideDiv(c[j].id );
178                   showInlineDiv( ( c[j].id + "_show" ) )
179                   hideDiv( ( c[j].id + "_hide" ) )
180
181                   showDiv( 'unhide-all' );
182               }
183           }
184      }
185 }
186