You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
5.0 KiB
HTML

2 months ago
<!doctype html>
<html>
<head>
<style>
2 months ago
body {
2 months ago
font-family: monospace;
2 months ago
margin: 5%;
}
2 months ago
#controls {
margin-bottom: 1em;
}
ins {
color: black;
visibility: visible;
}
del {
color: black;
visibility: visible;
}
2 months ago
#comment { font-style: italic; }
2 months ago
#revision { display: none } /* hide the template */
.revision {
margin-bottom: 2em;
2 months ago
text-align: center;
}
.revision .timestamp {
font-style: italic;
margin-bottom: 1em;
}
2 months ago
.revision .user {
text-transform: uppercase;
margin-bottom: 1em;
2 months ago
}
.revision .comment {
font-style: italic;
margin-bottom: 1em;
2 months ago
}
.revision .body .mw-diff-inline-header {
display: none;
}
.revision .body .mw-diff-inline-context {
display: none;
}
.revision .body .mw-diff-inline-changed {
color: white;
2 months ago
visibility: hidden;
2 months ago
}
2 months ago
</style>
</head>
<body>
2 months ago
<div id="controls">
article title: <input type="text" name="title" value="Han Kang" />
starting revision (id):<input type="text" value="376586279" name="revision" />
2 months ago
number of revisions: <input type="range" name="numrevs" min="1" max="100" value="10" />
<button id="generate">generate script</button>
</div>
<div id="revision" class="revision">
<div class="timestamp"></div>
<div class="user"></div>
<div class="comment"></div>
<div class="body"></div>
</div>
<div id="revisions"></div>
2 months ago
<script src="difftime.js"></script>
2 months ago
<script>
2 months ago
const dateFormat = new Intl.RelativeTimeFormat('en', { style: 'long' });
2 months ago
let r = {
action: "compare",
format: "json",
fromtitle: "Han Kang",
totitle: "Han Kang",
torelative: "next",
formatversion: 2,
prop: "diff|ids|title|user|comment|parsedcomment|timestamp",
difftype: "inline", // table, inline, unified
origin: "*"
}
2 months ago
let title = document.querySelector("input[name=title]");
let revid = document.querySelector("input[name=revision]");
let numrevs = document.querySelector("input[name=numrevs]");
2 months ago
let api_url = "https://en.wikipedia.org/w/api.php"
// let url = "https://en.wikipedia.org/w/api.php?action=compare&format=json&fromtitle=Han%20Kang&fromrev=376586279&totitle=Han%20Kang&torelative=next&formatversion=2&origin=*";
2 months ago
let generate = document.querySelector("button#generate");
2 months ago
let last_time;
2 months ago
generate.addEventListener("click", async e => {
r.fromrev = parseInt(revid.value);
r.fromtitle = title.value.trim();
r.totitle = r.fromtitle;
for (let x = 0; x<parseInt(numrevs.value); x++) {
console.log(`generate step ${x+1}`);
let resp = await fetch(api_url + "?" + new URLSearchParams(r));
let data = await resp.json();
// https://developer.mozilla.org/en-US/docs/Web/API/Node/cloneNode
let revision = document.querySelector("#revision").cloneNode(true);
revision.removeAttribute("id"); // technically shouldn't have multiple elements with the same id
document.querySelector("#revisions").appendChild(revision);
console.log("generate: got data", data);
revision.querySelector(".body").innerHTML = data.compare.body;
r.fromrev = data.compare.torevid;
console.log("generate, next revid", r.revid);
revision.querySelector(".user").textContent = data.compare.touser;
2 months ago
// revision.querySelector(".timestamp").textContent = data.compare.totimestamp;
console.log("totimestamp", data.compare.totimestamp);
let ts = new Date(data.compare.totimestamp);
if (x == 0) {
revision.querySelector(".timestamp").textContent = ts.toString();
} else {
revision.querySelector(".timestamp").textContent = replaceInWithLater(timeDiff(ts, last_time, dateFormat));
}
last_time = ts.getUTCTime();
2 months ago
revision.querySelector(".comment").textContent = data.compare.tocomment;
}
2 months ago
})
</script>
</body>
</html>