✨ 快捷键支持缩放页面
This commit is contained in:
@@ -20,6 +20,9 @@
|
||||
4. `command + ↓`:自动滚动到页面底部
|
||||
5. `command + r`:刷新页面
|
||||
6. `command + w`:隐藏窗口,非退出
|
||||
7. `command + -`:缩小页面
|
||||
8. `command + =`:放大页面
|
||||
9. `command + 0`:重置页面缩放
|
||||
|
||||
此外还支持双击头部进行全屏切换,拖拽头部进行移动窗口,还有其他需求,欢迎提过来。
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user