From 548847faecc19d94ff8ee7e0bb97f57cfb281de6 Mon Sep 17 00:00:00 2001 From: hyzhao <1048997225@qq.com> Date: Wed, 26 Oct 2022 11:44:03 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=BF=AB=E6=8D=B7=E9=94=AE?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=BC=A9=E6=94=BE=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ README_EN.md | 3 +++ src-tauri/src/pake.js | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) 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