refactoring
This commit is contained in:
		
							
								
								
									
										68
									
								
								scripts/background/signiture.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								scripts/background/signiture.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,68 @@ | ||||
| const signitures = ` | ||||
| ## Usage | ||||
| new Extractor().task(...args).task(...args).start(); | ||||
|  | ||||
| ## Extractor.task() Signitures: | ||||
| function(itemsSelector:string, fieldSelectors:string[]) | ||||
| function(itemsSelector:string, fieldSelectors:string[], url:string, from:number, to:number, interval:number) | ||||
| function(itemsSelector:string, fieldSelectors:string[], url:string, pages:number[]) | ||||
| function(itemsSelector:string, fieldSelectors:string[], urls:string[]) | ||||
|  | ||||
| ## Example: | ||||
| // extract all links text & url under '.item' elements | ||||
| // use 'selector@attr' to get attribute of the field elements | ||||
| new Extractor().task(".item", ["a", "a@href"]).start(); | ||||
|  | ||||
| ## See Detailed Help: | ||||
| https://git.jebbs.co/jebbs/data-extracter-extesion | ||||
| `.trim(); | ||||
|  | ||||
| function testArgs(...args) { | ||||
|     switch (args.length) { | ||||
|         case 0, 1: | ||||
|             return false; | ||||
|         case 2: | ||||
|             return args[0] && args[1] && | ||||
|                 (typeof args[0] == "string") && | ||||
|                 (args[1] instanceof Array) && | ||||
|                 testArrayVals(args[1], v => typeof v == "string"); | ||||
|         case 3: | ||||
|             return args[0] && args[1] && | ||||
|                 typeof args[0] == "string" && | ||||
|                 args[1] instanceof Array && | ||||
|                 testArrayVals(args[1], v => typeof v == "string") && | ||||
|                 ( | ||||
|                     ( | ||||
|                         args[2] instanceof Array && | ||||
|                         testArrayVals(args[2], v => typeof v == "string") | ||||
|                     ) || ( | ||||
|                         args[2] instanceof ExtractResult | ||||
|                     ) | ||||
|                 ); | ||||
|         case 4: | ||||
|             return args[0] && args[1] && | ||||
|                 typeof args[0] == "string" && | ||||
|                 args[1] instanceof Array && | ||||
|                 testArrayVals(args[1], v => typeof v == "string") && | ||||
|                 typeof args[2] == "string" && | ||||
|                 args[3] instanceof Array && | ||||
|                 testArrayVals(args[3], v => typeof v == "number"); | ||||
|         case 6: | ||||
|             return args[0] && args[1] && | ||||
|                 typeof args[0] == "string" && | ||||
|                 args[1] instanceof Array && | ||||
|                 testArrayVals(args[1], v => typeof v == "string") && | ||||
|                 typeof args[2] == "string" && | ||||
|                 !isNaN(args[3]) && !isNaN(args[4]) && !isNaN(args[5]); | ||||
|         default: | ||||
|             return false; | ||||
|     } | ||||
|  | ||||
|     function testArrayVals(arr, tester) { | ||||
|         return arr.reduce((p, c) => p && tester(c), true); | ||||
|     } | ||||
| } | ||||
|  | ||||
| function argsToString(...args) { | ||||
|     return args.map(v => (v instanceof Array ? `[${v.join(', ')}]` : v.toString())).join(', '); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user