-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
219 lines (181 loc) · 7.52 KB
/
index.html
File metadata and controls
219 lines (181 loc) · 7.52 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pattern Lock Research</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Pattern Lock Research</h1>
<div class="svg-container">
<svg id="lockSvg" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" width="300" height="300">
<g class="connections"></g>
<g class="active-dots"></g>
<g class="all-dots">
<circle cx="25" cy="25" r="6" class="dot" data-id="1"/>
<circle cx="50" cy="25" r="6" class="dot" data-id="2"/>
<circle cx="75" cy="25" r="6" class="dot" data-id="3"/>
<circle cx="25" cy="50" r="6" class="dot" data-id="4"/>
<circle cx="50" cy="50" r="6" class="dot" data-id="5"/>
<circle cx="75" cy="50" r="6" class="dot" data-id="6"/>
<circle cx="25" cy="75" r="6" class="dot" data-id="7"/>
<circle cx="50" cy="75" r="6" class="dot" data-id="8"/>
<circle cx="75" cy="75" r="6" class="dot" data-id="9"/>
</g>
</svg>
</div>
<script src="vendor.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<script>
/* ---------- SUPABASE ---------- */
window.sb = window.supabase.createClient(
"https://idwofjhbmanvyzbxtmcr.supabase.co",
"sb_publishable_9JcmwpGpBGCH6PqhfCPwuQ_cUn5rTFl"
);
async function submitPattern(patternStr) {
const { data } = await window.sb
.from("pattern_votes")
.select("vote_count")
.eq("pattern", patternStr)
.maybeSingle();
if (data) {
await window.sb
.from("pattern_votes")
.update({ vote_count: data.vote_count + 1 })
.eq("pattern", patternStr);
} else {
await window.sb
.from("pattern_votes")
.insert({ pattern: patternStr, vote_count: 1 });
}
console.log("Pattern submitted:", patternStr);
}
</script>
<script>
(function () {
const SVG_NS = "http://www.w3.org/2000/svg";
const svgCanvas = $('#lockSvg');
const dots = svgCanvas.find('.dot');
const activeDotGroup = svgCanvas.find('.active-dots');
const connectionGroup = svgCanvas.find('.connections');
/* ---------- ANDROID DOT MAP ---------- */
const DOT_MAP = {
1:{x:0,y:0}, 2:{x:1,y:0}, 3:{x:2,y:0},
4:{x:0,y:1}, 5:{x:1,y:1}, 6:{x:2,y:1},
7:{x:0,y:2}, 8:{x:1,y:2}, 9:{x:2,y:2}
};
function getMiddleDot(fromId, toId) {
const a = DOT_MAP[fromId];
const b = DOT_MAP[toId];
const mx = (a.x + b.x) / 2;
const my = (a.y + b.y) / 2;
for (const id in DOT_MAP) {
if (DOT_MAP[id].x === mx && DOT_MAP[id].y === my) {
return id;
}
}
return null;
}
let activePattern = [];
let currentLine = null;
let previousDot = null;
let isDrawing = false;
function startPattern(dot) {
isDrawing = true;
addDot(dot);
svgCanvas.on('mousemove touchmove', onMove);
$(document).one('mouseup touchend', finishPattern);
}
function onMove(event) {
if (!isDrawing) return;
event.preventDefault();
const { x, y } = getRelativePos(event);
if (currentLine) {
currentLine.setAttribute('x2', x);
currentLine.setAttribute('y2', y);
}
const cx = event.clientX || event.originalEvent.touches[0].clientX;
const cy = event.clientY || event.originalEvent.touches[0].clientY;
const el = document.elementFromPoint(cx, cy);
if (el && el.classList.contains('dot')) {
addDot(el);
}
}
/* ---------- ANDROID STYLE ADD DOT ---------- */
function addDot(dot) {
if (activePattern.includes(dot)) return;
const currentId = dot.dataset.id;
if (previousDot) {
const prevId = previousDot.dataset.id;
const middleId = getMiddleDot(prevId, currentId);
if (middleId) {
const middleDot = document.querySelector(
`.dot[data-id="${middleId}"]`
);
if (middleDot && !activePattern.includes(middleDot)) {
addDot(middleDot); // AUTO-SKIP
}
}
}
activePattern.push(dot);
const cx = dot.getAttribute('cx');
const cy = dot.getAttribute('cy');
if (previousDot) {
currentLine.setAttribute('x2', cx);
currentLine.setAttribute('y2', cy);
}
const line = document.createElementNS(SVG_NS, 'line');
line.setAttribute('x1', cx);
line.setAttribute('y1', cy);
line.setAttribute('x2', cx);
line.setAttribute('y2', cy);
line.classList.add('connection');
connectionGroup.append(line);
currentLine = line;
const circle = document.createElementNS(SVG_NS, 'circle');
circle.setAttribute('cx', cx);
circle.setAttribute('cy', cy);
circle.classList.add('active-dot');
activeDotGroup.append(circle);
previousDot = dot;
}
function finishPattern() {
if (!isDrawing) return;
isDrawing = false;
svgCanvas.off('mousemove touchmove');
if (activePattern.length < 4) {
resetUI();
return;
}
const patternStr = activePattern.map(d => d.dataset.id).join('');
submitPattern(patternStr);
resetUI();
}
function resetUI() {
activePattern = [];
previousDot = null;
currentLine = null;
activeDotGroup.empty();
connectionGroup.empty();
}
function getRelativePos(event) {
const clientX = event.clientX || event.originalEvent.touches[0].clientX;
const clientY = event.clientY || event.originalEvent.touches[0].clientY;
const offset = svgCanvas.offset();
return {
x: (clientX - offset.left) / svgCanvas.width() * 100,
y: (clientY - offset.top) / svgCanvas.height() * 100
};
}
dots.on('mousedown touchstart', function (e) {
e.preventDefault();
if (!isDrawing) startPattern(this);
});
})();
</script>
<footer class="app-footer">
<span>© 2026 JetRock Research Team</span>
</footer>
</body>
</html>