1- /**
1+ /**
22 * Copyright (c) 2021 Hengyang Zhang
33 *
44 * This software is released under the MIT License.
88import { OPTION_ROUTE } from "../app/router/constants"
99import { getAppPageUrl , SOURCE_CODE_PAGE , TU_CAO_PAGE } from "@util/constant/url"
1010import { t2Chrome } from "@util/i18n/chrome/t"
11+ import { IS_SAFARI } from "@util/constant/environment"
1112
1213const APP_PAGE_URL = getAppPageUrl ( true )
1314
@@ -19,30 +20,39 @@ const baseProps: Partial<chrome.contextMenus.CreateProperties> = {
1920 visible : true
2021}
2122
23+ function titleOf ( prefixEmoji : string , title : string ) {
24+ if ( IS_SAFARI ) {
25+ // Emoji does not work in Safari's context menu
26+ return title
27+ } else {
28+ return `${ prefixEmoji } ${ title } `
29+ }
30+ }
31+
2232const allFunctionProps : chrome . contextMenus . CreateProperties = {
2333 id : chrome . runtime . id + '_timer_menu_item_app_link' ,
24- title : '🏷️ ' + t2Chrome ( msg => msg . contextMenus . allFunctions ) ,
34+ title : titleOf ( '🏷️' , t2Chrome ( msg => msg . contextMenus . allFunctions ) ) ,
2535 onclick : ( ) => chrome . tabs . create ( { url : APP_PAGE_URL } ) ,
2636 ...baseProps
2737}
2838
2939const optionPageProps : chrome . contextMenus . CreateProperties = {
3040 id : chrome . runtime . id + '_timer_menu_item_option_link' ,
31- title : '🥰 ' + t2Chrome ( msg => msg . contextMenus . optionPage ) ,
41+ title : titleOf ( '🥰' , t2Chrome ( msg => msg . contextMenus . optionPage ) ) ,
3242 onclick : ( ) => chrome . tabs . create ( { url : APP_PAGE_URL + '#' + OPTION_ROUTE } ) ,
3343 ...baseProps
3444}
3545
3646const repoPageProps : chrome . contextMenus . CreateProperties = {
3747 id : chrome . runtime . id + '_timer_menu_item_repo_link' ,
38- title : '🍻 ' + t2Chrome ( msg => msg . contextMenus . repoPage ) ,
48+ title : titleOf ( '🍻' , t2Chrome ( msg => msg . contextMenus . repoPage ) ) ,
3949 onclick : ( ) => chrome . tabs . create ( { url : SOURCE_CODE_PAGE } ) ,
4050 ...baseProps
4151}
4252
4353const feedbackPageProps : chrome . contextMenus . CreateProperties = {
4454 id : chrome . runtime . id + '_timer_menu_item_feedback_link' ,
45- title : '😿 ' + t2Chrome ( msg => msg . contextMenus . feedbackPage ) ,
55+ title : titleOf ( '😿' , t2Chrome ( msg => msg . contextMenus . feedbackPage ) ) ,
4656 onclick : ( ) => chrome . tabs . create ( { url : TU_CAO_PAGE } ) ,
4757 ...baseProps
4858}
0 commit comments