1+ import { checkBreakLineHappened } from './checkBreakLineHappened' ;
12import { getPriority } from './getPriority' ;
23import { state } from './state' ;
34import { ignoreHref , isChinese , isUrl , queryWS , formatTranslation } from '@extension/shared' ;
@@ -11,55 +12,8 @@ const checkingTypeUpper = checkingTypeLower.map(item => item.toUpperCase());
1112const checkingTypes = checkingTypeLower . concat ( checkingTypeUpper ) ;
1213let tick = 0 ;
1314
14- const forceBreakLineTags = [ 'ul' , 'ol' , 'li' ] ;
15- const forceBreakLineTagsUpper = forceBreakLineTags . map ( item => item . toUpperCase ( ) ) ;
16-
17- const checkBreakLineHappened = ( node : HTMLElement ) => {
18- const computedStyle = window . getComputedStyle ( node ) ;
19- if ( computedStyle . display === 'none' || computedStyle . visibility === 'hidden' || computedStyle . opacity === '0' ) {
20- return false ;
21- }
22-
23- if ( forceBreakLineTagsUpper . includes ( node . nodeName ) || forceBreakLineTags . includes ( node . nodeName ) ) {
24- return true ;
25- }
26-
27- // 获取文本内容
28- const textContent = node . textContent ?. trim ( ) ;
29- if ( ! textContent ) return false ;
30-
31- // 方法1: 检查 white-space 属性
32- if ( computedStyle . whiteSpace === 'nowrap' ) {
33- return false ; // 强制不换行,所以没有折行
34- }
35-
36- // 方法2: 检查元素高度是否大于行高
37- const lineHeight = parseFloat ( computedStyle . lineHeight ) || parseFloat ( computedStyle . fontSize ) * 1.2 ;
38- const elementHeight = node . offsetHeight ;
39-
40- // 如果元素高度明显大于行高,说明发生了折行
41- if ( elementHeight > lineHeight * 1.5 ) {
42- return true ;
43- }
44-
45- // 方法3: 检查是否有换行符
46- if ( textContent . includes ( '\n' ) || textContent . includes ( '\r' ) ) {
47- return true ;
48- }
49-
50- // 方法4: 检查文本长度和容器宽度的比例
51- const elementWidth = node . offsetWidth ;
52- const fontSize = parseFloat ( computedStyle . fontSize ) ;
53- const estimatedCharWidth = fontSize * 0.6 ; // 估算每个字符的平均宽度
54- const estimatedTextWidth = textContent . length * estimatedCharWidth ;
55-
56- // 如果估算的文本宽度明显大于容器宽度,很可能发生折行
57- if ( estimatedTextWidth > elementWidth * 1.2 ) {
58- return true ;
59- }
60-
61- return false ;
62- } ;
15+ export const forceBreakLineTags = [ 'ul' , 'ol' , 'li' ] ;
16+ export const forceBreakLineTagsUpper = forceBreakLineTags . map ( item => item . toUpperCase ( ) ) ;
6317
6418export const handleNode = ( _node : Node ) : boolean => {
6519 const currentUrl = window . location . href ;
0 commit comments