Last active
May 11, 2023 10:28
-
-
Save tani/ebaf4578518e860def0b96e096dea229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Show Weekly Diff / esa.io | |
// @namespace io.github.tani | |
// @match https://*.esa.io/posts/* | |
// @grant none | |
// @version 1.0 | |
// @author Masaya Taniguchi | |
// @description 2023/5/11 18:40:31 | |
// @require https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js | |
// ==/UserScript== | |
// Usage | |
// Step 1. Install UserScript Manager (TemperMonkey / ViolentMonkey / GreaseMonkey) as you want | |
// Step 2. Go to https://gist.github.com/tani/ebaf4578518e860def0b96e096dea229/raw/show_weekly_diff.user.js | |
// Step 3. Click a button to install this script | |
// Step 4. Go to https://*.esa.io/posts/* | |
// Step 5. Click a link "Show weekly diff" | |
(async () => { | |
const response = await fetch(window.document.location.href + '/revisions') | |
const text = await response.text() | |
const parser = new DOMParser() | |
const doc = parser.parseFromString(text, 'text/html') | |
const revList = doc.querySelectorAll(".revision-list__item") | |
const today = dayjs() | |
let latestRev = parseInt(revList[0].querySelector(".num").innerHTML) | |
let oldestRev = latestRev | |
for(revItem of revList) { | |
const num = parseInt(revItem.querySelector(".num").innerHTML) | |
const date = dayjs(revItem.querySelector(".revision-list__date").innerHTML.slice(0, 10)) | |
console.log(date) | |
if(today.diff(date, 'day') >= 7) { | |
oldestRev = num | |
break | |
} | |
} | |
const el = window.document.createElement('li') | |
el.class = "viewer-action__item" | |
el.innerHTML = `<a href="${window.document.location.href}/revisions/compare/${oldestRev}...${latestRev}">Show weekly diff</a>` | |
window.document.querySelector('.viewer-action').append(el) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment