mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
73 lines
2.6 KiB
TypeScript
73 lines
2.6 KiB
TypeScript
// import { onMessage } from 'webext-bridge'
|
|
import { createApp } from 'vue'
|
|
import type { App as AppType } from 'vue'
|
|
import App from './views/App.vue'
|
|
import { setupApp } from '~/logic/common-setup'
|
|
import { i18n } from '~/utils/i18n'
|
|
import { SVG_ICONS } from '~/utils/svgIcons'
|
|
|
|
let app: AppType | null = null;
|
|
|
|
// Firefox `browser.tabs.executeScript()` requires scripts return a primitive value
|
|
(() => {
|
|
// console.info('[vitesse-webext] Hello world from content script')
|
|
|
|
// // communication example: send previous tab title from background page
|
|
// onMessage('tab-prev', ({ data }) => {
|
|
// console.log(`[vitesse-webext] Navigate from page "${data.title}"`)
|
|
// })
|
|
|
|
const currentUrl = document.URL
|
|
|
|
if (
|
|
/https?:\/\/bilibili.com\/?$/.test(currentUrl)
|
|
|| /https?:\/\/www.bilibili.com\/?$/.test(currentUrl)
|
|
|| /https?:\/\/www.bilibili.com\/index.html$/.test(currentUrl)
|
|
|| /https?:\/\/bilibili.com\/\?spm_id_from=.*/.test(currentUrl)
|
|
|| /https?:\/\/www.bilibili.com\/\?spm_id_from=(.)*/.test(currentUrl)
|
|
// || /https?:\/\/(www.)?bilibili.com\/video\/.*/.test(currentUrl)
|
|
) {
|
|
const originalPageContent = document.querySelector('#i_cecream')
|
|
if (originalPageContent)
|
|
originalPageContent.innerHTML = ''
|
|
|
|
// mount component to context window
|
|
const container = document.createElement('div')
|
|
container.id = 'bewly'
|
|
const root = document.createElement('div')
|
|
const styleEl = document.createElement('link')
|
|
const shadowDOM = container.attachShadow?.({ mode: __DEV__ ? 'open' : 'closed' }) || container
|
|
styleEl.setAttribute('rel', 'stylesheet')
|
|
styleEl.setAttribute('href', browser.runtime.getURL('dist/contentScripts/style.css'))
|
|
shadowDOM.appendChild(styleEl)
|
|
shadowDOM.appendChild(root)
|
|
|
|
// inject svg icons
|
|
const svgDiv = document.createElement('div')
|
|
svgDiv.innerHTML = SVG_ICONS
|
|
shadowDOM.appendChild(svgDiv)
|
|
|
|
document.body.appendChild(container)
|
|
app = createApp(App)
|
|
setupApp(app)
|
|
app.use(i18n).mount(root)
|
|
}
|
|
else if (/https?:\/\/(www.)?bilibili.com\/video\/.*/.test(currentUrl)) {
|
|
const container = document.createElement('div')
|
|
const root = document.createElement('div')
|
|
const styleEl = document.createElement('link')
|
|
styleEl.setAttribute('rel', 'stylesheet')
|
|
styleEl.setAttribute('href', browser.runtime.getURL('dist/contentScripts/style.css'))
|
|
container.id = 'bewly'
|
|
container.appendChild(styleEl)
|
|
container.appendChild(root)
|
|
document.body.appendChild(container)
|
|
|
|
const app = createApp(App)
|
|
setupApp(app)
|
|
app.use(i18n).mount(root)
|
|
}
|
|
})()
|
|
|
|
export default app as AppType
|