Skip to content

Commit 10be135

Browse files
committed
docs: implement fourth round of code review fixes including clipboard fallback
1 parent 7f4387f commit 10be135

4 files changed

Lines changed: 117 additions & 135 deletions

File tree

Mathematics/Fundamentals/HackerRank/Claude/Easy/Strange Grid Again/Strange_Grid_Again.html

Lines changed: 56 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,8 @@
406406
.cpbtn:hover {
407407
background: var(--gd);
408408
}
409-
.cpbtn:focus, .cpbtn:focus-visible {
410-
outline: 2px solid var(--gd);
411-
outline-offset: 2px;
412-
}
413-
.cpbtn:focus, .cpbtn:focus-visible {
409+
.cpbtn:focus,
410+
.cpbtn:focus-visible {
414411
outline: 2px solid var(--gd);
415412
outline-offset: 2px;
416413
}
@@ -1152,6 +1149,7 @@ <h2>FAQ</h2>
11521149
})();
11531150

11541151
/* Copy */
1152+
var copyTimeoutId = null;
11551153
document.getElementById('cpbtn').addEventListener('click', function () {
11561154
var code = `from __future__ import annotations
11571155
import os
@@ -1171,13 +1169,46 @@ <h2>FAQ</h2>
11711169
result = strangeGrid(r, c)
11721170
fptr.write(str(result) + "\\n")
11731171
fptr.close()`;
1174-
navigator.clipboard.writeText(code).then(function () {
1175-
var b = document.getElementById('cpbtn');
1176-
b.textContent = 'コピー完了!';
1177-
setTimeout(function () {
1172+
var b = document.getElementById('cpbtn');
1173+
1174+
function showStatus(text) {
1175+
b.textContent = text;
1176+
if (copyTimeoutId) clearTimeout(copyTimeoutId);
1177+
copyTimeoutId = setTimeout(function () {
11781178
b.textContent = 'コピー';
11791179
}, 2000);
1180-
});
1180+
}
1181+
1182+
if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
1183+
navigator.clipboard
1184+
.writeText(code)
1185+
.then(function () {
1186+
showStatus('コピー完了!');
1187+
})
1188+
.catch(function (err) {
1189+
console.error('Copy error:', err);
1190+
showStatus('コピー失敗');
1191+
});
1192+
} else {
1193+
try {
1194+
var ta = document.createElement('textarea');
1195+
ta.value = code;
1196+
ta.style.position = 'fixed';
1197+
ta.style.opacity = '0';
1198+
document.body.appendChild(ta);
1199+
ta.select();
1200+
var res = document.execCommand('copy');
1201+
document.body.removeChild(ta);
1202+
if (res) {
1203+
showStatus('コピー完了!');
1204+
} else {
1205+
showStatus('コピー失敗');
1206+
}
1207+
} catch (e) {
1208+
console.error('Fallback copy error:', e);
1209+
showStatus('コピー失敗');
1210+
}
1211+
}
11811212
});
11821213

11831214
/* Steps */
@@ -1188,10 +1219,12 @@ <h2>FAQ</h2>
11881219
wrap.style.display = 'inline-block';
11891220

11901221
var headerDiv = document.createElement('div');
1191-
headerDiv.style.cssText = 'display:flex;gap:4px;margin-bottom:4px;margin-left:48px;';
1222+
headerDiv.style.cssText =
1223+
'display:flex;gap:4px;margin-bottom:4px;margin-left:48px;';
11921224
COLS.forEach(function (c) {
11931225
var cellDiv = document.createElement('div');
1194-
cellDiv.style.cssText = 'width:52px;text-align:center;font-size:.72rem;font-weight:700;color:#64748b;';
1226+
cellDiv.style.cssText =
1227+
'width:52px;text-align:center;font-size:.72rem;font-weight:700;color:#64748b;';
11951228
cellDiv.textContent = 'c=' + c;
11961229
headerDiv.appendChild(cellDiv);
11971230
});
@@ -1212,59 +1245,12 @@ <h2>FAQ</h2>
12121245
COLS.forEach(function (c) {
12131246
var g = Math.floor((r - 1) / 2);
12141247
var cell = document.createElement('div');
1215-
1216-
var cClass = g % 2 === 0 ? 'ca' : 'cb';
1217-
if (highlightClassFn) {
1218-
cClass = highlightClassFn(r, c, g, cClass);
1219-
}
1220-
1221-
cell.className = 'cell ' + cClass;
1222-
cell.textContent = cellValFn(r, c);
1223-
cellContainer.appendChild(cell);
1224-
});
1225-
gpRow.appendChild(cellContainer);
1226-
wrap.appendChild(gpRow);
1227-
});
1228-
frag.appendChild(wrap);
1229-
return frag;
1230-
}
12311248

