You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
973 B
41 lines
973 B
'use strict'; |
|
|
|
// Selectors for assistant replies in DeepSeek chat. |
|
// Fallback hierarchy: from specific to generic. Order matters. |
|
const MESSAGE_SELECTORS = [ |
|
'.ds-markdown', |
|
'[class="markdown"]', |
|
'[data-testid="message"]', |
|
'[class*="message"]' |
|
]; |
|
|
|
// Collect text leaf nodes only (no nested blocks). |
|
// Join with LF to keep paragraph separators. |
|
function collectText(root) { |
|
if (!root) return ''; |
|
const parts = []; |
|
const walk = function (n) { |
|
if (!n) return; |
|
if (n.nodeType === 3) { |
|
const t = (n.nodeValue || '').trim(); |
|
if (t.length > 0) parts.push(t); |
|
return; |
|
} |
|
const kids = n.childNodes; |
|
if (!kids) return; |
|
for (let i = 0; i < kids.length; i++) walk(kids[i]); |
|
}; |
|
walk(root); |
|
return parts.join(String.fromCharCode(10)); |
|
}; |
|
|
|
const DSH_SELECTORS = { |
|
MESSAGE_SELECTORS: MESSAGE_SELECTORS, |
|
collectText: collectText |
|
}; |
|
|
|
globalThis.DSH_SELECTORS = DSH_SELECTORS; |
|
|
|
if (typeof module !== 'undefined' && module.exports) { |
|
module.exports = DSH_SELECTORS; |
|
}
|
|
|