diff --git a/README.md b/README.md index 071df01..7ea7217 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ 4. `command + ↓`:自动滚动到页面底部 5. `command + r`:刷新页面 6. `command + w`:隐藏窗口,非退出 +7. `command + -`:缩小页面 +8. `command + =`:放大页面 +9. `command + 0`:重置页面缩放 此外还支持双击头部进行全屏切换,拖拽头部进行移动窗口,还有其他需求,欢迎提过来。 diff --git a/README_EN.md b/README_EN.md index 9ece866..25afe61 100644 --- a/README_EN.md +++ b/README_EN.md @@ -20,6 +20,9 @@ 4. `command + ↓`:Auto scroll to bottom of page 5. `command + r`:Refresh Page 6. `command + w`:Hide window, not quite +7. `command + -`:ZoomOut Page +8. `command + =`:ZoomIn Page +9. `command + 0`:Reset Page zoom In addition, it supports double clicking the head to switch to full screen, and dragging the head to move the window diff --git a/src-tauri/src/pake.js b/src-tauri/src/pake.js index 8d33a47..c2132f3 100644 --- a/src-tauri/src/pake.js +++ b/src-tauri/src/pake.js @@ -85,6 +85,16 @@ window.addEventListener('DOMContentLoaded', (_event) => { if (event.key === "r" && event.metaKey){ window.location.reload(); } + if (event.key === "-" && event.metaKey){ + zoomOut(); + } + if (event.key === "=" && event.metaKey){ + zoomIn(); + } + if (event.key === "0" && event.metaKey){ + document.getElementsByTagName('html')[0].style.zoom = '100%'; + window.localStorage.setItem('htmlZoom', '100%'); + } }) const pakeLinks = document.links; @@ -92,4 +102,29 @@ window.addEventListener('DOMContentLoaded', (_event) => { pakeLinks[linkIndex].target = '_self'; } -}); \ No newline at end of file +}); + +setDefaultZoom(); + +function setDefaultZoom() { + const htmlZoom = window.localStorage.getItem('htmlZoom'); + if (htmlZoom) { + document.getElementsByTagName('html')[0].style.zoom = htmlZoom; + } +} + +function zoomIn() { + const htmlZoom = window.localStorage.getItem('htmlZoom') || '100%'; + const html = document.getElementsByTagName('html')[0]; + const zoom = parseInt(htmlZoom) < 200 ? (parseInt(htmlZoom) + 10 +'%') : '200%'; + html.style.zoom = zoom; + window.localStorage.setItem('htmlZoom', zoom); +} + +function zoomOut() { + const htmlZoom = window.localStorage.getItem('htmlZoom') || '100%'; + const html = document.getElementsByTagName('html')[0]; + const zoom = parseInt(htmlZoom) > 30 ? (parseInt(htmlZoom) - 10 +'%') : '30%'; + html.style.zoom = zoom; + window.localStorage.setItem('htmlZoom', zoom); +} \ No newline at end of file