Skip to content

Commit b04a535

Browse files
committed
Added <hr class="hr"> in the buttom. And add doc
1 parent 1111ddd commit b04a535

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,91 @@ npm run test:unit
9898
npm run test:e2e
9999
```
100100

101+
## Architecture
102+
103+
### DOM Structure and Element Cloning
104+
105+
This extension displays English version update information by cloning the existing `article-metadata-footer` element on Microsoft Learn pages.
106+
107+
#### HTML Structure
108+
109+
The Microsoft Learn page has the following structure:
110+
111+
```html
112+
<div data-main-column="">
113+
<div>
114+
<!-- Page header with breadcrumbs and actions -->
115+
<div id="article-header">...</div>
116+
117+
<!-- Article title -->
118+
<div class="content"><h1>Title</h1></div>
119+
120+
<!-- Top metadata (existing) -->
121+
<div id="article-metadata">
122+
<div id="user-feedback">...</div>
123+
</div>
124+
125+
<!-- Our custom cloned element (inserted here - after article-metadata) -->
126+
<div id="custom-header-from-article-metadata-footer">
127+
<hr class="hr">
128+
<ul class="metadata page-metadata" lang="ja-jp">
129+
<li>
130+
<span class="badge">Last updated on 2025/10/08</span>
131+
<p>英語版の更新日: <a href="...">2025/4/10 (224 日前に更新)</a></p>
132+
</li>
133+
</ul>
134+
</div>
135+
136+
<hr class="hr">
137+
138+
<!-- Article content -->
139+
<div class="content">...</div>
140+
141+
<!-- Feedback section and other components -->
142+
143+
<!-- Bottom metadata (clone source) -->
144+
<div id="article-metadata-footer">
145+
<hr class="hr">
146+
<ul class="metadata page-metadata">
147+
<li>
148+
<span class="badge">Last updated on 2025/10/08</span>
149+
</li>
150+
</ul>
151+
</div>
152+
</div>
153+
</div>
154+
```
155+
156+
#### Cloning Strategy
157+
158+
The extension uses the following approach:
159+
160+
1. **Clone Source**: `article-metadata-footer` element (bottom of the page)
161+
- This element contains the page's metadata structure with proper styling
162+
163+
2. **Clone Process**:
164+
```javascript
165+
customContainer = articleMetadataFooter.cloneNode(true);
166+
customContainer.id = 'custom-header-from-article-metadata-footer';
167+
```
168+
169+
3. **Insertion Point**: Inserted immediately after `article-metadata` (top of the page)
170+
```javascript
171+
articleMetadata.insertAdjacentElement('afterend', customContainer);
172+
```
173+
174+
4. **Customization**:
175+
- Update the `lang` attribute to match the current page language
176+
- Add a new `<p>` element containing the English version update information
177+
- Apply appropriate styling based on whether the English version is newer
178+
179+
#### Why This Approach?
180+
181+
- **Consistency**: By cloning the existing metadata footer, we inherit all the proper CSS classes and structure
182+
- **Maintainability**: If Microsoft changes the metadata structure, our extension adapts automatically
183+
- **Visibility**: Placing the update information near the top of the page ensures users see it immediately
184+
- **Clone-based**: We clone from `article-metadata-footer` at the bottom but display at the top for better UX
185+
101186
## Contribution
102187

103188
Contributions are welcome! Follow these steps to contribute:

src/content.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ const applyStyles = (element, styles) => {
180180
}
181181

182182
articleMetadata.insertAdjacentElement('afterend', customContainer);
183+
184+
// Add hr element below custom container
185+
const hr = document.createElement('hr');
186+
hr.className = 'hr';
187+
customContainer.insertAdjacentElement('afterend', hr);
183188
} else if (customContainer) {
184189
updateInfo = customContainer.querySelector('li.visibility-hidden-visual-diff p');
185190
}

0 commit comments

Comments
 (0)