MCPcopy Index your code
hub / github.com/XIU2/UserScript / getSelectedBlockKeywordText

Function getSelectedBlockKeywordText

Zhihu-Enhanced.user.js:855–865  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

853
854// 读取当前选中的文字,兼容输入框和普通页面选区
855function 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// 记录最近一次选中的文字,供右键脚本菜单 [添加选中文字到屏蔽词] 使用
868function rememberSelectedBlockKeyword() {

Callers 2

Calls 1

Tested by

no test coverage detected