自定义菜单右键加入复制功能

This commit is contained in:
tangly1024.com
2024-01-31 11:32:01 +08:00
parent 1bb329dfac
commit 195b54e661
3 changed files with 40 additions and 10 deletions

View File

@@ -93,13 +93,33 @@ export default function CustomContextMenu(props) {
/**
* 切换主题
*/
function handeChangeTheme() {
function handleChangeTheme() {
const randomTheme = THEMES[Math.floor(Math.random() * THEMES.length)] // 从THEMES数组中 随机取一个主题
const query = router.query
query.theme = randomTheme
router.push({ pathname: router.pathname, query })
}
/**
* 复制内容
*/
function handleCopy(){
var selectedText = document.getSelection().toString();
if (selectedText) {
var tempInput = document.createElement("input");
tempInput.value = selectedText;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand("copy");
document.body.removeChild(tempInput);
// alert("Text copied: " + selectedText);
} else {
// alert("Please select some text first.");
}
setShow(false)
}
function handleChangeDarkMode() {
const newStatus = !isDarkMode
saveDarkModeToCookies(newStatus)
@@ -153,21 +173,29 @@ export default function CustomContextMenu(props) {
{/* 功能按钮 */}
<div className='w-full px-2'>
<div onClick={handleCopyLink} title={locale.MENU.COPY_URL} className='w-full px-2 h-10 flex justify-start items-center flex-nowrap cursor-pointer hover:bg-blue-600 hover:text-white rounded-lg duration-200 transition-all'>
{siteConfig('CAN_COPY') && (
<div onClick={handleCopy} title={locale.MENU.COPY} className='w-full px-2 h-10 flex justify-start items-center flex-nowrap cursor-pointer hover:bg-blue-600 hover:text-white rounded-lg duration-200 transition-all'>
<i className="fa-solid fa-copy mr-2" />
<div className='whitespace-nowrap'>{locale.MENU.COPY}</div>
</div>
)}
<div onClick={handleCopyLink} title={locale.MENU.SHARE_URL} className='w-full px-2 h-10 flex justify-start items-center flex-nowrap cursor-pointer hover:bg-blue-600 hover:text-white rounded-lg duration-200 transition-all'>
<i className="fa-solid fa-arrow-up-right-from-square mr-2" />
<div className='whitespace-nowrap'>{locale.MENU.COPY_URL}</div>
<div className='whitespace-nowrap'>{locale.MENU.SHARE_URL}</div>
</div>
<div onClick={handleChangeDarkMode} title={isDarkMode ? locale.MENU.LIGHT_MODE : locale.MENU.DARK_MODE} className='w-full px-2 h-10 flex justify-start items-center flex-nowrap cursor-pointer hover:bg-blue-600 hover:text-white rounded-lg duration-200 transition-all'>
{isDarkMode ? <i className="fa-regular fa-sun mr-2" /> : <i className="fa-regular fa-moon mr-2" />}
<div className='whitespace-nowrap'> {isDarkMode ? locale.MENU.LIGHT_MODE : locale.MENU.DARK_MODE}</div>
</div>
{siteConfig('CUSTOM_RIGHT_CLICK_CONTEXT_MENU_THEME_SWITCH') && (
<div onClick={handeChangeTheme} title={locale.MENU.THEME_SWITCH} className='w-full px-2 h-10 flex justify-start items-center flex-nowrap cursor-pointer hover:bg-blue-600 hover:text-white rounded-lg duration-200 transition-all'>
{siteConfig('CUSTOM_RIGHT_CLICK_CONTEXT_MENU_THEME_SWITCH') && (
<div onClick={handleChangeTheme} title={locale.MENU.THEME_SWITCH} className='w-full px-2 h-10 flex justify-start items-center flex-nowrap cursor-pointer hover:bg-blue-600 hover:text-white rounded-lg duration-200 transition-all'>
<i className="fa-solid fa-palette mr-2" />
<div className='whitespace-nowrap'>{locale.MENU.THEME_SWITCH}</div>
</div>
)}
)}
</div>
</div>

View File

@@ -4,10 +4,11 @@ export default {
WALK_AROUND: 'Walk Around',
CATEGORY: 'Category',
TAGS: 'Tags',
COPY_URL: 'Copy URL',
SHARE_URL: 'Share URL',
DARK_MODE: 'Dark Mode',
LIGHT_MODE: 'Light Mode',
THEME_SWITCH: 'Theme Switch'
THEME_SWITCH: 'Theme Switch',
COPY: 'Copy'
},
NAV: {
INDEX: 'Home',

View File

@@ -4,10 +4,11 @@ export default {
WALK_AROUND: '随便逛逛',
CATEGORY: '博客分类',
TAGS: '博客标签',
COPY_URL: '复制地址',
SHARE_URL: '分享地址',
DARK_MODE: '深色模式',
LIGHT_MODE: '浅色模式',
THEME_SWITCH: '主题切换'
THEME_SWITCH: '主题切换',
COPY:'复制'
},
NAV: {
INDEX: '首页',