chore: lint

This commit is contained in:
karishmas6
2024-08-12 05:30:57 +05:30
parent 871d4fd48a
commit 196cfd4cca

View File

@@ -279,7 +279,7 @@ async function scrollDownToLoadMore(selector, limit) {
* @returns {Array.<Array.<Object>>} Array of arrays of scraped items, one sub-array per list * @returns {Array.<Array.<Object>>} Array of arrays of scraped items, one sub-array per list
*/ */
window.scrapeList = async function (config) { window.scrapeList = async function (config) {
const { listSelector, fields, limit, flexible = false, pagination } = config; const { listSelector, fields, limit, flexible = false, pagination } = config;
const lists = Array.from(document.querySelectorAll(listSelector)); const lists = Array.from(document.querySelectorAll(listSelector));
@@ -364,44 +364,44 @@ async function scrollDownToLoadMore(selector, limit) {
* @param {string} listSelector - Selector for the list container(s) * @param {string} listSelector - Selector for the list container(s)
* @returns {Array.<Object>} Array of objects, each containing the CSS selector and innerText of the children * @returns {Array.<Object>} Array of objects, each containing the CSS selector and innerText of the children
*/ */
window.scrapeListAuto = function (listSelector) { window.scrapeListAuto = function (listSelector) {
const lists = Array.from(document.querySelectorAll(listSelector)); const lists = Array.from(document.querySelectorAll(listSelector));
const results = []; const results = [];
lists.forEach(list => { lists.forEach(list => {
const children = Array.from(list.children); const children = Array.from(list.children);
children.forEach(child => { children.forEach(child => {
const selectors = []; const selectors = [];
let element = child; let element = child;
// Traverse up to gather the CSS selector for the element // Traverse up to gather the CSS selector for the element
while (element && element !== document) { while (element && element !== document) {
let selector = element.nodeName.toLowerCase(); let selector = element.nodeName.toLowerCase();
if (element.id) { if (element.id) {
selector += `#${element.id}`; selector += `#${element.id}`;
selectors.push(selector); selectors.push(selector);
break; break;
} else { } else {
const className = element.className.trim().split(/\s+/).join('.'); const className = element.className.trim().split(/\s+/).join('.');
if (className) { if (className) {
selector += `.${className}`; selector += `.${className}`;
}
selectors.push(selector);
element = element.parentElement;
} }
selectors.push(selector);
element = element.parentElement;
} }
}
results.push({ results.push({
selector: selectors.reverse().join(' > '), selector: selectors.reverse().join(' > '),
innerText: child.innerText.trim() innerText: child.innerText.trim()
});
}); });
}); });
});
return results; return results;
}; };
})(window); })(window);