()
| 22 | protected chibi!: permissionElement[]; |
| 23 | |
| 24 | public async init() { |
| 25 | const manifest = chrome.runtime.getManifest(); |
| 26 | |
| 27 | const required: tempPermissionElement = { |
| 28 | name: 'required', |
| 29 | match: [], |
| 30 | api: manifest.host_permissions.filter(el => el !== '<all_urls>'), |
| 31 | }; |
| 32 | |
| 33 | const player: tempPermissionElement = { |
| 34 | name: 'player', |
| 35 | match: [], |
| 36 | api: [], |
| 37 | }; |
| 38 | |
| 39 | const pages: tempPermissionElement[] = []; |
| 40 | |
| 41 | manifest.content_scripts!.forEach(page => { |
| 42 | if (page.matches) { |
| 43 | const obj: tempPermissionElement = { |
| 44 | match: page.matches, |
| 45 | }; |
| 46 | |
| 47 | const script = page.js?.find(e => /content\/page_/.test(e) || e.includes('iframe.js')); |
| 48 | |
| 49 | if (!script) { |
| 50 | required.match = required.match.concat(obj.match); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | if (script.includes('iframe.js')) { |
| 55 | player.match = player.match.concat(page.matches); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | obj.name = script.replace(/^.*content\/page_/, '').replace('.js', ''); |
| 60 | |
| 61 | pages.push(obj); |
| 62 | } |
| 63 | }); |
| 64 | |
| 65 | let chibi: tempPermissionElement[] = []; |
| 66 | try { |
| 67 | const chibiRepo = await (await ChibiListRepository.getInstance()).init(); |
| 68 | chibi = chibiRepo.getPermissionsElements(); |
| 69 | } catch (e) { |
| 70 | con.error('Failed to load chibi permissions', e); |
| 71 | } |
| 72 | |
| 73 | const activePermissions = await chrome.permissions.getAll(); |
| 74 | |
| 75 | this.required = await this.testPermission(required, activePermissions); |
| 76 | this.player = await this.testPermission(player, activePermissions); |
| 77 | this.pages = await Promise.all(pages.map(page => this.testPermission(page, activePermissions))); |
| 78 | this.chibi = await Promise.all(chibi.map(page => this.testPermission(page, activePermissions))); |
| 79 | |
| 80 | return this; |
| 81 | } |
no test coverage detected