Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7dc53fa
🎨 Update version.
tolerious Jan 31, 2025
0305a9a
🎨 Cut background script out.
tolerious Jan 31, 2025
c550a93
🎨 Complete search-word request.
tolerious Feb 1, 2025
ae9d7ee
🎨 Favour word function done.
tolerious Feb 1, 2025
698c504
🎨 Favour word function.
tolerious Feb 1, 2025
bc8fcd0
🎨 Delete word done.
tolerious Feb 1, 2025
e987a75
🎨 Remove log.
tolerious Feb 1, 2025
227e1f7
🎨 Update.
tolerious Feb 1, 2025
710ad70
🎨 Fix bug.
tolerious Feb 1, 2025
75b66ca
🎨 Fix bug.
tolerious Feb 1, 2025
ddf06af
🎨 Update version number.
tolerious Feb 1, 2025
8423b65
🎨 Play
tolerious Feb 1, 2025
84ee75b
🎨 Add audio element.
tolerious Feb 1, 2025
748651b
🎨 Remove log.
tolerious Feb 1, 2025
63f87fe
🎨 Remove floating panel folder.
tolerious Feb 1, 2025
b15cb4a
🎨 Don't speak for phrase or sentence.
tolerious Feb 1, 2025
15cccc2
🙈 Udpate ignore file.
tolerious Feb 2, 2025
0e0680a
✨ Add review word link.
tolerious Feb 2, 2025
3de4cc8
🎨 Fix conflict.
tolerious Feb 2, 2025
26d1d2b
🎨 Update code.
tolerious Feb 2, 2025
3034e96
🎨 Fix bug.
tolerious Feb 2, 2025
9c858b6
🔖 Update version.
tolerious Feb 2, 2025
a87d157
🎨 Fix conflict.
tolerious Feb 2, 2025
17d54fb
🐛 Fix #67
tolerious Feb 3, 2025
47bd0a0
🔖 Update version.
tolerious Feb 3, 2025
b593461
✨ Add custom element.
tolerious Feb 4, 2025
11a7e14
🔖 Update version.
tolerious Feb 4, 2025
c1408a4
🐛 Fix request multiple times issue.
tolerious Feb 4, 2025
22c07c7
🔇 Remove log.
tolerious Feb 6, 2025
970da7c
🐛 Fix request could be multiple times & remove temporary floating panel.
tolerious Feb 9, 2025
31af6d6
🔖 Update version.
tolerious Feb 9, 2025
a25f2af
✏️ Add new symbol regex.
tolerious Feb 11, 2025
1f4566c
🔀 Merge with master.
tolerious Feb 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/background/background.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function convertStringToLowerCaseAndRemoveSpecialCharacter(s) {
.replace(/\)/g, "")
.replace(/:/g, "")
.replace(/'/g, "")
.replace(/’/g, "")
.replace(/\?/g, "")
.replace(/!/g, "");
}
Expand Down
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.23",
"version": "0.0.25",
"icons": {
"48": "icons/stylish-reader-48.png"
},
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/general/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { listenEventFromBackgroundScript, logger } from "../utils/utils";
import { StylishReaderSpan } from "./stylishReaderSpan";
import {
createAndSetDefaultGroupForCurrentPage,
createAudioTagForFloatingPanel,
customizeGeneralEvent,
getWordList,
goThroughDomAndGenerateCustomElement,
injectPhraseFloatingPanelToShadowDom,
injectTranslationFloatingPanelToShadowDom,
listenEventFromOfficialWebsite,
} from "./utils";

