diff --git a/assets/js/webview-preload.js b/assets/js/webview-preload.js index 038a0be69..2dd1670d7 100644 --- a/assets/js/webview-preload.js +++ b/assets/js/webview-preload.js @@ -11,9 +11,59 @@ window.onclick = (e) => { `) } -// Faster zoomLevel setting -window.webFrame = electron.webFrame +// Faster align setting +webFrame = electron.webFrame var ROOT = remote.getGlobal('ROOT') var config = remote.require(`${ROOT}/lib/config`) -zoom = config.get('poi.webview.width', 800) / 800 -webFrame.setZoomFactor(zoom) + +var alertCSS = +`#alert { + transform: scale(0.8); + left: 80px !important; + top: -80px !important; +} +` + +var alignCSS = document.createElement('style') + +window.align = () => { + var zoom + zoom = config.get('poi.webview.width', 800) / 800 + webFrame.setZoomFactor(zoom) + window.scrollTo(0, 0) + alignCSS.innerHTML = + `html { + overflow: hidden; + } + #w, #main-ntg { + position: absolute !important; + top: 0; + left: 0; + z-index: 100; + margin-left: 0 !important; + margin-top: 0 !important; + } + #game_frame { + width: 800px !important; + position: absolute; + top: -16px; + left: 0; + } + #spacing_top { + display: none; + } + .naviapp { + z-index: -1; + } + ` +} +window.unalign = () => { + alignCSS.innerHTML = "" +} + +window.align() + +remote.getCurrentWebContents().insertCSS(alertCSS) +document.addEventListener("DOMContentLoaded", (e) => { + document.querySelector('body').appendChild(alignCSS) +}) diff --git a/views/components/info/control.cjsx b/views/components/info/control.cjsx index e9af417e4..8c948037b 100644 --- a/views/components/info/control.cjsx +++ b/views/components/info/control.cjsx @@ -68,23 +68,9 @@ PoiControl = React.createClass window.dispatchEvent new Event('resize') e.preventDefault() handleUnlockWebview: -> - $('kan-game webview').insertCSS """ - html { - overflow: auto; - } - #w, #main-ntg { - position: relative !important; - top: 0; - left: 0; - z-index: 100; - margin-left: 0 !important; - margin-top: 0 !important; - } - #game_frame { - width: 900px !important; - position: relative; - } - """ + $('kan-game webview').executeJavaScript ''' + window.unalign() + ''' handleSetExtend: -> extend = !@state.extend @setState {extend} diff --git a/views/services/layout.coffee b/views/services/layout.coffee index 6b208335a..75166f067 100644 --- a/views/services/layout.coffee +++ b/views/services/layout.coffee @@ -107,41 +107,9 @@ adjustSize = -> $('kan-game #webview-wrapper')?.style?.height = "#{Math.ceil(480 * window.webviewFactor)}px" factor = null return - # Insert CSS - webview.insertCSS """ - html { - overflow: hidden; - } - #w, #main-ntg { - position: absolute !important; - top: 0; - left: 0; - z-index: 100; - margin-left: 0 !important; - margin-top: 0 !important; - } - #game_frame { - width: 800px !important; - position: absolute; - top: -16px; - left: 0; - } - #spacing_top { - display: none; - } - .naviapp { - z-index: -1; - } - #alert { - transform: scale(0.8); - left: 80px !important; - top: -80px !important; - } - """ # Set zoom factor webview.executeJavaScript """ - window.scrollTo(0, 0); - window.webFrame.setZoomFactor(#{factor}) + window.align() """ adjustSize()