Skip to content

Commit 142ff43

Browse files
committed
chore: move polliLib setup to deferred script
1 parent e04bb28 commit 142ff43

File tree

2 files changed

+49
-50
lines changed

2 files changed

+49
-50
lines changed

index.html

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,7 @@
1111
<link rel="stylesheet" href="js/ui/stylesScreensaver.css">
1212
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
1313
<script defer src="js/polliLib/polliLib-web.global.js"></script>
14-
<script defer>
15-
// Configure polliLib default client and expose an explicit client for MCP helpers
16-
(function(){
17-
try {
18-
if (window.polliLib) {
19-
// Derive base referrer from attribute or window location (no path segments)
20-
const cur = document.currentScript;
21-
const attrRef = cur && cur.getAttribute('data-referrer');
22-
let base = window.location.origin;
23-
if (attrRef) {
24-
// Support values missing protocol by resolving against window.location.origin
25-
try { base = new URL(attrRef, window.location.origin).origin; } catch {}
26-
}
27-
const referrer = base.endsWith('/') ? base : base + '/';
28-
window.polliLib.configure({ referrer });
29-
window.polliClient = window.polliLib.getDefaultClient();
30-
31-
// Provide basic helpers used by image features
32-
if (!window.randomSeed) {
33-
window.randomSeed = function randomSeed() { return Math.floor(Math.random() * 1000000); };
34-
}
35-
if (!window.imagePatterns) {
36-
window.imagePatterns = [
37-
{ pattern: /```image\n([\s\S]*?)\n```/i, group: 1 },
38-
];
39-
}
40-
if (!window.audioPatterns) {
41-
window.audioPatterns = [
42-
{ pattern: /```audio\n([\s\S]*?)\n```/i, group: 1 },
43-
];
44-
}
45-
if (!window.uiPatterns) {
46-
window.uiPatterns = [
47-
{ pattern: /```ui\n([\s\S]*?)\n```/i, group: 1 },
48-
];
49-
}
50-
if (!window.voicePatterns) {
51-
window.voicePatterns = [
52-
{ pattern: /```voice\n([\s\S]*?)\n```/i, group: 1 },
53-
];
54-
}
55-
if (!window.videoPatterns) {
56-
window.videoPatterns = [
57-
{ pattern: /```video\n([\s\S]*?)\n```/i, group: 1 },
58-
];
59-
}
60-
}
61-
} catch (e) { console.warn('polliLib configure failed', e); }
62-
})();
63-
</script>
14+
<script defer src="js/pollilib-init.js"></script>
6415
</head>
6516
<body>
6617
<div id="screensaver-container" class="screensaver hidden">

js/pollilib-init.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Configure polliLib default client and expose an explicit client for MCP helpers
2+
(function(){
3+
try {
4+
if (window.polliLib) {
5+
// Derive base referrer from attribute or window location (no path segments)
6+
const cur = document.currentScript;
7+
const attrRef = cur && cur.getAttribute('data-referrer');
8+
let base = window.location.origin;
9+
if (attrRef) {
10+
// Support values missing protocol by resolving against window.location.origin
11+
try { base = new URL(attrRef, window.location.origin).origin; } catch {}
12+
}
13+
const referrer = base.endsWith('/') ? base : base + '/';
14+
window.polliLib.configure({ referrer });
15+
window.polliClient = window.polliLib.getDefaultClient();
16+
17+
// Provide basic helpers used by image features
18+
if (!window.randomSeed) {
19+
window.randomSeed = function randomSeed() { return Math.floor(Math.random() * 1000000); };
20+
}
21+
if (!window.imagePatterns) {
22+
window.imagePatterns = [
23+
{ pattern: /```image\n([\s\S]*?)\n```/i, group: 1 },
24+
];
25+
}
26+
if (!window.audioPatterns) {
27+
window.audioPatterns = [
28+
{ pattern: /```audio\n([\s\S]*?)\n```/i, group: 1 },
29+
];
30+
}
31+
if (!window.uiPatterns) {
32+
window.uiPatterns = [
33+
{ pattern: /```ui\n([\s\S]*?)\n```/i, group: 1 },
34+
];
35+
}
36+
if (!window.voicePatterns) {
37+
window.voicePatterns = [
38+
{ pattern: /```voice\n([\s\S]*?)\n```/i, group: 1 },
39+
];
40+
}
41+
if (!window.videoPatterns) {
42+
window.videoPatterns = [
43+
{ pattern: /```video\n([\s\S]*?)\n```/i, group: 1 },
44+
];
45+
}
46+
}
47+
} catch (e) { console.warn('polliLib configure failed', e); }
48+
})();

0 commit comments

Comments
 (0)