diff --git a/index.js b/index.js index 96385c2..353da83 100644 --- a/index.js +++ b/index.js @@ -107,7 +107,7 @@ hexo.on("deployAfter", async function (post) { //insert webpushr tracking code hexo.extend.filter.register('after_render:html', data => { var payload = `(function (w, d, s, id) { - if (typeof (w.webpushr) !== 'undefined') return; w.webpushr = w.webpushr || function () { (w.webpushr.q = w.webpushr.q || []).push(arguments) }; var js, fjs = d.getElementsByTagName(s)[0]; js = d.createElement(s); js.id = id; js.async = 1; js.src = "https://cdn.webpushr.com/app.min.js";fjs.parentNode.appendChild(js);}(window, document, 'script', 'webpushr-jssdk'));webpushr('setup', { 'key': '${hexo.config.webPushNotification.trackingCode}' });` + if (typeof (w.webpushr) !== 'undefined') return; w.webpushr = w.webpushr || function () { (w.webpushr.q = w.webpushr.q || []).push(arguments) }; var js, fjs = d.getElementsByTagName(s)[0]; js = d.createElement(s); js.id = id; js.async = false; js.src = "https://cdn.webpushr.com/app.min.js";fjs.parentNode.appendChild(js);}(window, document, 'script', 'webpushr-jssdk'));webpushr('setup', { 'key': '${hexo.config.webPushNotification.trackingCode}' });` // return data.replace(/(?!<\/body>).+?<\/body>/s, str => str.replace('', "")); return data.replace(/(?!<\/body>).+?<\/body>/s, str => str.replace('', "")); @@ -117,4 +117,4 @@ hexo.extend.filter.register('after_render:html', data => { //insert webpushr-sw.js to web root dir hexo.on('generateAfter', async function (post) { fs.writeFile('public/webpushr-sw.js', "importScripts('https://cdn.webpushr.com/sw-server.min.js');", function (err, data) { hexo.log.info("Generated: webpushr-sw.js") }) -}) \ No newline at end of file +})