Skip to content

Commit

Permalink
Feat/refactor network request (#59)
Browse files Browse the repository at this point in the history
* 🚧 Add pop module

* 🚧 Modify build & release command.

* 🚧 Config to show popup page.

* 🚧 Remove duplicated code.

* 🚧 Add tailwindcss support.

* πŸ”– Bump version.

* 🚧 Increase version number.

* 🎨 Update proto.

* 🎨 Ignore source files in popup module.

* 🎨 Add new module.

* 🎨 Remove unnecessary code.

* 🎨 Do not use Vue framework.

* 🎨 Bump version.

* 🎨 Fix bug.

* 🎨 Fix bug.

* 🎨 Fix bug.

* 🎨 Bump version;

---------

Co-authored-by: Toly <[email protected]>
  • Loading branch information
tolerious and Toly authored Dec 14, 2024
1 parent 657db68 commit fb4df71
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Stylish Reader",
"description": "Help you learn English better and easier.",
"developer": { "name": "Toly Feng", "url": "https://stylishreader.com" },
"version": "0.0.12",
"version": "0.0.15",
"icons": {
"48": "icons/stylish-reader-48.png"
},
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/general/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ async function createTranslationFloatingPanelToShadowDom(x = 0, y = 0) {
// 添加到鑡青上
document.body.appendChild(shadowRoot);

eval(vueScript.textContent);
// eval(vueScript.textContent);
return Promise.resolve();
}

Expand Down
51 changes: 21 additions & 30 deletions src/webPage/translationPanel/src/elementControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ export function playAudio(data: any) {
"stylish-reader-translation-panel-shadow-root"
)?.shadowRoot;
if (shadow) {
const audio = shadow.querySelector("#audioPlayer");
if (audio instanceof HTMLElement) {
audio.setAttribute("src", data);
// @ts-ignore
audio.play();
}
const audio = shadow.querySelector("#audioPlayer") as HTMLAudioElement;
audio.setAttribute("src", data);
audio.play();
}
}

Expand All @@ -27,10 +24,8 @@ export function hideUnLikeIcon() {
"stylish-reader-translation-panel-shadow-root"
)?.shadowRoot;
if (shadow) {
const icon = shadow.querySelector("#unlike-icon");
if (icon instanceof HTMLElement) {
icon.style.display = "none";
}
const icon = shadow.querySelector("#unlike-icon") as HTMLElement;
icon.style.display = "none";
}
}
export function showLikeIcon() {
Expand All @@ -47,10 +42,8 @@ export function hideLikeIcon() {
"stylish-reader-translation-panel-shadow-root"
)?.shadowRoot;
if (shadow) {
const icon = shadow.querySelector("#like-icon");
if (icon instanceof HTMLElement) {
icon.style.display = "none";
}
const icon = shadow.querySelector("#like-icon") as HTMLElement;
icon.style.display = "none";
}
}

Expand All @@ -72,10 +65,10 @@ export function clearTranslationContainerContent() {
"stylish-reader-translation-panel-shadow-root"
)?.shadowRoot;
if (shadow) {
const translationContainer = shadow.querySelector("#translation-container");
if (translationContainer instanceof HTMLElement) {
translationContainer.replaceChildren();
}
const translationContainer = shadow.querySelector(
"#translation-container"
) as HTMLElement;
translationContainer.replaceChildren();
}
}

Expand All @@ -86,14 +79,14 @@ export function generateTranslationContent(translations: []) {
"stylish-reader-translation-panel-shadow-root"
)?.shadowRoot;
if (shadow) {
const translationContainer = shadow.querySelector("#translation-container");
if (translationContainer instanceof HTMLElement) {
translations.forEach((translation: { pos: string; zh: string }) => {
translationContainer.appendChild(
generateTranslationItem(translation.pos, translation.zh)
);
});
}
const translationContainer = shadow.querySelector(
"#translation-container"
) as HTMLElement;
translations.forEach((translation: { pos: string; zh: string }) => {
translationContainer.appendChild(
generateTranslationItem(translation.pos, translation.zh)
);
});
}
}

Expand All @@ -102,9 +95,7 @@ export function setPhoneticContent(content: string) {
"stylish-reader-translation-panel-shadow-root"
)?.shadowRoot;
if (shadow) {
const phonetic = shadow.querySelector("#phonetic");
if (phonetic instanceof HTMLElement) {
phonetic.textContent = content;
}
const phonetic = shadow.querySelector("#phonetic") as HTMLElement;
phonetic.textContent = content;
}
}
30 changes: 12 additions & 18 deletions src/webPage/translationPanel/src/eventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,18 @@ export function addEventListener() {
google.addEventListener("click", () => goToGoogleTranslate());
}

const playButton = shadow?.querySelector("#play-audio");
if (playButton instanceof HTMLElement) {
playButton.addEventListener("click", () =>
getAudioStream(localStorage.getItem("currentWord")!)
);
}
const playButton = shadow?.querySelector("#play-audio") as HTMLElement;
playButton.addEventListener("click", () =>
getAudioStream(localStorage.getItem("currentWord")!)
);

const likeIcon = shadow?.querySelector("#like-icon");
if (likeIcon instanceof HTMLElement) {
likeIcon.addEventListener("click", () => {
deleteWord();
});
}
const likeIcon = shadow?.querySelector("#like-icon") as HTMLElement;
likeIcon.addEventListener("click", () => {
deleteWord();
});

const unLikeIcon = shadow?.querySelector("#unlike-icon");
if (unLikeIcon instanceof HTMLElement) {
unLikeIcon.addEventListener("click", () => {
favourWord();
});
}
const unLikeIcon = shadow?.querySelector("#unlike-icon") as HTMLElement;
unLikeIcon.addEventListener("click", () => {
favourWord();
});
}

0 comments on commit fb4df71

Please sign in to comment.