diff --git a/src/sites.ts b/src/sites.ts index 2536eaa..c71c81c 100644 --- a/src/sites.ts +++ b/src/sites.ts @@ -4,8 +4,11 @@ import { PartialSite, Sites } from './types.js' const extractQuery = (node: HTMLElement) => createQuery(node.innerText) const createQuery = (text: string) => { - const query = text.split(' ').slice(2, 15).join(' ') - return query + const wordsInNgram = 5 + const maxCountOfNgrams = 5 + const textArr = text.split(' ') + const search = textArr.map((word, wordIndex) => (wordIndex + wordsInNgram <= textArr.length) && (wordIndex < maxCountOfNgrams) && textArr.slice(wordIndex, wordIndex + wordsInNgram).join(' ')) + return search.filter(search => search).map(search => `"${search}"`).join(' OR ') || text.split(' ').slice(2, 15).join(' ') } const makeQueryFunc = (selector: string) => { return (node) => extractQuery(node.querySelector(selector))