Skip to content

Instantly share code, notes, and snippets.

@kubosho
Forked from ArcCosine/mondo's script refactor
Last active February 8, 2018 06:50
Show Gist options
  • Save kubosho/bc98af0f8da17e441e147694ea12da51 to your computer and use it in GitHub Desktop.
Save kubosho/bc98af0f8da17e441e147694ea12da51 to your computer and use it in GitHub Desktop.
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