File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 11<!-- Display GoatCounter pageviews -->
22< script >
3- let pv = document . getElementById ( 'pageviews' ) ;
3+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
4+ const pv = document . getElementById ( 'pageviews' ) ;
45
5- if ( pv !== null ) {
6- const uri = location . pathname . replace ( / \/ $ / , '' ) ;
7- const url = `https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/${ encodeURIComponent ( uri ) } .json` ;
6+ if ( pv !== null ) {
7+ const uri = location . pathname . replace ( / \/ $ / , '' ) ;
8+ const url = `https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/${ encodeURIComponent ( uri ) } .json` ;
89
9- fetch ( url )
10+ fetch ( url )
1011 . then ( ( response ) => response . json ( ) )
1112 . then ( ( data ) => {
1213 const count = data . count . replace ( / \s / g, '' ) ;
1516 . catch ( ( error ) => {
1617 pv . innerText = '1' ;
1718 } ) ;
18- }
19+ }
20+ } ) ;
1921</ script >
You can’t perform that action at this time.
0 commit comments