Skip to content

Commit

Permalink
Merge pull request #26 from koudaiii/koudaiii/fix-naming
Browse files Browse the repository at this point in the history
fix naming
  • Loading branch information
koudaiii authored Sep 5, 2024
2 parents 7561ce7 + e47f72d commit 572b6b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jp-learn-microsoft-com-update-checker",
"name": "learn-microsoft-com-update-checker",
"version": "1.2.0",
"description": "Chrome extension to check and display the latest update date from the English version of Microsoft Learn pages when viewing the Japanese version.",
"description": "Chrome extension to check and display the latest update date from the English version of Microsoft Learn pages when viewing the current language version.",
"main": "src/content.js",
"scripts": {
"test:unit": "jest tests/unit",
Expand Down
22 changes: 11 additions & 11 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ const languageLabels = {
const currentLang = languageCodeMatch ? languageCodeMatch[1] : null;
if (!currentLang) return;

// Check if the page(https://learn.microsoft.com/en-us) is in en-us
// Check if the page(https://learn.microsoft.com/en-us) is in en-us, if so, return
const lang = 'en-us';
if (currentLang === lang) return;

const debug = new URLSearchParams(window.location.search).get("jp-learn-microsoft-com-update-checker-debug");

// Get Japanese date element
const japaneseDateElement = document.querySelector('time[data-article-date]');
if (!japaneseDateElement) return;
// Get data-article-date element in current page
const dataArticleDateElement = document.querySelector('time[data-article-date]');
if (!dataArticleDateElement) return;

// Parse Japanese date
const japaneseDateStr = japaneseDateElement.getAttribute("datetime");
const japaneseDate = new Date(japaneseDateStr);
// Parse article date
const articleDateStr = dataArticleDateElement.getAttribute("datetime");
const articleDate = new Date(articleDateStr);

// Translate URL to English
const englishUrl = currentUrl.replace(`/${currentLang}/`, "/en-us/");
Expand All @@ -45,7 +45,7 @@ const languageLabels = {

// Add update info to current page
const updateInfo = document.createElement("p");
japaneseDateElement.parentElement.appendChild(updateInfo);
dataArticleDateElement.parentElement.appendChild(updateInfo);

const updateClass = () => {
// if theme is selected, apply appropriate text color based on theme
Expand All @@ -61,9 +61,9 @@ const languageLabels = {
informationIcon = "";

console.log("English date:", englishDate);
console.log("Japanese date:", japaneseDate);
// Compare English date and Japanese date
if (englishDate > japaneseDate || debug === "true") {
console.log("Article date:", articleDate);
// Compare English date and Article date
if (englishDate > articleDate || debug === "true") {
// Display alert if English page is updated
updateInfo.className = "alert is-primary"; // <class="alert is-primary"> is defined in CSS
updateInfo.style.margin = "5px";
Expand Down

0 comments on commit 572b6b6

Please sign in to comment.