Created
December 17, 2020 02:44
-
-
Save dyxang/547057d66a0ddd5b5783d8b6bb283cd9 to your computer and use it in GitHub Desktop.
Valine评论懒加载
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="1"></div> | |
<script type="text/javascript"> | |
loadComments(); | |
function loadComments() { | |
if (typeof Valine === 'undefined') { | |
var getScript = (options) => { | |
var script = document.createElement('script'); | |
script.defer = true; | |
script.crossOrigin = 'anonymous'; | |
Object.keys(options).forEach((key) => { | |
script[key] = options[key]; | |
}); | |
document.body.appendChild(script); | |
}; | |
getScript({ | |
src: 'https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js', | |
onload: () => { | |
newValine(); | |
} | |
}); | |
} else { | |
newValine(); | |
} | |
} | |
function newValine() { | |
new Valine({ | |
el: '#1', | |
appId: '<%= commentSetting.disqusSetting.api %>', | |
appKey: '<%= commentSetting.disqusSetting.apikey %>', | |
placeholder:'Hello!留下你的足迹吧 !(可直接在评论框内粘贴图片)', | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment