import * as toBuffer from 'blob-to-buffer'
import * as domtoimage from 'dom-to-image'
import { remote, shell } from 'electron'
import * as fs from 'fs'

const container = document.getElementById('app-container')

export function saveImage(fileName: string): Promise<string> {
    return domtoimage.toBlob(container).then((blob: Blob) => {
        toBuffer(blob, (__: any, buffer: Buffer) => {
            fs.writeFile(fileName, buffer)
        })
    })
}

export function openLinksInExternalBrowser(): void {
    const links = document.querySelectorAll('a[href]')
    Array.prototype.forEach.call(links, (link: Element) => {
        const url = link.getAttribute('href')
        if (url!.indexOf('http') === 0) {
            link.addEventListener('click', (e) => {
                e.preventDefault()
                shell.openExternal(url!)
            })
        }
    })
}

export function setFileMenuItemsEnable(enable: boolean): void {
    const menu = remote.Menu.getApplicationMenu()
    menu.items[1].submenu!.items[1].enabled = enable
    menu.items[1].submenu!.items[2].enabled = enable
}

import * as toBuffer from 'blob-to-buffer'
import * as domtoimage from 'dom-to-image'
import { remote, shell } from 'electron'
import * as fs from 'fs'

const container = document.getElementById('app-container')

export function saveImage(fileName: string): Promise<string> {
    return domtoimage.toBlob(container).then((blob: Blob) => {
        toBuffer(blob, (__: any, buffer: Buffer) => {
            fs.writeFile(fileName, buffer)
        })
    })
}

export function openLinksInExternalBrowser(): void {
    const links = document.querySelectorAll('a[href]')
    for (const link of links) {
        const url = link.getAttribute('href')
        if (url!.indexOf('http') === 0) {
            link.addEventListener('click', (e) => {
                e.preventDefault()
                shell.openExternal(url!)
            })
        }
    }
}

export function setFileMenuItemsEnable(enable: boolean): void {
    const menu = remote.Menu.getApplicationMenu()
    menu.items[1].submenu!.items[1].enabled = enable
    menu.items[1].submenu!.items[2].enabled = enable
}

Replace forEach.call with for each loop
Replace forEach.call with for each loop
