1 /* Log to the console if we can: firebug firefox extension will view these */
4 if ( window.console && window.console.log )
6 window.console.log( txt );
11 function createCookie(name,value,days)
16 var date = new Date();
17 date.setTime(date.getTime()+(days*24*60*60*1000));
18 expires = "; expires="+date.toGMTString();
20 document.cookie = name+"="+value+expires+"; path=/";
21 log( "Created cookie: " + document.cookie );
25 function readCookie(name)
27 var nameEQ = name + "=";
28 var ca = document.cookie.split(';');
29 for(var i=0;i < ca.length;i++)
32 while (c.charAt(0)==' ')
33 c = c.substring(1,c.length);
35 if (c.indexOf(nameEQ) == 0)
36 return c.substring(nameEQ.length,c.length);
42 function eraseCookie(name)
44 log( "erasingCookie" );
45 createCookie(name,"",-1);
48 /* exclude entries from the same domain as the given URL */
49 function exclude( site )
51 log( "Excluding: " + site );
53 domain = site.match( /:\/\/(\.*)([^/:]+)/ );
54 domain = domain[2]?domain[2]:'';
56 var val=readCookie('excludes');
66 createCookie('excludes',val, 10);
72 domain = site.match( /:\/\/(\.*)([^/:]+)/ );
73 domain = domain[2]?domain[2]:'';
75 log( "Showing " + site );
78 var val=readCookie('excludes');
79 if ( !val ) { val = ''; }
81 /* new cookie value */
84 hosts=val.split( ',' );
85 for( var i=0 ; i < hosts.length; i++ )
87 /* the currently excluded host isn't the one we're to show now - so keep it */
88 if ( hosts[i] != domain )
90 if ( n.length > 0 ) { n = n + ',' ; }
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++ )
100 showInlineDiv( ( c[j].id + "_hide" ) )
101 hideDiv( ( c[j].id + "_show" ) )
106 createCookie('excludes',n, 10);
109 /* avoid excluding any sites : clear the cookie */
110 function excludeNone()
112 eraseCookie( 'excludes' );
113 window.location.reload();
114 hideDiv( 'unhide-all' );
117 /* hide the given div, if possible */
118 function hideDiv( id ) {
119 i = document.getElementById(id);
122 log( "Setting div " + id + " -> display:none;" );
123 i.style.display="none";
127 /* show the given div */
128 function showDiv( id ) {
129 i = document.getElementById(id);
132 log( "Setting div " + id + " -> display:block;" );
133 i.style.display="block";
136 function showInlineDiv( id ) {
137 i = document.getElementById(id);
140 log( "Setting div " + id + " -> display:inline;" );
141 i.style.display="inline";
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 );
151 for (var i=0; i < els.length; i++) {
152 if (els[i].className) {
153 if(c.test(els[i].className)) {
162 /* hide all the hosts we're supposed to */
165 var excl=readCookie( 'excludes');
166 if ( ! excl ) { excl='' ; }
167 hosts=excl.split( ',' );
169 for ( var i = 0; i < hosts.length; i++ )
171 // ok so we have a host. should we hide it?
174 c = getElementsByClassNamePrefix( hosts[i] );
175 for ( var j = 0; j < c.length; j++ )
178 showInlineDiv( ( c[j].id + "_show" ) )
179 hideDiv( ( c[j].id + "_hide" ) )
181 showDiv( 'unhide-all' );