Function
forEachScript
($: CheerioAPI | string, callback: (script) => void, defaultReturn: any = null, selector = 'script[nonce][type="text/javascript"]')
Source from the content-addressed store, hash-verified
| 93 | } |
| 94 | |
| 95 | const forEachScript = ($: CheerioAPI | string, callback: (script) => void, defaultReturn: any = null, selector = 'script[nonce][type="text/javascript"]') => { |
| 96 | const scripts = typeof $ === 'string' ? [$] : $(selector).toArray(); |
| 97 | for (const script of scripts) { |
| 98 | try { |
| 99 | callback(script); |
| 100 | } catch (error) { |
| 101 | if (error instanceof LoopReturn) { |
| 102 | return error.to_return; |
| 103 | } |
| 104 | if (error instanceof LoopContinue) { |
| 105 | continue; |
| 106 | } |
| 107 | throw error; |
| 108 | } |
| 109 | } |
| 110 | return defaultReturn; |
| 111 | }; |
| 112 | |
| 113 | // view-source a *_SHARE_PAGE type article and search for `ITEM_SHOW_TYPE_MAP` |
| 114 | // Please update the comments below if you find new types or new examples |
Tested by
no test coverage detected