<commit_before>const { remote, webFrame } = require('electron')
const config = remote.require('./lib/config')
const WindowManager = remote.require('./lib/window')

if (config.get('poi.content.muted', false)) {
  remote.getCurrentWebContents().setAudioMuted(true)
}

remote.getCurrentWebContents().addListener('dom-ready', (e) => {
  if (config.get('poi.enableDMMcookie', false)) {
    document.cookie = "cklg=welcome;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/"
    document.cookie = "cklg=welcome;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/netgame/"
    document.cookie = "cklg=welcome;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/netgame_s/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=osapi.dmm.com;path=/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=203.104.209.7;path=/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=www.dmm.com;path=/netgame/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=log-netgame.dmm.com;path=/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/netgame/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/netgame_s/"
    const ua = remote.getCurrentWebContents().session.getUserAgent()
    remote.getCurrentWebContents().session.setUserAgent(ua, 'ja-JP')
  }
  if (config.get('poi.disableNetworkAlert', false)) {
    // eslint-disable-next-line no-undef
    DMM.netgame.reloadDialog=function(){}
  }
})
remote.getCurrentWebContents().addListener('new-window', (e) => {
  const exWindow = WindowManager.createWindow({
    realClose: true,
    navigatable: true,
    nodeIntegration: false,
  })
  exWindow.loadURL(e.url)
  exWindow.show()
  e.preventDefault()
})

// webview focus area fix
// This is a workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=600395
window.onclick = (e) => {
  remote.getCurrentWindow().webContents.executeJavaScript(`
    $('webview').blur()<commit_msg>Fix crash on new-window event<commit_after>const { remote, webFrame } = require('electron')
const config = remote.require('./lib/config')
const WindowManager = remote.require('./lib/window')

if (config.get('poi.content.muted', false)) {
  remote.getCurrentWebContents().setAudioMuted(true)
}

remote.getCurrentWebContents().addListener('dom-ready', (e) => {
  if (config.get('poi.enableDMMcookie', false)) {
    document.cookie = "cklg=welcome;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/"
    document.cookie = "cklg=welcome;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/netgame/"
    document.cookie = "cklg=welcome;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/netgame_s/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=osapi.dmm.com;path=/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=172.16.31.10;path=/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=www.dmm.com;path=/netgame/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=log-netgame.dmm.com;path=/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/netgame/"
    document.cookie = "ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=.dmm.com;path=/netgame_s/"
    const ua = remote.getCurrentWebContents().session.getUserAgent()
    remote.getCurrentWebContents().session.setUserAgent(ua, 'ja-JP')
  }
  if (config.get('poi.disableNetworkAlert', false)) {
    // eslint-disable-next-line no-undef
    DMM.netgame.reloadDialog=function(){}
  }
})
window.WindowManager = WindowManager
remote.getCurrentWebContents().addListener('new-window', (e, url) => {
  const exWindow = WindowManager.createWindow({
    realClose: true,
    navigatable: true,
    nodeIntegration: false,
  })
  exWindow.loadURL(url)
  exWindow.show()
  e.preventDefault()
})

// webview focus area fix
// This is a workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=600395
window.onclick = (e) => {
  remote.getCurrentWindow().webContents.executeJavaScript(`
    $('webview').blur()
{'fraction_non_alphanumeric': 0.16867744138402002, 'fraction_numerical': 0.06487593899385385, 'mean_word_length': 4.905913978494624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4379839', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1562, 'n_words': 262}