summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-livereload/src/index.js
blob: e73f12d51c41b62685bdea2c02ad9e3e7d170b4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const GitBook = require('gitbook-core');

module.exports = GitBook.createPlugin({
    activate: (dispatch, getState, { Components }) => {
        if (typeof window === 'undefined') {
            return;
        }

        const newEl = document.createElement('script');
        const firstScriptTag = document.getElementsByTagName('script')[0];

        if (firstScriptTag) {
            newEl.async = 1;
            newEl.src = '//' + window.location.hostname + ':35729/livereload.js';
            firstScriptTag.parentNode.insertBefore(newEl, firstScriptTag);
        }
    }
});