-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#65] Parse creator information on offcanvas
DOMParser is not available anymore in MV3 Conditionally use the old way or the offscreen page (which calls old fn)
- Loading branch information
Showing
8 changed files
with
136 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!doctype html> | ||
<script src="scripts/offscreen.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import browser from 'webextension-polyfill'; | ||
import { getInformation } from './page/offscreen'; | ||
|
||
browser.runtime.onMessage.addListener(async (message: { [key: string]: any; }) => { | ||
if (message.target !== 'offscreen') { | ||
return false; | ||
} | ||
console.dev.log('Received message for offcanvas', message); | ||
switch (message.type) { | ||
case 'getCreatorInformation': { | ||
const data = await getInformation(); | ||
await browser.runtime.sendMessage({ | ||
type: 'receiveCreatorInformation', | ||
target: 'background', | ||
data | ||
}); | ||
} break; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const getInformation = async () => { | ||
const res = await fetch('https://talent.nebula.tv/creators/'); | ||
const body = await res.text(); | ||
const parser = new DOMParser(); | ||
const doc = parser.parseFromString(body, 'text/html'); | ||
return Array.from(doc.querySelectorAll('#creator-wall .youtube-creator')).map(c => ({ | ||
name: c.querySelector('img').alt, | ||
nebula: c.querySelector<HTMLAnchorElement>('.link.nebula')?.href?.split('/')?.pop(), | ||
nebulaAlt: new URL(c.querySelector<HTMLAnchorElement>('h3 a').href).pathname.split('/')[1], | ||
channel: c.getAttribute('data-video'), | ||
uploads: c.getAttribute('data-video') ? 'UU' + c.getAttribute('data-video').substring(2) : undefined, | ||
})); | ||
}; |