Skip to content

Commit

Permalink
feat: adjust <a> tag link targe attribute
Browse files Browse the repository at this point in the history
When open the homepage, top bar links should open in a new tab; when not on the homepage, they should open in the same page
  • Loading branch information
hakadao committed Jan 9, 2024
1 parent 56c8380 commit 770c806
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/components/TopBar/components/ChannelsPop.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { isHomePage } from '~/utils/main'
const { t } = useI18n()
Expand Down Expand Up @@ -62,6 +63,7 @@ const genres = [
>
<a
:href="genre.href"
:target="isHomePage() ? '_blank' : '_self'"
flex="~"
items="center"
w="170px"
Expand Down
4 changes: 2 additions & 2 deletions src/components/TopBar/components/MorePop.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { getUserID } from '~/utils/main'
import { getUserID, isHomePage } from '~/utils/main'
const { t } = useI18n()
Expand All @@ -26,7 +26,7 @@ const list = [
v-for="item in list"
:key="item.name"
:href="item.url"
target="_blank"
:target="isHomePage() ? '_blank' : '_self'"
pos="relative"
p="x-4 y-2"
bg="hover:$bew-fill-2"
Expand Down
3 changes: 2 additions & 1 deletion src/components/TopBar/components/NotificationsPop.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { isHomePage } from '~/utils/main'
const { t } = useI18n()
Expand Down Expand Up @@ -82,7 +83,7 @@ function getUnreadMessageCount() {
v-for="item in list"
:key="item.name"
:href="item.url"
target="_blank"
:target="isHomePage() ? '_blank' : '_self'"
pos="relative"
p="x-4 y-2"
bg="hover:$bew-fill-2"
Expand Down
12 changes: 6 additions & 6 deletions src/components/TopBar/components/UserPanelPop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useI18n } from 'vue-i18n'
import type { UserInfo, UserStat } from '../types'
import { revokeAccessKey } from '~/utils/authProvider'
import { getCSRF, getUserID } from '~/utils/main'
import { getCSRF, getUserID, isHomePage } from '~/utils/main'
import { numFormatter } from '~/utils/dataFormatter'
defineProps<{
Expand Down Expand Up @@ -73,12 +73,12 @@ async function logout() {
<a
class="group mr-4"
href="https://account.bilibili.com/account/coin"
target="_blank"
:target="isHomePage() ? '_blank' : '_self'"
>{{ $t('topbar.user_dropdown.money') + userInfo.money }}</a>
<a
class="group"
href="https://pay.bilibili.com/pay-v2-web/bcoin_index"
target="_blank"
:target="isHomePage() ? '_blank' : '_self'"
>{{
$t('topbar.user_dropdown.b_coins') + userInfo.wallet?.bcoin_balance
}}</a>
Expand All @@ -87,7 +87,7 @@ async function logout() {
<a
class="group"
:href="`https://space.bilibili.com/${mid}/fans/follow`"
target="_blank"
:target="isHomePage() ? '_blank' : '_self'"
:title="`${userStat.following}`"
>
<div class="num">
Expand All @@ -97,7 +97,7 @@ async function logout() {
</a>
<a
:href="`https://space.bilibili.com/${mid}/fans/fans`"
target="_blank"
:target="isHomePage() ? '_blank' : '_self'"
:title="`${userStat.follower}`"
>
<div class="num">
Expand All @@ -107,7 +107,7 @@ async function logout() {
</a>
<a
:href="`https://space.bilibili.com/${mid}/dynamic`"
target="_blank"
:target="isHomePage() ? '_blank' : '_self'"
:title="`${userStat.dynamic_count}`"
>
<div class="num">
Expand Down
4 changes: 2 additions & 2 deletions src/contentScripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function isSupportedPages() {
|| /https?:\/\/message.bilibili.com\.*/.test(currentUrl)
// bilibili channel page b站分区页面
|| /https?:\/\/www.bilibili.com\/v\/.*/.test(currentUrl)
// anime page
|| /https?:\/\/www.bilibili.com\/anime.*/.test(currentUrl)
// anime page & chinese anime page
|| /https?:\/\/www.bilibili.com\/(anime|guochuang).*/.test(currentUrl)
// tv shows, movie, variety shows, mooc page
|| /https?:\/\/(www.)?bilibili.com\/(tv|movie|variety|mooc).*/.test(currentUrl))
return true
Expand Down

0 comments on commit 770c806

Please sign in to comment.