url list support
This commit is contained in:
@ -44,6 +44,7 @@ function extract(...args) {
|
||||
function extract(itemsSelector:string, fieldSelectors:string[])
|
||||
function extract(itemsSelector:string, fieldSelectors:string[], url:string, from:number, to:number, interval:number)
|
||||
function extract(itemsSelector:string, fieldSelectors:string, url:string, pages:number[])
|
||||
function extract(itemsSelector:string, fieldSelectors:string[], urls:string[])
|
||||
|
||||
## Examples:
|
||||
----------------------------
|
||||
|
||||
@ -2,20 +2,23 @@
|
||||
* Extract data from current tab / multiple urls.
|
||||
* @param {string} itemsSelector items selectors for selecting items (data rows)
|
||||
* @param {Array<string>} fieldSelectors fields selectors for selecting fields (data columns) under each item
|
||||
* @param {string} url url template to generate urls by filling with page numers.
|
||||
* @param {...number} args page numers, either [from, to, interval] or [...pages]
|
||||
* @param {...any} args url list / url templates, page numers, either [from, to, interval] or [...pages]
|
||||
*/
|
||||
function extract(itemsSelector, fieldSelectors, url, ...args) {
|
||||
function extract(itemsSelector, fieldSelectors, ...args) {
|
||||
let urls = [];
|
||||
if (url) {
|
||||
let listOrTempl = args.shift();
|
||||
if (listOrTempl instanceof Array) {
|
||||
urls = listOrTempl;
|
||||
} else if (url) {
|
||||
let urlTempl = listOrTempl;
|
||||
if (args[0] instanceof Array) {
|
||||
urls = args[0].map(p => url.replace("${page}", p));
|
||||
urls = args[0].map(p => urlTempl.replace("${page}", p));
|
||||
} else if (args.length >= 3) {
|
||||
let from = args.shift();
|
||||
let to = args.shift();
|
||||
let interval = args.shift();
|
||||
for (let i = from; i <= to; i += interval) {
|
||||
urls.push(url.replace("${page}", i));
|
||||
urls.push(urlTempl.replace("${page}", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user