From 07976ba6000f2050e96fd3de6ff4c048ac94f559 Mon Sep 17 00:00:00 2001 From: Sergey Kolesnik Date: Fri, 7 Jul 2023 23:29:32 +0300 Subject: [PATCH 1/3] fix: compatibility with other plugins: inserting icon right before text node --- src/modules/pageIcons/pageIcons.ts | 8 +++++--- src/modules/utils.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/modules/pageIcons/pageIcons.ts b/src/modules/pageIcons/pageIcons.ts index 2bd51c5..f757df8 100644 --- a/src/modules/pageIcons/pageIcons.ts +++ b/src/modules/pageIcons/pageIcons.ts @@ -1,7 +1,7 @@ import fastdom from 'fastdom' import { body, doc, globals, propsObject, root } from '../globals'; -import { settingsTextToPropsObj, isNeedLowContrastFix, isEmoji, injectPluginCSS, ejectPluginCSS } from '../utils'; +import { settingsTextToPropsObj, isNeedLowContrastFix, isEmoji, injectPluginCSS, ejectPluginCSS, htmlToElement } from '../utils'; import { getPropsByPageName } from './queries'; import pageIconsStyles from './pageIcons.css?inline'; @@ -129,11 +129,13 @@ const setIconToLinkItem = async (linkItem: HTMLElement, pageProps: propsObject, return; } if (pageIcon && pageIcon !== 'none') { - const oldPageIcon = linkItem.querySelector('.awLi-icon'); oldPageIcon && oldPageIcon.remove(); hideTitle(linkItem, pageProps); - linkItem.insertAdjacentHTML('afterbegin', `${pageIcon}`); + + const iconNode = htmlToElement(`${pageIcon}`); + const lastNode = linkItem.childNodes[linkItem.childNodes.length - 1]; + linkItem.insertBefore(iconNode, lastNode); } } diff --git a/src/modules/utils.ts b/src/modules/utils.ts index acd44db..03004e0 100644 --- a/src/modules/utils.ts +++ b/src/modules/utils.ts @@ -103,3 +103,13 @@ export const ejectPluginCSS = (iframeId: string, label: string) => { } pluginIframe.contentDocument?.getElementById(label)?.remove(); } + +/** + * source: https://stackoverflow.com/a/35385518/7662783 + */ +export function htmlToElement(html: string): ChildNode { + var template = document.createElement('template'); + html = html.trim(); // Never return a text node of whitespace as the result + template.innerHTML = html; + return template.content.firstChild as ChildNode; +} From bc30ea8914e52eb151e3d70b350e9fa92bcdfdd7 Mon Sep 17 00:00:00 2001 From: Sergey Kolesnik Date: Sat, 13 Jul 2024 15:58:24 +0300 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20var=20=E2=86=92=20const?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/utils.ts b/src/modules/utils.ts index 03004e0..9f1a5d0 100644 --- a/src/modules/utils.ts +++ b/src/modules/utils.ts @@ -108,7 +108,7 @@ export const ejectPluginCSS = (iframeId: string, label: string) => { * source: https://stackoverflow.com/a/35385518/7662783 */ export function htmlToElement(html: string): ChildNode { - var template = document.createElement('template'); + const template = document.createElement('template'); html = html.trim(); // Never return a text node of whitespace as the result template.innerHTML = html; return template.content.firstChild as ChildNode; From df6d1f355f4e07a208c74a08b5f61b375325994a Mon Sep 17 00:00:00 2001 From: Sergey Kolesnik Date: Sat, 13 Jul 2024 16:14:55 +0300 Subject: [PATCH 3/3] build: inc pnpm action version --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d915f14..5aad4c7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,9 +26,9 @@ jobs: node-version: "18" - name: Setup pnpm - uses: pnpm/action-setup@v2.2.4 + uses: pnpm/action-setup@v4 with: - version: 7 + version: latest - name: Install dependencies run: pnpm install