-
-
Save kubosho/bc98af0f8da17e441e147694ea12da51 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
javascript:( | |
() => { | |
'use strict'; | |
const getLastUpdate = (domObj) => { | |
return domObj.querySelector(".contributors-sub time").dateTime; | |
}; | |
const isOlderJapaneseArticle = (jaLastMod, enLastMod) => { | |
return Date.parse(jaLastMod) - Date.parse(enLastMod) < 0; | |
}; | |
const renderMessages = (messages) => { | |
const article = document.querySelector('#wikiArticle'); | |
messages.forEach((message) => article.insertBefore(message)); | |
} | |
// fetchで英語版MDNを取得 | |
fetch(`https://developer.mozilla.org/${location.pathname.replace(/ja/, 'en-US')}/`) | |
.then((response) => { | |
console.log(response); | |
return response.text(); | |
}) | |
.then((resText) => { | |
const parser = new DOMParser(); | |
const enLastMod = getLastUpdate(parser.parseFromString(resText, "text/html")); | |
const jaLastMod = getLastUpdate(document); | |
let message = 'この情報は最新です☺'; | |
let updated = ''; | |
if (isOlderJapaneseArticle(jaLastMod, enLastMod)) { | |
message = '日本語の情報が古いです。'; | |
updated = `en: ${enLastMod}, ja: ${jaLastMod}`; | |
} | |
renderMessages([message, updated]); | |
}); | |
} | |
)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment