fix bugs and add hotkey & mouse wheel options

This commit is contained in:
ACS106103 2021-07-10 23:32:25 +08:00
parent bfa0e11278
commit ad74a4cd29
2 changed files with 59 additions and 42 deletions

View File

@ -1,43 +1,28 @@
/* /*
* view-scale * view-scale
* (c) 2020 SP12893678 (https://github.com/SP12893678) * (c) 2020 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* (c) 2020 SP12893678
* under the MIT license * under the MIT license
*/ */
.bottom-right-buttons { .notion-topbar-actions{
position: absolute;
bottom: 33px;
right: 33px;
z-index: 101;
cursor: default;
pointer-events: none;
display: flex; display: flex;
flex-direction: column; align-items: center !important;
align-items: center; justify-content: center;
}
.bottom-right-buttons > div {
margin-top: 8px;
pointer-events: auto;
user-select: none;
position: static !important;
width: 40px;
border-radius: 100%;
font-size: 20px;
box-shadow: rgba(50, 50, 50, 0.05) 0px 0px 0px 1px, rgba(50, 50, 50, 0.05) 0px 2px 4px;
} }
.notion-scale-contaienr{ .notion-scale-contaienr{
border: 1px solid rgba(200, 200, 200, 0.5); border: 1px solid rgba(200, 200, 200, 0.5);
border-radius: 8px !important; border-radius: 8px !important;
display: flex; display: flex;
flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
margin: 0px 2px;
} }
.notion-scale-contaienr div{ .notion-scale-contaienr div{
margin: 4px 0px; margin: 2px 2px;
cursor: pointer; cursor: pointer;
} }

View File

@ -22,6 +22,18 @@ module.exports = {
type: 'toggle', type: 'toggle',
value: true, value: true,
}, },
{
key: 'canMouseWheel',
label: 'use mouse wheel to scale',
type: 'toggle',
value: true,
},
{
key: 'canHotkey',
label: 'use keyboard hotkey to scale',
type: 'toggle',
value: true,
},
{ {
key: 'offset', key: 'offset',
label: 'set scale plus and minus offset', label: 'set scale plus and minus offset',
@ -43,6 +55,7 @@ module.exports = {
const attempt_interval = setInterval(enhance, 500); const attempt_interval = setInterval(enhance, 500);
function enhance() { function enhance() {
if (!document.querySelector('.notion-frame')) return; if (!document.querySelector('.notion-frame')) return;
if (!document.querySelector('.notion-topbar-actions')) return;
clearInterval(attempt_interval); clearInterval(attempt_interval);
electron.webFrame.setZoomFactor(store().zoom / 100) electron.webFrame.setZoomFactor(store().zoom / 100)
@ -51,9 +64,7 @@ module.exports = {
let minZoom = 0.5 let minZoom = 0.5
let maxZoom = 2 let maxZoom = 2
const $container = document.createElement('div'); const $topBarActionShareMenu = document.querySelector('.notion-topbar-share-menu');
const $helpButton = document.querySelector('.notion-help-button');
const $scaleSet = createElement('<div class="notion-scale-contaienr"></div>'); const $scaleSet = createElement('<div class="notion-scale-contaienr"></div>');
const $scalePlusButton = createElement('<div class="notion-scale-button"></div>'); const $scalePlusButton = createElement('<div class="notion-scale-button"></div>');
const $scaleView = createElement('<div class="notion-scale-view">100%</div>'); const $scaleView = createElement('<div class="notion-scale-view">100%</div>');
@ -73,25 +84,46 @@ module.exports = {
$scaleSet.append($scaleView) $scaleSet.append($scaleView)
$scaleSet.append($scaleMinusButton) $scaleSet.append($scaleMinusButton)
$container.className = 'bottom-right-buttons'; $topBarActionShareMenu.before($scaleSet);
$helpButton.after($container);
$container.append($scaleSet);
$container.append($helpButton);
changeScaleViewUIValue() changeScaleViewUIValue()
} }
if(store().canMouseWheel){
document.defaultView.addEventListener('wheel', (event)=>{
if (event.ctrlKey && event.deltaY < 0){
zoomPlus()
if(store().showUI) changeScaleViewUIValue()
}
document.defaultView.addEventListener('keydown', (event) => { if (event.ctrlKey && event.deltaY > 0){
if (event.key == '+' && event.ctrlKey){ zoomMinus()
zoomPlus() if(store().showUI) changeScaleViewUIValue()
if(store().showUI) changeScaleViewUIValue() }
} });
}
if (event.key == '-' && event.ctrlKey){ if(store().canHotkey){
zoomMinus() document.defaultView.addEventListener('keydown', (event) => {
if(store().showUI) changeScaleViewUIValue() if (event.key == '+' && event.ctrlKey){
} zoomPlus()
}) if(store().showUI) changeScaleViewUIValue()
}
if (event.key == '-' && event.ctrlKey){
zoomMinus()
if(store().showUI) changeScaleViewUIValue()
}
})
}
const observer = new MutationObserver((list, observer) => {
electron.webFrame.setZoomFactor(zoom)
if(store().showUI) changeScaleViewUIValue()
});
observer.observe(document.querySelector('.notion-frame'), {
childList: true
});
function zoomPlus() { function zoomPlus() {
if(zoom + offset > maxZoom) return if(zoom + offset > maxZoom) return