Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
numberOfCiters: 0,
scholarId: null,
}, refractoryPeriod);
break;
case SCHOLAR_REQUEST_TYPE_CITERS:
dispatchAndEcho({type: RESOLVE_SCHOLAR_CITERS_REQUEST}, refractoryPeriod);
break;
default:
console.error(`Unexpected Scholar request type ${state.scholar.requests[0].type}`);
dispatchAndEcho(null, refractoryPeriod);
break;
}
} else {
switch (state.scholar.requests[0].type) {
case SCHOLAR_REQUEST_TYPE_INITIALIZE: {
const publications = cssSelect(publicationsQuery, dom);
const candidates = [];
for (const publication of publications) {
const titleCandidates = cssSelect(titleFromPublicationQuery, publication);
if (
titleCandidates.length === 0
|| !titleCandidates[0].children
|| titleCandidates[0].children.length === 0
|| titleCandidates[0].children[0].type !== 'text'
) {
continue;
}
for (let citersLinkCandidate of cssSelect(citersLinkFromPublicationQuery, publication)) {
if (
citersLinkCandidate.children
&& citersLinkCandidate.children.length > 0
&& citersLinkCandidate.children[0].type === 'text'
break;
case SCHOLAR_REQUEST_TYPE_CITERS:
dispatchAndEcho({type: RESOLVE_SCHOLAR_CITERS_REQUEST}, refractoryPeriod);
break;
default:
console.error(`Unexpected Scholar request type ${state.scholar.requests[0].type}`);
dispatchAndEcho(null, refractoryPeriod);
break;
}
} else {
switch (state.scholar.requests[0].type) {
case SCHOLAR_REQUEST_TYPE_INITIALIZE: {
const publications = cssSelect(publicationsQuery, dom);
const candidates = [];
for (const publication of publications) {
const titleCandidates = cssSelect(titleFromPublicationQuery, publication);
if (
titleCandidates.length === 0
|| !titleCandidates[0].children
|| titleCandidates[0].children.length === 0
|| titleCandidates[0].children[0].type !== 'text'
) {
continue;
}
for (let citersLinkCandidate of cssSelect(citersLinkFromPublicationQuery, publication)) {
if (
citersLinkCandidate.children
&& citersLinkCandidate.children.length > 0
&& citersLinkCandidate.children[0].type === 'text'
&& citersLinkCandidate.attribs
&& citersLinkCandidate.attribs.href
) {
...candidate,
distance,
};
}
return best;
}, null);
dispatchAndEcho({
type: RESOLVE_SCHOLAR_INITIAL_REQUEST,
numberOfCiters: bestCandidate.numberOfCiters,
scholarId: bestCandidate.scholarId,
}, refractoryPeriod);
}
break;
}
case SCHOLAR_REQUEST_TYPE_CITERS: {
const publications = cssSelect(publicationsQuery, dom);
if (publications.length > 0) {
for (const publication of publications) {
const titleCandidates = cssSelect(titleFromPublicationQuery, publication);
if (
titleCandidates.length === 0
|| !titleCandidates[0].children
|| titleCandidates[0].children.length === 0
|| titleCandidates[0].children[0].type !== 'text'
) {
dispatch({
type: REJECT_SCHOLAR_CITER_PARSING,
doi: state.scholar.requests[0].doi,
title: `Parsing a citer's metadata for ${state.scholar.requests[0].doi} failed`,
subtitle: 'Tags with the class \'gs_rt\' and link children could not be found',
});
continue;
const state = getState();
const blocked = state.scholar.status === SCHOLAR_STATUS_BLOCKED_HIDDEN || state.scholar.status === SCHOLAR_STATUS_BLOCKED_VISIBLE;
if (
cssSelect(firstCategoryRecaptchaQuery, dom).length > 0
|| cssSelect(secondCategoryRecaptchaQuery, dom).length > 0
) {
if (!blocked) {
dispatch({
type: BLOCK_SCHOLAR,
url,
});
}
} else if (
decodeURIComponent(url) === 'https://ipv4.google.com/sorry/index'
|| (cssSelect(titleQuery, dom).length > 0
&& cssSelect(titleQuery, dom)[0].children
&& cssSelect(titleQuery, dom)[0].children[0].data === 'Sorry...'
)
) {
ipcRenderer.once('cookies-cleared', () => {
dispatchAndEcho({type: RESET_SCHOLAR}, 0);
});
ipcRenderer.send('clear-cookies');
} else {
const refractoryPeriod = Math.floor(
Math.random() * (1 + state.scholar.maximumRefractoryPeriod - state.scholar.minimumRefractoryPeriod)
) + state.scholar.minimumRefractoryPeriod;
if (!state.publications.has(state.scholar.requests[0].doi)) {
switch (state.scholar.requests[0].type) {
case SCHOLAR_REQUEST_TYPE_INITIALIZE:
dispatchAndEcho({
type: RESOLVE_SCHOLAR_INITIAL_REQUEST,
.then(dom => {
const state = getState();
const blocked = state.scholar.status === SCHOLAR_STATUS_BLOCKED_HIDDEN || state.scholar.status === SCHOLAR_STATUS_BLOCKED_VISIBLE;
if (
cssSelect(firstCategoryRecaptchaQuery, dom).length > 0
|| cssSelect(secondCategoryRecaptchaQuery, dom).length > 0
) {
if (!blocked) {
dispatch({
type: BLOCK_SCHOLAR,
url,
});
}
} else if (
decodeURIComponent(url) === 'https://ipv4.google.com/sorry/index'
|| (cssSelect(titleQuery, dom).length > 0
&& cssSelect(titleQuery, dom)[0].children
&& cssSelect(titleQuery, dom)[0].children[0].data === 'Sorry...'
)
) {
ipcRenderer.once('cookies-cleared', () => {
.then(dom => {
const state = getState();
const blocked = state.scholar.status === SCHOLAR_STATUS_BLOCKED_HIDDEN || state.scholar.status === SCHOLAR_STATUS_BLOCKED_VISIBLE;
if (
cssSelect(firstCategoryRecaptchaQuery, dom).length > 0
|| cssSelect(secondCategoryRecaptchaQuery, dom).length > 0
) {
if (!blocked) {
dispatch({
type: BLOCK_SCHOLAR,
url,
});
}
} else if (
decodeURIComponent(url) === 'https://ipv4.google.com/sorry/index'
|| (cssSelect(titleQuery, dom).length > 0
&& cssSelect(titleQuery, dom)[0].children
&& cssSelect(titleQuery, dom)[0].children[0].data === 'Sorry...'
)
) {
ipcRenderer.once('cookies-cleared', () => {
dispatchAndEcho({type: RESET_SCHOLAR}, 0);
});
ipcRenderer.send('clear-cookies');
} else {
const refractoryPeriod = Math.floor(
Math.random() * (1 + state.scholar.maximumRefractoryPeriod - state.scholar.minimumRefractoryPeriod)
) + state.scholar.minimumRefractoryPeriod;
if (!state.publications.has(state.scholar.requests[0].doi)) {
switch (state.scholar.requests[0].type) {
case SCHOLAR_REQUEST_TYPE_INITIALIZE:
dispatchAndEcho({
.then(dom => {
const state = getState();
const blocked = state.scholar.status === SCHOLAR_STATUS_BLOCKED_HIDDEN || state.scholar.status === SCHOLAR_STATUS_BLOCKED_VISIBLE;
if (
cssSelect(firstCategoryRecaptchaQuery, dom).length > 0
|| cssSelect(secondCategoryRecaptchaQuery, dom).length > 0
) {
if (!blocked) {
dispatch({
type: BLOCK_SCHOLAR,
url,
});
}
} else if (
decodeURIComponent(url) === 'https://ipv4.google.com/sorry/index'
|| (cssSelect(titleQuery, dom).length > 0
&& cssSelect(titleQuery, dom)[0].children
&& cssSelect(titleQuery, dom)[0].children[0].data === 'Sorry...'
)
) {
ipcRenderer.once('cookies-cleared', () => {
dispatchAndEcho({type: RESET_SCHOLAR}, 0);
function querySelectorAll(query: Query, elems: XmlAST | XmlAST[]): XmlAST[] {
return cssSelect(query, elems, cssSelectOpts);
}
const titleCandidates = cssSelect(titleFromPublicationQuery, publication);
if (
titleCandidates.length === 0
|| !titleCandidates[0].children
|| titleCandidates[0].children.length === 0
|| titleCandidates[0].children[0].type !== 'text'
) {
dispatch({
type: REJECT_SCHOLAR_CITER_PARSING,
doi: state.scholar.requests[0].doi,
title: `Parsing a citer's metadata for ${state.scholar.requests[0].doi} failed`,
subtitle: 'Tags with the class \'gs_rt\' and link children could not be found',
});
continue;
}
const metadataCandidates = cssSelect(metadataFromPublicationQuery, publication);
if (
metadataCandidates.length === 0
|| !metadataCandidates[0].children
) {
dispatch({
type: REJECT_SCHOLAR_CITER_PARSING,
doi: state.scholar.requests[0].doi,
title: `Parsing a citer's metadata for ${state.scholar.requests[0].doi} failed`,
subtitle: 'Tags with the class \'gs_a\' could not be found',
});
continue;
}
let metadata = '';
for (let child of metadataCandidates[0].children) {
if (child.type === 'text') {
metadata += child.data.replace(/ /g, ' ');