Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nto dev
  • Loading branch information
MengNianxiaoyao committed Apr 29, 2024
2 parents 87a00b7 + beff7d0 commit 00a8e14
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
25 changes: 0 additions & 25 deletions assets/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,5 @@
"resourceTypes": ["xmlhttprequest"],
"requestMethods": ["post"]
}
},
{
"id": 3,
"priority": 2,
"action": {
"type": "modifyHeaders",
"requestHeaders": [
{
"header": "origin",
"operation": "set",
"value": "https://t.bilibili.com"
},
{
"header": "referer",
"operation": "set",
"value": "https://t.bilibili.com"
}
]
},
"condition": {
"domainType": "thirdParty",
"urlFilter": "||api.bilibili.com",
"resourceTypes": ["xmlhttprequest"],
"initiatorDomains": ["t.bilibili.com"]
}
}
]
25 changes: 23 additions & 2 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
import browser from 'webextension-polyfill'

// import { onMessage, sendMessage } from 'webext-bridge'
import { setupAllMsgLstnrs } from './messageListeners'

browser.runtime.onInstalled.addListener((): void => {
// eslint-disable-next-line no-console
console.log('Extension installed')
})

// eslint-disable-next-line node/prefer-global/process
if (process.env.FIREFOX) {
browser.webRequest.onBeforeSendHeaders.addListener(
(details) => {
const requestHeaders: browser.WebRequest.HttpHeaders = []
if (details.documentUrl) {
const url = new URL(details.documentUrl)
details.requestHeaders = details.requestHeaders || []
for (let i = 0; i < details.requestHeaders.length; i++) {
if (details.requestHeaders[i].name.toLowerCase() === 'origin' || details.requestHeaders[i].name.toLowerCase() === 'referer')
requestHeaders.push({ name: details.requestHeaders[i].name, value: url.origin })
else
requestHeaders.push(details.requestHeaders[i])
}

return { ...details, requestHeaders }
}
},
{ urls: ['<all_urls>'] },
['blocking', 'requestHeaders'],
)
}

// Setup all message listeners
setupAllMsgLstnrs()
3 changes: 2 additions & 1 deletion src/contentScripts/views/Home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useMainStore } from '~/stores/mainStore'
const mainStore = useMainStore()
const { handleBackToTop, scrollbarRef } = useBewlyApp()
const { getBewlyImage } = useBewlyImage()
const activatedPage = ref<HomeSubPage>(HomeSubPage.ForYou)
const pages = {
Expand Down Expand Up @@ -144,7 +145,7 @@ function toggleTabContentLoading(loading: boolean) {
pos="absolute left-0 top-0" w-full h-inherit bg="cover center" z-1
pointer-events-none
:style="{
backgroundImage: `url(${settings.searchPageWallpaper})`,
backgroundImage: `url(${getBewlyImage(settings.searchPageWallpaper)})`,
backgroundAttachment: settings.searchPageModeWallpaperFixed ? 'fixed' : 'unset',
}"
/>
Expand Down
23 changes: 16 additions & 7 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export async function getManifest() {
'storage',
'scripting',
'declarativeNetRequest',
...isFirefox
? ['webRequest', 'webRequestBlocking']
: [],
],
host_permissions: [
'*://*.bilibili.com/*',
Expand Down Expand Up @@ -67,13 +70,19 @@ export async function getManifest() {
? `script-src 'self' http://localhost:${port}; object-src 'self' http://localhost:${port}`
: 'script-src \'self\'; object-src \'self\'',
},
declarative_net_request: {
rule_resources: [{
id: 'ruleset_1',
enabled: true,
path: 'assets/rules.json',
}],
},
...isFirefox
? {}
: {
declarative_net_request: {
rule_resources: [
{
id: 'ruleset_1',
enabled: true,
path: 'assets/rules.json',
},
],
},
},
}

if (isDev)
Expand Down
1 change: 1 addition & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineConfig(() => ({
define: {
'__DEV__': JSON.stringify(isDev),
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
'process.env.FIREFOX': isFirefox ? 'true' : 'false',
},
platform: 'browser',
minifyWhitespace: !isDev,
Expand Down

0 comments on commit 00a8e14

Please sign in to comment.