export async function initializeGeneralWebSite() {
customElements.define("stylish-reader-span", StylishReaderSpan);
logger("initializeGeneralWebSite");
listenEventFromBackgroundScript();
listenEventFromOfficialWebsite();
Expand All @@ -20,4 +21,7 @@ export async function initializeGeneralWebSite() {
goThroughDomAndGenerateCustomElement(await getWordList());
createAudioTagForFloatingPanel();
// await injectPhraseFloatingPanelToShadowDom();
setInterval(async () => {
goThroughDomAndGenerateCustomElement(await getWordList());
}, 5000);
}
5 changes: 5 additions & 0 deletions src/plugins/general/stylishReaderSpan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class StylishReaderSpan extends HTMLElement {
constructor() {
super();
}
}
35 changes: 20 additions & 15 deletions src/plugins/general/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { backendServerUrl } from "../entryPoint/constants";
import { getLoginToken } from "../../background/background.utils";
import { backendServerUrl } from "../entryPoint/constants";
import { stylishReaderMainColor } from "../utils/constants";
import {
checkUserLoginStatus,
Expand Down Expand Up @@ -61,19 +61,21 @@ export function goThroughDomAndGenerateCustomElement(targetWordList) {

// 为所有高亮单词添加点击事件
document.querySelectorAll(`.${clickableWordClassName}`).forEach((e) => {
e.addEventListener("click", (e) => {
const newElement = e.cloneNode(true);
e.parentNode.replaceChild(newElement, e);
newElement.addEventListener("click", (e1) => {
hideFloatingIcon();
sendMessageFromGeneralScriptToFloatingPanel({
type: "search-word",
word: e.target.textContent,
word: e1.target.textContent,
});

sendMessageFromContentScriptToBackgroundScript("search-word", {
word: e.target.textContent,
word: e1.target.textContent,
});
sendMessageFromContentScriptToBackgroundScript(
"play-audio-from-floating-panel",
e.target.textContent.toString().trim()
e1.target.textContent.toString().trim()
);
});
});
Expand Down Expand Up @@ -122,7 +124,8 @@ function convertCurrentTextNodeContent(textNode, targetWordList) {
// 这段文本不包含目标单词
const stt = s + " ";
if (indexList.indexOf(index) > -1) {
const spanElement = document.createElement("span");
// const spanElement = document.createElement("span");
const spanElement = document.createElement("stylish-reader-span");
spanElement.textContent = stt;
spanElement.style.color = stylishReaderMainColor;
spanElement.classList = [clickableWordClassName];
Expand All @@ -133,16 +136,18 @@ function convertCurrentTextNodeContent(textNode, targetWordList) {
newNodeList.push(textNode);
}
});
/**
* FIXME: 这里再最外层添加了一个span元素,是有一些问题的,因为增加了一个原本dom中不存在的元素
* 有可能会改变原有dom的样式,这里最好是插入一个自定义的dom元素,这样不会改变原有dom的结构。
*/
const temporaryDivElement = document.createElement("span");

const temporaryCustomSpanElement = document.createElement(
"stylish-reader-span"
);
newNodeList.forEach((node) => {
temporaryDivElement.append(node);
temporaryCustomSpanElement.append(node);
});
if (!currentTextNodeParentNode.classList.contains(clickableWordClassName)) {
currentTextNodeParentNode.replaceChild(temporaryDivElement, textNode);
currentTextNodeParentNode.replaceChild(
temporaryCustomSpanElement,
textNode
);
}
}
}
Expand Down Expand Up @@ -305,7 +310,6 @@ function hideFloatingIcon() {
function calculateFloatingPanelPosition(targetElement) {
const x = targetElement.getBoundingClientRect().left;
const y = targetElement.getBoundingClientRect().top;
showTranslationFloatingPanelTemporary();
const floatingPanel = document.getElementById(
translationFloatingPanelShadowRootId
);
Expand Down Expand Up @@ -351,7 +355,6 @@ export async function showTranslationFloatingPanel(
);
translationPanel.style.display = "block";
if (source === "selection") {
showTranslationFloatingPanelTemporary();
let x = gSelectionPosition.x;
let y = gSelectionPosition.y;
translationPanel.style.top = y + "px";
Expand Down Expand Up @@ -711,6 +714,8 @@ function convertStringToLowerCaseAndRemoveSpecialCharacter(s) {
.replaceAll("!", "")
.replaceAll("'", "")
.replaceAll(":", "")
.replaceAll("’", "")
.replaceAll("'", "")
.replaceAll("?", "");
}

Expand Down
1 change: 1 addition & 0 deletions src/webPage/translationPanel/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function convertStringToLowerCaseAndRemoveSpecialCharacter(s: string) {
.replace(/\)/g, "")
.replace(/:/g, "")
.replace(/'/g, "")
.replace(/’/g, "")
.replace(/\?/g, "")
.replace(/!/g, "");
}
Expand Down