Skip to content

Commit 1f3e174

Browse files
committed
Fix CSE bug when reloaded location contains gsc.ref=
1 parent 5619e2a commit 1f3e174

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

index.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
66
<title property="name">Alt-Power – Alternative Google-based power-search engine</title>
77
<meta name="description" content="Alternative Google-powered internet search engine with support for advanced search operators in a clunky old-school interface, preferred by power users. 💪">
8-
<script async src="https://cse.google.com/cse.js?cx=678377fcbde92019b"></script>
98
<script async src="https://www.googletagmanager.com/gtag/js?id=G-0DSFRN8VMG"></script>
109
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('set','url_passthrough',true);gtag('js',new Date());gtag('config','G-0DSFRN8VMG');</script>
1110
<link rel="dns-prefetch preconnect" href="https://www.google.com">
@@ -297,6 +296,19 @@ <h2>Feedback & Contacts</h2>
297296
></div>
298297
</main>
299298
<script>if (!(new URLSearchParams(location.search).has('q'))) document.body.classList.add('fullscreen')</script>
299+
<script>
300+
const gsc_ref = /&gsc\.ref=[^&]*/.exec(location.hash)?.[0];
301+
if (gsc_ref) {
302+
location.hash = location.hash.replace(gsc_ref, '');
303+
let cb_done = false;
304+
window.__gcse || (window.__gcse = {});
305+
window.__gcse.searchCallbacks = {
306+
web: { rendered: (gname, query, promoElts, resultElts) => { if (!cb_done++) location.hash = location.hash + gsc_ref; },},
307+
image: {},
308+
};
309+
}
310+
</script>
311+
<script async src="https://cse.google.com/cse.js?cx=678377fcbde92019b"></script>
300312
<script>document.querySelectorAll('img').forEach(el => { el.title ||= el.alt });</script>
301313
<script>
302314
const q = decodeURIComponent(

0 commit comments

Comments
 (0)