epicpedia

main
Michael Murtaugh 1 month ago
parent d481ff2272
commit f976044d73

@ -3,15 +3,32 @@
<head> <head>
<style> <style>
body { body {
font-face: monospace; font-family: monospace;
margin: 5%; margin: 5%;
} }
ins { color: green } #controls {
del { color: red } margin-bottom: 1em;
}
ins {
color: black;
visibility: visible;
}
del {
color: black;
visibility: visible;
}
#comment { font-style: italic; } #comment { font-style: italic; }
#revision { display: none } /* hide the template */ #revision { display: none } /* hide the template */
.revision { .revision {
border-bottom: 1px dotted gray; border-bottom: 1px dotted gray;
margin-bottom: 1em;
text-align: center;
}
.revision .user {
text-transform: uppercase;
}
.revision .comment {
font-style: italic;
} }
.revision .body .mw-diff-inline-header { .revision .body .mw-diff-inline-header {
display: none; display: none;
@ -21,14 +38,15 @@
} }
.revision .body .mw-diff-inline-changed { .revision .body .mw-diff-inline-changed {
color: white; color: white;
visibility: hidden;
} }
</style> </style>
</head> </head>
<body> <body>
<div> <div id="controls">
title: <input type="text" name="title" value="Han Kang" /> article title: <input type="text" name="title" value="Han Kang" />
revid:<input type="text" value="376586279" name="revision" /> starting revision (id):<input type="text" value="376586279" name="revision" />
number of revisions: <input type="range" name="numrevs" min="1" max="100" value="10" /> number of revisions: <input type="range" name="numrevs" min="1" max="100" value="10" />
<button id="generate">generate script</button> <button id="generate">generate script</button>
</div> </div>
@ -39,7 +57,9 @@
<div class="body"></div> <div class="body"></div>
</div> </div>
<div id="revisions"></div> <div id="revisions"></div>
<script src="difftime.js"></script>
<script> <script>
const dateFormat = new Intl.RelativeTimeFormat('en', { style: 'long' });
let r = { let r = {
action: "compare", action: "compare",
format: "json", format: "json",
@ -57,6 +77,7 @@
let api_url = "https://en.wikipedia.org/w/api.php" 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=*"; // 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=*";
let generate = document.querySelector("button#generate"); let generate = document.querySelector("button#generate");
let last_time;
generate.addEventListener("click", async e => { generate.addEventListener("click", async e => {
r.fromrev = parseInt(revid.value); r.fromrev = parseInt(revid.value);
r.fromtitle = title.value.trim(); r.fromtitle = title.value.trim();
@ -74,7 +95,17 @@
r.fromrev = data.compare.torevid; r.fromrev = data.compare.torevid;
console.log("generate, next revid", r.revid); console.log("generate, next revid", r.revid);
revision.querySelector(".user").textContent = data.compare.touser; revision.querySelector(".user").textContent = data.compare.touser;
revision.querySelector(".timestamp").textContent = data.compare.totimestamp;
// 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();
revision.querySelector(".comment").textContent = data.compare.tocomment; revision.querySelector(".comment").textContent = data.compare.tocomment;
} }
}) })

Loading…
Cancel
Save