Skip to content

Commit 9fd4f9b

Browse files
committed
q
1 parent 9b2fdce commit 9fd4f9b

1 file changed

Lines changed: 87 additions & 11 deletions

File tree

pages/git/index.html

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,9 @@ <h2>change commit timestamp</h2>
909909
document.addEventListener("DOMContentLoaded", () => {
910910
const parent = document.querySelector("#timestaxxxxmp-table");
911911

912-
const offsetRange = parent.querySelector("[name=offset]");
913-
const offsetOutput = parent.querySelector("[name=offset-output]");
912+
const offsetRange = parent.querySelector(`[name="offset"]`);
913+
const offsetOutput = parent.querySelector(`[name="offset-output"]`);
914+
const offsetButton = parent.querySelector(`[name="offset-button"]`);
914915

915916
var year = (function (target) {
916917
var current = new Date().getFullYear();
@@ -1055,6 +1056,74 @@ <h2>change commit timestamp</h2>
10551056
return d;
10561057
})(parent.querySelector("#hash"));
10571058

1059+
range(offsetRange, (v) => {
1060+
var d = getDateWithOffset();
1061+
1062+
offsetOutput.textContent = d.toISOString() + " - " + humanReadable(v);
1063+
});
1064+
1065+
function humanReadable(seconds) {
1066+
var h = Math.floor(seconds / 3600);
1067+
var m = Math.floor((seconds % 3600) / 60);
1068+
var s = seconds % 60;
1069+
1070+
var res = [];
1071+
if (h > 0) res.push(h + "h");
1072+
if (m > 0) res.push(m + "m");
1073+
if (s > 0 || res.length === 0) res.push(s + "s");
1074+
1075+
return res.join(" ");
1076+
}
1077+
1078+
function getCurrentTime() {
1079+
var d = new Date();
1080+
1081+
d.setFullYear(year.value);
1082+
d.setMonth(month.value);
1083+
d.setDate(day.value);
1084+
d.setHours(hour.value);
1085+
d.setMinutes(minute.value);
1086+
d.setSeconds(seconds.value);
1087+
d.setMilliseconds(0);
1088+
1089+
return d;
1090+
}
1091+
1092+
function setInputsWithDate(d) {
1093+
year.value = d.getFullYear();
1094+
month.value = d.getMonth();
1095+
day.value = d.getDate();
1096+
hour.value = d.getHours();
1097+
minute.value = d.getMinutes();
1098+
seconds.value = d.getSeconds();
1099+
}
1100+
1101+
function getDateWithOffset() {
1102+
var d = getCurrentTime();
1103+
1104+
var offset = parseInt(offsetRange.value, 10);
1105+
1106+
var randomMs = Math.floor(Math.random() * 1000);
1107+
1108+
d.setSeconds(d.getSeconds() + offset);
1109+
1110+
d.setMilliseconds(randomMs);
1111+
1112+
return d;
1113+
}
1114+
1115+
offsetButton.addEventListener("click", function () {
1116+
var d = getDateWithOffset();
1117+
1118+
var offset = parseInt(offsetRange.value, 10);
1119+
1120+
offsetOutput.textContent = d.toISOString() + " - " + humanReadable(offset);
1121+
1122+
setInputsWithDate(d)
1123+
1124+
update(d);
1125+
});
1126+
10581127
var update = (function () {
10591128
var element = parent.querySelector(".timestamp");
10601129

@@ -1064,15 +1133,8 @@ <h2>change commit timestamp</h2>
10641133

10651134
var pre = element.value;
10661135

1067-
return function () {
1068-
var d = new Date();
1069-
1070-
d.setFullYear(year.value);
1071-
d.setMonth(month.value);
1072-
d.setDate(day.value);
1073-
d.setHours(hour.value);
1074-
d.setMinutes(minute.value);
1075-
d.setSeconds(seconds.value);
1136+
return function (d) {
1137+
d = d ?? getCurrentTime();
10761138

10771139
element.value = pre.replace(/xxx/g, d.toISOString()).replace(/yyy/g, hash.value);
10781140
};
@@ -1083,6 +1145,17 @@ <h2>change commit timestamp</h2>
10831145
});
10841146

10851147
update();
1148+
1149+
function range(element, event, onLoad = true) {
1150+
function hc() {
1151+
event(parseInt(element.value, 10));
1152+
}
1153+
element.addEventListener("change", hc);
1154+
element.addEventListener("input", hc);
1155+
if (onLoad) {
1156+
hc();
1157+
}
1158+
}
10861159
});
10871160
}
10881161
</script>
@@ -1127,6 +1200,9 @@ <h2>change commit timestamp</h2>
11271200
<div>
11281201
<pre name="offset-output"></pre>
11291202
</div>
1203+
<div>
1204+
<button name="offset-button">apply</button>
1205+
</div>
11301206
</td>
11311207
</tr>
11321208
</tbody>

0 commit comments

Comments
 (0)