Skip to content

Commit a2b3edf

Browse files
committed
chore: add listener to update ads when route change
1 parent 490247f commit a2b3edf

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

docs/docusaurus.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const config = {
3838
// src: '/js/gpt.js',
3939
// async: true,
4040
// },
41+
{
42+
src: '/js/ads.js',
43+
async: true,
44+
},
4145
],
4246

4347
presets: [

docs/static/js/ads.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-disable */ // --> OFF
2+
3+
;(function () {
4+
var pushState = history.pushState
5+
var replaceState = history.replaceState
6+
7+
history.pushState = function () {
8+
pushState.apply(history, arguments)
9+
window.dispatchEvent(new Event('pushstate'))
10+
window.dispatchEvent(new Event('locationchange'))
11+
}
12+
13+
history.replaceState = function () {
14+
replaceState.apply(history, arguments)
15+
window.dispatchEvent(new Event('replacestate'))
16+
window.dispatchEvent(new Event('locationchange'))
17+
}
18+
19+
window.addEventListener('popstate', function () {
20+
window.dispatchEvent(new Event('locationchange'))
21+
})
22+
})()
23+
24+
window.addEventListener('locationchange', function () {
25+
setTimeout(() => {
26+
;(window.adsbygoogle = window.adsbygoogle || []).push({})
27+
}, 1000)
28+
})

0 commit comments

Comments
 (0)