-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(page-icon): add sidebar links inherited icons on load/add
- Loading branch information
Showing
10 changed files
with
91 additions
and
22 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { doc } from './DOMContainers'; | ||
import { searchIcon } from './queries'; | ||
|
||
export const setSidebarIcons = async (sidebarLinksList?: NodeListOf<HTMLAnchorElement> | HTMLAnchorElement[]) => { | ||
if (!sidebarLinksList) { | ||
sidebarLinksList = doc.querySelectorAll('.nav-contents-container :is(.favorite-item , .recent-item) .items-center'); | ||
} | ||
for (let i = 0; i < sidebarLinksList.length; i++) { | ||
const sidebarLinkItem = sidebarLinksList[i]; | ||
const defaultIcon = sidebarLinkItem.querySelector('.ui__icon'); | ||
if (!defaultIcon) { | ||
continue; | ||
} | ||
const pageTitle = sidebarLinkItem.querySelector('.page-title')?.textContent; | ||
if (!pageTitle) { | ||
continue; | ||
} | ||
const pageIcon = await searchIcon(pageTitle); | ||
if (pageIcon) { | ||
sidebarLinkItem.insertAdjacentHTML('afterbegin', `<span class="page-icon awLinks-sidebar-icon">${pageIcon}</span>`); | ||
} | ||
} | ||
} | ||
|
||
const removeSidebarIcons = () => { | ||
const pageIcons = doc.querySelectorAll('.nav-contents-container .page-icon.awLinks-sidebar-icon'); | ||
if (pageIcons.length) { | ||
for (let i = 0; i < pageIcons.length; i++) { | ||
pageIcons[i].remove(); | ||
} | ||
} | ||
} | ||
|
||
export const sidebarIconsLoad = async () => { | ||
setSidebarIcons(); | ||
} | ||
|
||
export const sidebarIconsUnload = () => { | ||
removeSidebarIcons(); | ||
} |
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