Skip to content

Commit

Permalink
v3.1.6 update google parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ik9999 committed Oct 2, 2021
1 parent 79184a6 commit 21f1e95
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "popupsearch",
"version": "3.1.5",
"version": "3.1.6",
"description": "Chrome extension for searching",
"author": "[email protected]",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
51 changes: 34 additions & 17 deletions src/popup/search/googleHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -144,19 +157,21 @@ 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;
}
}
});
}
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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
};

0 comments on commit 21f1e95

Please sign in to comment.