@@ -17,76 +17,77 @@ export class MySiteCounterElement extends HTMLElement {
1717 static getTag ( ) { return 'my-site-counter' ; }
1818
1919 /** @return {string } */
20- get gcid ( ) {
20+ get # gcid ( ) {
2121 const GC_ID = this . getAttribute ( 'gcid' ) ;
2222 if ( GC_ID ) return GC_ID ;
2323 throw new Error ( 'The "gcid" required attribute is missing.' ) ;
2424 }
2525
26- get _guardLocalhost ( ) {
27- if ( this . getAttribute ( 'allow-localhost' ) ) return true ;
26+ get #guardLocalhost ( ) {
27+ if ( this . hasAttribute ( 'allow-localhost' ) ) return true ;
2828 if ( location . hostname === 'localhost' ) return false ;
2929
3030 return true ;
3131 }
3232
33- get _guardMyself ( ) {
33+ get #guardMyself ( ) {
3434 return location . hash !== '#toggle-goatcounter' ;
3535 }
3636
3737 connectedCallback ( ) {
38- if ( ! this . _guardMyself ) {
38+ if ( ! this . #guardMyself ) {
3939 return console . debug ( 'my-site-counter:' , 'Not counting myself!' ) ;
4040 }
41- if ( ! this . _guardLocalhost ) {
41+ if ( ! this . #guardLocalhost ) {
4242 return console . debug ( 'my-site-counter:' , 'Not counting localhost' ) ;
4343 }
4444
45- const imgElement = this . _createPixelImageElement ( ) ;
45+ const imgElement = this . #createPixelImageElement ( ) ;
4646
4747 this . attachShadow ( { mode : 'open' } ) . appendChild ( imgElement ) ;
4848 }
4949
50- _createPixelImageElement ( ) {
50+ #createPixelImageElement ( ) {
5151 const IMG = document . createElement ( 'img' ) ;
5252
53- IMG . src = this . _goatCounterImageUrl ;
53+ IMG . src = this . #goatCounterImageUrl ;
5454 IMG . alt = '' ; // Accessibility: a decorative image.
5555 IMG . setAttribute ( 'aria-hidden' , true ) ;
5656 IMG . loading = 'eager' ;
5757 IMG . onerror = ( ev ) => {
5858 const { target } = ev ; // error, message - Undefined (cross-origin).
59- console . error ( 'my-site-counter ERROR:' , this . gcid , IMG . src , target , ev ) ;
59+ console . error ( 'my-site-counter ERROR:' , this . # gcid, IMG . src , target , ev ) ;
6060 } ;
6161 IMG . onload = ( ev ) => {
62- console . debug ( 'my-site-counter OK (GoatCounter):' , this . gcid , this . _queryParams , this ) ;
62+ console . debug ( 'my-site-counter OK (GoatCounter):' , this . # gcid, [ this ] ) ;
6363 } ;
6464 return IMG ;
6565 }
6666
67- get _goatCounterImageUrl ( ) {
68- const urlParams = new URLSearchParams ( this . _queryParams ) ;
69- return `https://${ this . gcid } .goatcounter.com/count?${ urlParams . toString ( ) } ` ;
67+ get #goatCounterImageUrl ( ) {
68+ return `https://${ this . #gcid} .goatcounter.com/count?${ this . #queryString} ` ;
7069 }
7170
72- get _screenSizeAndScale ( ) {
71+ get #screenSizeAndScale ( ) {
7372 const { width, height } = window . screen ;
7473 const SCALE = parseInt ( window . devicePixelRatio ) ;
7574
7675 return `${ parseInt ( width ) } ,${ parseInt ( height ) } ,${ SCALE } ` ;
7776 }
7877
79- get _cacheBusting ( ) { return Math . random ( ) . toString ( 36 ) . substr ( 2 , 8 ) ; }
78+ get #cacheBusting ( ) { return Math . random ( ) . toString ( 36 ) . substr ( 2 , 8 ) ; }
8079
81- get _queryParams ( ) {
80+ get #queryString ( ) { return new URLSearchParams ( this . #queryParams) . toString ( ) ; }
81+
82+ get #queryParams ( ) {
8283 return {
8384 p : location . pathname ,
8485 t : document . title || '[none]' ,
8586 r : document . referrer || '' ,
8687 e : false , // Event.
8788 q : '' , // Query, campaign.
88- s : this . _screenSizeAndScale ,
89- rnd : this . _cacheBusting
89+ s : this . #screenSizeAndScale ,
90+ rnd : this . #cacheBusting
9091 } ;
9192 }
9293}
0 commit comments