-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
229 lines (210 loc) · 12.6 KB
/
index.html
File metadata and controls
229 lines (210 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>Pinpoint Viewer</title><style>
*{margin:0;padding:0;box-sizing:border-box}
html,body{height:100%;font-family:system-ui,-apple-system,sans-serif;background:#0a0a0a;}
#topbar{position:fixed;top:0;left:0;right:0;height:48px;background:#111;border-bottom:1px solid #222;display:flex;align-items:center;padding:0 16px;gap:12px;z-index:99999;box-shadow:0 2px 12px rgba(0,0,0,.4)}
.logo{color:#fff;font-weight:700;font-size:15px;display:flex;align-items:center;gap:6px;white-space:nowrap}
.logo span{color:#3b82f6}
.site-url{color:#555;font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;font-family:monospace}
.count{color:#fff;background:#3b82f6;border-radius:20px;padding:3px 12px;font-size:12px;font-weight:600;white-space:nowrap}
.open-btn{color:#888;font-size:12px;text-decoration:none;white-space:nowrap;border:1px solid #333;padding:4px 10px;border-radius:6px}
.open-btn:hover{color:#fff;border-color:#555}
#scroll-wrap{position:fixed;top:48px;left:0;right:0;bottom:0;overflow-y:auto;overflow-x:hidden;background:#0a0a0a;}
#page-container{position:relative;width:100%;/* height set by JS or image */}
#page-screenshot{display:block;width:100%;}
.pin{position:absolute;z-index:2;pointer-events:auto;}
.pin-dot{width:28px;height:28px;background:#3b82f6;color:#fff;border-radius:50%;font-size:12px;font-weight:700;display:flex;align-items:center;justify-content:center;box-shadow:0 2px 14px rgba(59,130,246,.6);cursor:pointer;border:2px solid #fff;transform:translate(-50%,-50%);transition:transform .15s,background .15s;user-select:none;}
.pin-dot:hover{transform:translate(-50%,-50%) scale(1.1)}
.pin.open .pin-dot{background:#1d4ed8;transform:translate(-50%,-50%) scale(1.1)}
.pin-card{display:none;position:absolute;background:#1e1e1e;color:#e5e5e5;padding:14px 16px 12px;border-radius:14px;font-size:13px;line-height:1.6;max-width:320px;min-width:200px;box-shadow:0 8px 40px rgba(0,0,0,.7);border:1px solid rgba(255,255,255,.12);left:36px;top:-10px;user-select:text;pointer-events:auto;z-index:3;}
.pin.open .pin-card{display:block}
.pin-card.flip{left:auto;right:36px}
.pin-card-header{display:flex;justify-content:space-between;align-items:flex-start;gap:8px;margin-bottom:8px;}
.pin-card-num{color:#3b82f6;font-weight:700;font-size:11px;text-transform:uppercase;letter-spacing:.5px;white-space:nowrap;}
.pin-card-close{background:rgba(255,255,255,.08);border:none;color:#888;width:20px;height:20px;border-radius:50%;font-size:13px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s,color .15s;}
.pin-card-close:hover{background:rgba(255,255,255,.18);color:#fff}
.pin-card-body{white-space:pre-wrap;word-break:break-word;cursor:text;}
.pin-card-path{color:#555;font-size:10px;margin-top:8px;font-family:monospace;word-break:break-all;}
.pin-card-img{margin-top:8px;max-width:100%;border-radius:8px;border:1px solid rgba(255,255,255,.1);}
#legend{position:fixed;bottom:16px;right:16px;z-index:99999;background:#111;border:1px solid #222;border-radius:14px;padding:12px 14px;max-width:300px;max-height:260px;overflow-y:auto;box-shadow:0 8px 32px rgba(0,0,0,.5);}
.legend-title{font-size:11px;color:#555;margin-bottom:10px;font-weight:600;text-transform:uppercase;letter-spacing:.5px}
.legend-item{display:flex;gap:10px;align-items:flex-start;margin-bottom:10px;cursor:pointer;padding:6px 8px;border-radius:8px;transition:background .15s;}
.legend-item:last-child{margin-bottom:0}
.legend-item:hover{background:rgba(255,255,255,.05)}
.legend-item.active{background:rgba(59,130,246,.12)}
.legend-num{min-width:22px;height:22px;background:#3b82f6;color:#fff;border-radius:50%;font-size:11px;font-weight:700;display:flex;align-items:center;justify-content:center;flex-shrink:0;margin-top:1px;}
.legend-text{font-size:12px;color:#ccc;line-height:1.4;}
#overlay{position:fixed;inset:0;background:#0a0a0a;display:flex;flex-direction:column;align-items:center;justify-content:center;z-index:199999;gap:16px;}
.overlay-logo{font-size:32px}.overlay-msg{color:#888;font-size:15px}
.overlay-err{color:#f87171;font-size:14px;max-width:400px;text-align:center;padding:0 20px}
.spinner{width:32px;height:32px;border:3px solid #222;border-top-color:#3b82f6;border-radius:50%;animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
</style></head>
<body>
<div id="topbar" style="display:none">
<div class="logo">📌 <span>Pinpoint</span></div>div>
<div class="site-url" id="site-url"></div>div>
<span class="count" id="ann-count"></span>
<a class="open-btn" id="open-btn" target="_blank" rel="noopener">Open site ↗</a>a>
</div>div>
<div id="scroll-wrap" style="display:none">
<div id="page-container">
<img id="page-screenshot" alt="Page screenshot">
</div>div>
</div>div>
<div id="legend" style="display:none">
<div class="legend-title">Comments</div>div>
<div id="legend-items"></div>div>
</div>div>
<div id="overlay">
<div class="overlay-logo">📌</div>div>
<div class="spinner" id="spinner"></div>div>
<div class="overlay-msg" id="overlay-msg">Loading annotations…</div>div>
</div>div>
<script>
function esc(s){return String(s||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');}
var params = new URLSearchParams(location.search);
var id = params.get('id');
if (!id) { showError('No annotation ID in URL.'); } else { loadAnnotations(id); }
// Parse imgs param — maps filenames to URLs
var imgsParam = {};
try { imgsParam = JSON.parse(params.get('imgs') || '{}'); } catch(e){}
async function loadAnnotations(gistId) {
try {
var r = await fetch('https://api.github.com/gists/' + gistId);
if (!r.ok) throw new Error('Could not load annotations (status ' + r.status + ')');
var d = await r.json();
var f = d.files['pinpoint.json'];
var txt = f.truncated ? await (await fetch(f.raw_url)).text() : f.content;
var rec = JSON.parse(txt);
init(rec.url, rec.title, rec.annotations);
} catch(e) { showError(e.message); }
}
function init(url, title, annotations) {
document.title = (title || 'Pinpoint') + ' \u2014 Annotated';
document.getElementById('site-url').textContent = url;
document.getElementById('ann-count').textContent = annotations.length + ' comment' + (annotations.length !== 1 ? 's' : '');
document.getElementById('open-btn').href = url;
document.getElementById('topbar').style.display = 'flex';
document.getElementById('scroll-wrap').style.display = 'block';
document.getElementById('legend').style.display = 'block';
var li = document.getElementById('legend-items');
li.innerHTML = annotations.map(function(a) {
return '<div class="legend-item" data-id="' + a.id + '"><div class="legend-num">' + a.id + '</div><div class="legend-text">' + esc(a.comment) + '</div></div>';
}).join('');
var container = document.getElementById('page-container');
var wrap = document.getElementById('scroll-wrap');
var img = document.getElementById('page-screenshot');
var pageH = (annotations[0] && annotations[0].pageH) || 8000;
// Use thum.io for a free full-page screenshot — width 1500 to match typical desktop
var screenshotUrl = 'https://image.thum.io/get/fullpage/width/1500/noanimate/' + url;
img.src = screenshotUrl;
img.onload = function() {
// Image loaded — scale pins to match rendered image size
placePins();
};
img.onerror = function() {
// Fallback: show a colored placeholder at pageH
img.style.display = 'none';
container.style.height = pageH + 'px';
container.style.background = 'linear-gradient(180deg, #111 0%, #1a1a2e 50%, #111 100%)';
placePins();
};
// Fallback timeout in case image loads slowly
setTimeout(function() { placePins(); }, 8000);
var placed = false;
function placePins() {
if (placed) return;
placed = true;
// Determine scale: the image's natural width was captured at 1500px
// annotations x is % of page width, y is absolute px at that capture width
// We need to scale y proportionally to the rendered image height
var captureW = 1500;
var renderedW = container.offsetWidth;
var scale = renderedW / captureW;
annotations.forEach(function(a) {
var pin = document.createElement('div');
pin.className = 'pin';
pin.dataset.id = a.id;
// x: % of page width
pin.style.left = a.x + '%';
// y: scale from capture coords to rendered size
pin.style.top = (a.y * scale) + 'px';
var flip = a.x > 75 ? ' flip' : '';
// Build image HTML if annotation has an image
var imgHtml = '';
if (a.image && imgsParam[a.image]) {
imgHtml = '<img class="pin-card-img" src="' + esc(imgsParam[a.image]) + '" alt="Reference">';
}
pin.innerHTML =
'<div class="pin-dot">' + a.id + '</div>' +
'<div class="pin-card' + flip + '"><div class="pin-card-header">' +
'<span class="pin-card-num">Comment #' + a.id + '</span>' +
'<button class="pin-card-close">✕</button></div>' +
'<div class="pin-card-body">' + esc(a.comment) + '</div>' +
imgHtml +
(a.path ? '<div class="pin-card-path">' + esc(a.path) + '</div>' : '') +
'</div>';
container.appendChild(pin);
pin.querySelector('.pin-dot').addEventListener('click', function(e) {
e.stopPropagation();
var open = pin.classList.contains('open');
closeAll();
if (!open) { pin.classList.add('open'); highlight(a.id, true); }
});
pin.querySelector('.pin-card-close').addEventListener('click', function(e) {
e.stopPropagation(); pin.classList.remove('open'); highlight(a.id, false);
});
});
// Reposition on resize
window.addEventListener('resize', function() {
var newScale = container.offsetWidth / captureW;
annotations.forEach(function(a) {
var p = container.querySelector('.pin[data-id="' + a.id + '"]');
if (p) p.style.top = (a.y * newScale) + 'px';
});
});
hideOverlay();
}
function closeAll() {
document.querySelectorAll('.pin.open').forEach(function(p){ p.classList.remove('open'); });
document.querySelectorAll('.legend-item.active').forEach(function(el){ el.classList.remove('active'); });
}
function highlight(id, on) {
var leg = document.querySelector('.legend-item[data-id="' + id + '"]');
if (leg) leg.classList.toggle('active', on);
}
document.addEventListener('click', function(e) { if (!e.target.closest('.pin')) closeAll(); });
li.querySelectorAll('.legend-item').forEach(function(item) {
item.addEventListener('click', function() {
var pid = item.dataset.id;
var ann = annotations.find(function(a){ return String(a.id) === pid; });
if (!ann) return;
var scale = container.offsetWidth / 1500;
var pinY = ann.y * scale;
wrap.scrollTo({ top: Math.max(0, pinY - wrap.offsetHeight / 2), behavior: 'smooth' });
setTimeout(function() {
closeAll();
var pin = container.querySelector('.pin[data-id="' + pid + '"]');
if (pin) { pin.classList.add('open'); item.classList.add('active'); }
}, 500);
});
});
}
function hideOverlay() {
var o = document.getElementById('overlay');
o.style.opacity='0'; o.style.transition='opacity .4s';
setTimeout(function(){ o.style.display='none'; }, 400);
}
function showError(msg) {
document.getElementById('spinner').style.display='none';
document.getElementById('overlay-msg').style.display='none';
var e = document.createElement('div');
e.className='overlay-err'; e.textContent='\u274c '+msg;
document.getElementById('overlay').appendChild(e);
}
</script>
</body></html>
</script></span>
</body>
</style></title></head></html>