diff --git a/package.json b/package.json index 075c5bb..77c0b05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "popupsearch", - "version": "3.1.5", + "version": "3.1.6", "description": "Chrome extension for searching", "author": "q@eqw.me", "scripts": { diff --git a/src/manifest.json b/src/manifest.json index e2797f3..383c356 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "name": "PopupSearch", "description": "Chrome extension for searching in googleâ„¢ using popup window with keyboard navigation support", - "version": "3.1.5", + "version": "3.1.6", "manifest_version": 2, "icons": { "48": "icons/icon_48.png", diff --git a/src/popup/search/googleHTML.js b/src/popup/search/googleHTML.js index d33fab4..08e2d65 100644 --- a/src/popup/search/googleHTML.js +++ b/src/popup/search/googleHTML.js @@ -60,10 +60,19 @@ export default async function(query, start) { if (!$input) { return Promise.reject(_.extend(new Error('Parsing error'), {url: newUrl})); } + $body.find('div.g').each(function(resultIdx) { + const $this = $(this); + if ($this.parents('div.g').length > 0) { + return; + } + $this.find('div.g').each(function(resultIdx) { + $(this).addClass('subresult'); + $(this).insertBefore($this); + }) + }); $body.find('div.g').each(function(resultIdx) { const $this = $(this); - console.log($this.html()); if ($this.parents('div.g').length > 0) { return; } @@ -103,6 +112,10 @@ export default async function(query, start) { } return false; }); + if (!linkElem) { + linkElem = $this.find('a[href]').eq(0); + item.href = linkElem.attr('href'); + } if (!linkElem) { console.warn('no link elem', resultIdx); return; @@ -144,7 +157,6 @@ export default async function(query, start) { $this.find('div > div').each(function() { if ($(this)[0].classList.length >= 4) { let $parent = $(this).parent(); - console.log($parent[0].classList.length, validateTextContainer($(this)[0])); if ($parent[0].classList.length === 1 && validateTextContainer($(this)[0])) { $descElem = $(this); return false; @@ -152,11 +164,14 @@ export default async function(query, start) { } }); } + if (!$descElem || $descElem.length === 0) { + $descElem = $this.find('span[style*="webkit-line-clamp') + } if (!$descElem || $descElem.length === 0) { $descElem = $this.find('span:last-of-type'); } let $sublinksInlineElem = undefined; - + if (item.href) { let itemHrefHost; try { @@ -197,16 +212,7 @@ export default async function(query, start) { item.link = item.href; } - if ($sublinksInlineElem) { - $sublinksInlineElem.find('a').each(function() { - removeUnwantedTags($(this)); - item.subLinkList.push({ - href: $(this).attr('href'), - title: _.trim($(this).text()), - }); - $(this).remove(); - }); - } else if ($this.find('table').length > 0) { + if ($this.find('table').length > 0) { let $sublinksTable = $this.find('table'); $sublinksTable.find('tr').last().remove(); $sublinksTable.find('td').each(function() { @@ -253,6 +259,15 @@ export default async function(query, start) { }); $(this).remove(); }); + } else if ($sublinksInlineElem) { + $sublinksInlineElem.find('a').each(function() { + removeUnwantedTags($(this)); + item.subLinkList.push({ + href: $(this).attr('href'), + title: _.trim($(this).text()), + }); + $(this).remove(); + }); } if (($descElem.length === 0 || $descElem.text().trim().length === 0) && $this.find('div.g').length > 0) { console.log('is featured snippet', resultIdx); @@ -305,11 +320,13 @@ export default async function(query, start) { if (item.href && item.title) { res.links.push(item) } - }) + }); - if ($body.find('td.b a span').last().text() === 'Next') { - res.startNext = start + res.links.length; - } + $($body.find('td a span').get().reverse()).each(function() { + if ($(this).text() === 'Next') { + res.startNext = start + res.links.length; + } + }); return res; };