mirror of https://github.com/jkjoy/sunpeiwen.git
78 lines
2.6 KiB
Markdown
78 lines
2.6 KiB
Markdown
---
|
|
abbrlink: 8828c81e
|
|
categories:
|
|
- - 分享
|
|
date: '2023-06-13T14:25:30.714383+08:00'
|
|
excerpt: ...
|
|
tags:
|
|
- Memos
|
|
title: 给Memos添加Artalk评论
|
|
updated: '2023-8-13T14:28:41.53+8:0'
|
|
cover:
|
|
---
|
|
上文提到
|
|
[给Memos添加Twikoo评论](/2023/507a5d86.html)
|
|
|
|
|
|
2023.9.26更新提醒: memos升级到0.15.1后版本,本方法失效
|
|
## 自定义脚本
|
|
|
|
```
|
|
// Artalk comments 2023.8.15更新
|
|
// 用 JS 向页面中插入 JS
|
|
function addArtalkJS() {
|
|
var memosArtalk = document.createElement("script");
|
|
memosArtalk.src = `https://unpkg.com/artalk/dist/Artalk.js`;
|
|
var artakPos = document.getElementsByTagName("script")[0];
|
|
artakPos.parentNode.insertBefore(memosArtalk, artakPos);
|
|
};
|
|
// div
|
|
function startArtalk() {
|
|
start = setInterval(function(){
|
|
var artalkDom = document.getElementById('Comments') || '';
|
|
var memoAt = document.querySelector('.memo-wrapper') || '';
|
|
var memoLoading = document.querySelector('.action-button-container') || '';
|
|
var memoLoadingA = document.querySelector('.action-button-container a') || '';
|
|
if(window.location.href.replace(/^.*\/(m)\/.*$/,'$1') == "m" && memoLoadingA){
|
|
memoLoading.innerHTML = "评论加载中……"
|
|
}
|
|
if(window.location.href.replace(/^.*\/(m)\/.*$/,'$1') == "m" && !artalkDom){
|
|
addArtalkJS()
|
|
if(memoAt){
|
|
clearInterval(start)
|
|
var cssLink = document.createElement("link");
|
|
cssLink.rel = "stylesheet";
|
|
cssLink.href = "https://unpkg.com/artalk/dist/Artalk.css";
|
|
document.head.appendChild(cssLink);
|
|
memoAt.insertAdjacentHTML('afterend', '<div id="Comments"></div>');
|
|
setTimeout(function() {
|
|
Artalk.init({
|
|
el: '#Comments',
|
|
pageKey: location.pathname,
|
|
pageTitle: document.title,
|
|
server: 'https://atim.fly.dev',
|
|
site: 'memos',
|
|
darkMode: 'auto'
|
|
});
|
|
Artalk.on('list-loaded', function() {
|
|
// console.log('评论加载完成');
|
|
memoLoading.innerHTML = ''
|
|
startArtalk();
|
|
});
|
|
}, 1000);
|
|
}
|
|
}
|
|
//console.log(window.location.href);
|
|
}, 1000)
|
|
}
|
|
startArtalk();
|
|
```
|
|
|
|
## 自定义样式
|
|
|
|
```
|
|
a.time-text:after { content: ' 评论 💬 '; }
|
|
.atk-main-editor { margin-top: 20px; }
|
|
|
|
```
|