添加:文本选择模式下,点击恢复功能
This commit is contained in:
40
content.js
40
content.js
@@ -166,6 +166,11 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// 避免点击已模糊的文本段落时触发(这些段落有自己的点击事件)
|
||||
if (e.target.classList.contains('blurtext-selection-wrapped')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const selection = window.getSelection();
|
||||
const selectedText = selection.toString().trim();
|
||||
|
||||
@@ -229,6 +234,15 @@
|
||||
const span = document.createElement('span');
|
||||
span.className = 'blurtext-blurred blurtext-selection-wrapped';
|
||||
span.style.setProperty('--blur-intensity', `${blurIntensity}px`);
|
||||
span.style.cursor = 'pointer';
|
||||
span.title = '点击恢复此段文本';
|
||||
|
||||
// 添加点击事件,允许单独恢复
|
||||
span.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
unblurSelectionSpan(span);
|
||||
});
|
||||
|
||||
// 包裹选中的内容
|
||||
range.surroundContents(span);
|
||||
@@ -245,7 +259,7 @@
|
||||
hideBlurButton();
|
||||
|
||||
// 显示提示
|
||||
showHint('文本已模糊', 2000);
|
||||
showHint('文本已模糊(点击可单独恢复)', 2000);
|
||||
} catch (error) {
|
||||
console.error('[BlurText] Error blurring selection:', error);
|
||||
showHint('无法模糊该选区(可能包含复杂的HTML结构)', 3000);
|
||||
@@ -253,6 +267,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 恢复单个选择模式的模糊段落
|
||||
function unblurSelectionSpan(span) {
|
||||
if (!span || !span.parentNode) return;
|
||||
|
||||
console.log('[BlurText] Unblurring selection span');
|
||||
|
||||
// 从集合中移除
|
||||
blurredElements.delete(span);
|
||||
|
||||
// 获取 span 的内容
|
||||
const fragment = document.createDocumentFragment();
|
||||
while (span.firstChild) {
|
||||
fragment.appendChild(span.firstChild);
|
||||
}
|
||||
|
||||
// 用原内容替换 span
|
||||
span.parentNode.replaceChild(fragment, span);
|
||||
|
||||
// 显示提示
|
||||
showHint('已恢复此段文本', 1500);
|
||||
|
||||
console.log('[BlurText] Selection span removed, remaining elements:', blurredElements.size);
|
||||
}
|
||||
|
||||
// 鼠标悬停高亮
|
||||
function handleMouseOver(e) {
|
||||
if (!isBlurMode || blurMode !== 'element') return;
|
||||
|
||||
Reference in New Issue
Block a user