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.

83 lines
3.7 KiB
HTML

1 month ago
<!doctype html>
<html>
<head>
<style>
1 month ago
body {
font-face: monospace;
margin: 5%;
}
1 month ago
ins { color: green }
del { color: red }
#comment { font-style: italic; }
1 month ago
#revision { display: none } /* hide the template */
.revision {
border-bottom: 1px dotted gray;
}
.revision .body .mw-diff-inline-header {
display: none;
}
.revision .body .mw-diff-inline-context {
display: none;
}
.revision .body .mw-diff-inline-changed {
color: white;
}
1 month ago
</style>
</head>
<body>
1 month ago
<div>
title: <input type="text" name="title" value="Han Kang" />
revid:<input type="text" value="376586279" name="revision" />
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>
1 month ago
<script>
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: "*"
}
1 month ago
let title = document.querySelector("input[name=title]");
let revid = document.querySelector("input[name=revision]");
let numrevs = document.querySelector("input[name=numrevs]");
1 month 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=*";
1 month ago
let generate = document.querySelector("button#generate");
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;
revision.querySelector(".timestamp").textContent = data.compare.totimestamp;
revision.querySelector(".comment").textContent = data.compare.tocomment;
}
1 month ago
})
</script>
</body>
</html>