-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7af1a8c
commit a1ace1e
Showing
6 changed files
with
87 additions
and
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function removeHighlightFromSelection() { | ||
const selection = window.getSelection(); | ||
// 檢查是否有選取範圍 | ||
if (!selection.rangeCount) return; | ||
const range = selection.getRangeAt(0); | ||
const container = range.commonAncestorContainer; | ||
// 確保範圍是在一個元素內部 | ||
const parentElement = container.nodeType === 3 ? container.parentNode : container; | ||
|
||
// 查找所有的 highlight divs | ||
const highlights = parentElement.parentNode.querySelectorAll('div.highlight_underline, div.highlight_yellow, div.highlight_green, div.highlight_blue, div.highlight_pink'); | ||
|
||
// 移除每個 highlight div 的外部 HTML | ||
highlights.forEach(highlight => { | ||
highlight.outerHTML = highlight.innerHTML; | ||
}); | ||
} | ||
|
||
// 綁定一個按鈕來觸發這個函數 | ||
removeHighlightFromSelection(); |
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