()
| 853 | |
| 854 | // 读取当前选中的文字,兼容输入框和普通页面选区 |
| 855 | function getSelectedBlockKeywordText() { |
| 856 | let text = ''; |
| 857 | const activeElement = document.activeElement; |
| 858 | if (activeElement && ((activeElement.tagName === 'TEXTAREA') || (activeElement.tagName === 'INPUT' && /^(?:text|search|url|tel|password)$/i.test(activeElement.type))) && typeof activeElement.selectionStart === 'number') { |
| 859 | text = activeElement.value.slice(activeElement.selectionStart, activeElement.selectionEnd); |
| 860 | } |
| 861 | if (!text && window.getSelection) { |
| 862 | text = window.getSelection().toString(); |
| 863 | } |
| 864 | return normalizeBlockKeywordText(text); |
| 865 | } |
| 866 | |
| 867 | // 记录最近一次选中的文字,供右键脚本菜单 [添加选中文字到屏蔽词] 使用 |
| 868 | function rememberSelectedBlockKeyword() { |
no test coverage detected