1232-
function buildGridFragment(COLS, rows, cellValFn, highlightClassFn) {
1233-
var frag = document.createDocumentFragment();
1234-
var wrap = document.createElement('div');
1235-
wrap.style.display = 'inline-block';
1236-
1237-
var headerDiv = document.createElement('div');
1238-
headerDiv.style.cssText = 'display:flex;gap:4px;margin-bottom:4px;margin-left:48px;';
1239-
COLS.forEach(function (c) {
1240-
var cellDiv = document.createElement('div');
1241-
cellDiv.style.cssText = 'width:52px;text-align:center;font-size:.72rem;font-weight:700;color:#64748b;';
1242-
cellDiv.textContent = 'c=' + c;
1243-
headerDiv.appendChild(cellDiv);
1244-
});
1245-
wrap.appendChild(headerDiv);
1246-
1247-
rows.forEach(function (r) {
1248-
var gpRow = document.createElement('div');
1249-
gpRow.className = 'gp-row';
1250-
1251-
var rl = document.createElement('div');
1252-
rl.className = 'rl';
1253-
rl.textContent = 'r=' + r;
1254-
gpRow.appendChild(rl);
1255-
1256-
var cellContainer = document.createElement('div');
1257-
cellContainer.style.cssText = 'display:flex;gap:4px;';
1258-
1259-
COLS.forEach(function (c) {
1260-
var g = Math.floor((r - 1) / 2);
1261-
var cell = document.createElement('div');
1262-
12631249
var cClass = g % 2 === 0 ? 'ca' : 'cb';
12641250
if (highlightClassFn) {
12651251
cClass = highlightClassFn(r, c, g, cClass);
12661252
}
1267-
1253+
12681254
cell.className = 'cell ' + cClass;
12691255
cell.textContent = cellValFn(r, c);
12701256
cellContainer.appendChild(cell);
@@ -1324,9 +1310,14 @@ <h2>FAQ</h2>
13241310
c = 3,
13251311
g = Math.floor((r - 1) / 2);
13261312
var rows = [6, 5, 4, 3, 2, 1];
1327-
var frag = buildGridFragment(COLS, rows, cellVal, function(ri, ci, gi, defaultClass) {
1328-
return (ri === r && ci === c) ? 'ch' : defaultClass;
1329-
});
1313+
var frag = buildGridFragment(
1314+
COLS,
1315+
rows,
1316+
cellVal,
1317+
function (ri, ci, gi, defaultClass) {
1318+
return ri === r && ci === c ? 'ch' : defaultClass;
1319+
},
1320+
);
13301321

13311322
var fbox = document.createElement('div');
13321323
fbox.className = 'fbox';
@@ -1540,8 +1531,8 @@ <h2>FAQ</h2>
15401531
row_offset = (r - 1) % 2,
15411532
answer = base + col_offset + row_offset;
15421533
var rows = [6, 5, 4, 3, 2, 1];
1543-
var frag = buildGridFragment(COLS, rows, cellVal, function(ri, ci) {
1544-
return (ri === r && ci === c) ? 'ch' : 'cn';
1534+
var frag = buildGridFragment(COLS, rows, cellVal, function (ri, ci) {
1535+
return ri === r && ci === c ? 'ch' : 'cn';
15451536
});
15461537

15471538
var resWrap = document.createElement('div');

Mathematics/Fundamentals/HackerRank/Claude/Easy/Strange Grid Again/Strange_Grid_Again.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ if __name__ == '__main__':
104104
グリッドの先頭部分(下から)は以下の通り:
105105

106106
```
107-
Row 6: 20 22 24 26 28 ...
108-
Row 5: 21 23 25 27 29 ... ← ※上下逆に見える点に注意
109-
Row 4: 10 12 14 16 18 ...
110-
Row 3: 11 13 15 17 19 ...
107+
Row 6: 21 23 25 27 29 ...
108+
Row 5: 20 22 24 26 28 ... ← ※上下逆に見える点に注意
109+
Row 4: 11 13 15 17 19 ...
110+
Row 3: 10 12 14 16 18 ...
111111
Row 2: 1 3 5 7 9 ...
112112
Row 1: 0 2 4 6 8 ...
113113
```

public/Mathematics/Fundamentals/HackerRank/Claude/Easy/Strange Grid Again/Strange_Grid_Again.html

Lines changed: 56 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,8 @@
406406
.cpbtn:hover {
407407
background: var(--gd);
408408
}
409-
.cpbtn:focus, .cpbtn:focus-visible {
410-
outline: 2px solid var(--gd);
411-
outline-offset: 2px;
412-
}
413-
.cpbtn:focus, .cpbtn:focus-visible {
409+
.cpbtn:focus,
410+
.cpbtn:focus-visible {
414411
outline: 2px solid var(--gd);
415412
outline-offset: 2px;
416413
}
@@ -1152,6 +1149,7 @@ <h2>FAQ</h2>
11521149
})();
11531150

11541151
/* Copy */
1152+
var copyTimeoutId = null;
11551153
document.getElementById('cpbtn').addEventListener('click', function () {
11561154
var code = `from __future__ import annotations
11571155
import os
@@ -1171,13 +1169,46 @@ <h2>FAQ</h2>
11711169
result = strangeGrid(r, c)
11721170
fptr.write(str(result) + "\\n")
11731171
fptr.close()`;
1174-
navigator.clipboard.writeText(code).then(function () {
1175-
var b = document.getElementById('cpbtn');
1176-
b.textContent = 'コピー完了!';
1177-
setTimeout(function () {
1172+
var b = document.getElementById('cpbtn');
1173+
1174+
function showStatus(text) {
1175+
b.textContent = text;
1176+
if (copyTimeoutId) clearTimeout(copyTimeoutId);
1177+
copyTimeoutId = setTimeout(function () {
11781178
b.textContent = 'コピー';
11791179
}, 2000);
1180-
});
1180+
}
1181+
1182+
if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
1183+
navigator.clipboard
1184+
.writeText(code)
1185+
.then(function () {
1186+
showStatus('コピー完了!');
1187+
})
1188+
.catch(function (err) {
1189+
console.error('Copy error:', err);
1190+
showStatus('コピー失敗');
1191+
});
1192+
} else {
1193+
try {
1194+
var ta = document.createElement('textarea');
1195+
ta.value = code;
1196+
ta.style.position = 'fixed';
1197+
ta.style.opacity = '0';
1198+
document.body.appendChild(ta);
1199+
ta.select();
1200+
var res = document.execCommand('copy');
1201+
document.body.removeChild(ta);
1202+
if (res) {
1203+
showStatus('コピー完了!');
1204+
} else {
1205+
showStatus('コピー失敗');
1206+
}
1207+
} catch (e) {
1208+
console.error('Fallback copy error:', e);
1209+
showStatus('コピー失敗');
1210+
}
1211+
}
11811212
});
11821213

11831214
/* Steps */
@@ -1188,10 +1219,12 @@ <h2>FAQ</h2>
11881219
wrap.style.display = 'inline-block';
11891220

11901221
var headerDiv = document.createElement('div');
1191-
headerDiv.style.cssText = 'display:flex;gap:4px;margin-bottom:4px;margin-left:48px;';
1222+
headerDiv.style.cssText =
1223+
'display:flex;gap:4px;margin-bottom:4px;margin-left:48px;';
11921224
COLS.forEach(function (c) {
11931225
var cellDiv = document.createElement('div');
1194-
cellDiv.style.cssText = 'width:52px;text-align:center;font-size:.72rem;font-weight:700;color:#64748b;';
1226+
cellDiv.style.cssText =
1227+
'width:52px;text-align:center;font-size:.72rem;font-weight:700;color:#64748b;';
11951228
cellDiv.textContent = 'c=' + c;
11961229
headerDiv.appendChild(cellDiv);
11971230
});
@@ -1212,59 +1245,12 @@ <h2>FAQ</h2>
12121245
COLS.forEach(function (c) {
12131246
var g = Math.floor((r - 1) / 2);
12141247
var cell = document.createElement('div');
1215-
1216-
var cClass = g % 2 === 0 ? 'ca' : 'cb';
1217-
if (highlightClassFn) {
1218-
cClass = highlightClassFn(r, c, g, cClass);
1219-
}
1220-
1221-
cell.className = 'cell ' + cClass;
1222-
cell.textContent = cellValFn(r, c);
1223-
cellContainer.appendChild(cell);
1224-
});
1225-
gpRow.appendChild(cellContainer);
1226-
wrap.appendChild(gpRow);
1227-
});
1228-
frag.appendChild(wrap);
1229-
return frag;
1230-
}
12311248

1232-
function buildGridFragment(COLS, rows, cellValFn, highlightClassFn) {
1233-
var frag = document.createDocumentFragment();
1234-
var wrap = document.createElement('div');
1235-
wrap.style.display = 'inline-block';
1236-
1237-
var headerDiv = document.createElement('div');
1238-
headerDiv.style.cssText = 'display:flex;gap:4px;margin-bottom:4px;margin-left:48px;';
1239-
COLS.forEach(function (c) {
1240-
var cellDiv = document.createElement('div');
1241-
cellDiv.style.cssText = 'width:52px;text-align:center;font-size:.72rem;font-weight:700;color:#64748b;';
1242-
cellDiv.textContent = 'c=' + c;
1243-
headerDiv.appendChild(cellDiv);
1244-
});
1245-
wrap.appendChild(headerDiv);
1246-
1247-
rows.forEach(function (r) {
1248-
var gpRow = document.createElement('div');
1249-
gpRow.className = 'gp-row';
1250-
1251-
var rl = document.createElement('div');
1252-
rl.className = 'rl';
1253-
rl.textContent = 'r=' + r;
1254-
gpRow.appendChild(rl);
1255-
1256-
var cellContainer = document.createElement('div');
1257-
cellContainer.style.cssText = 'display:flex;gap:4px;';
1258-
1259-
COLS.forEach(function (c) {
1260-
var g = Math.floor((r - 1) / 2);
1261-
var cell = document.createElement('div');
1262-
12631249
var cClass = g % 2 === 0 ? 'ca' : 'cb';
12641250
if (highlightClassFn) {
12651251
cClass = highlightClassFn(r, c, g, cClass);
12661252
}
1267-
1253+
12681254
cell.className = 'cell ' + cClass;
12691255
cell.textContent = cellValFn(r, c);
12701256
cellContainer.appendChild(cell);
@@ -1324,9 +1310,14 @@ <h2>FAQ</h2>
13241310
c = 3,
13251311
g = Math.floor((r - 1) / 2);
13261312
var rows = [6, 5, 4, 3, 2, 1];
1327-
var frag = buildGridFragment(COLS, rows, cellVal, function(ri, ci, gi, defaultClass) {
1328-
return (ri === r && ci === c) ? 'ch' : defaultClass;
1329-
});
1313+
var frag = buildGridFragment(
1314+
COLS,
1315+
rows,
1316+
cellVal,
1317+
function (ri, ci, gi, defaultClass) {
1318+
return ri === r && ci === c ? 'ch' : defaultClass;
1319+
},
1320+
);
13301321

13311322
var fbox = document.createElement('div');
13321323
fbox.className = 'fbox';
@@ -1540,8 +1531,8 @@ <h2>FAQ</h2>
15401531
row_offset = (r - 1) % 2,
15411532
answer = base + col_offset + row_offset;
15421533
var rows = [6, 5, 4, 3, 2, 1];
1543-
var frag = buildGridFragment(COLS, rows, cellVal, function(ri, ci) {
1544-
return (ri === r && ci === c) ? 'ch' : 'cn';
1534+
var frag = buildGridFragment(COLS, rows, cellVal, function (ri, ci) {
1535+
return ri === r && ci === c ? 'ch' : 'cn';
15451536
});
15461537

15471538
var resWrap = document.createElement('div');

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ <h1 class="site-title">
787787

788788
<footer>
789789
<span class="footer-icon">🧪</span>
790-
Generated on 2026-02-21 02:33:33 UTC
790+
Generated on 2026-02-21 03:08:55 UTC
791791
</footer>
792792

793793
<script>

0 commit comments

Comments
 (0)