Skip to content

Instantly share code, notes, and snippets.

@Lincest
Last active August 10, 2023 02:38
Show Gist options
  • Save Lincest/80297f88c5525d3f49bdbbbf8a9e5c75 to your computer and use it in GitHub Desktop.
Save Lincest/80297f88c5525d3f49bdbbbf8a9e5c75 to your computer and use it in GitHub Desktop.
waline-in-memos
a.time-text:after { content: ' 评论 💬 '; }
.wl-count { color: #888888; }
#waline{ margin-top: 20px; width: 100%;}
function addCss() {
// Waline link
const cssLink = document.createElement('link');
cssLink.rel = 'stylesheet';
cssLink.href = 'https://unpkg.com/@waline/client@v2/dist/waline.css';
document.head.append(cssLink);
}
function addComment() {
const memosWalline = document.createElement('script');
memosWalline.type = 'module';
memosWalline.text = `
import { init } from 'https://unpkg.com/@waline/client@v2/dist/waline.mjs';
init({
el: '#waline',
serverURL: 'https://comment.roccoshi.top',
dark: 'html[data-joy-color-scheme="dark"]'
});
`;
const artakPos = document.querySelectorAll('script')[0];
artakPos.parentNode.insertBefore(memosWalline, artakPos);
}
// Div
function startComment() {
start = setInterval(() => {
const commentDom = document.querySelector('#waline') || '';
const memoAt = document.querySelector('.memo-wrapper') || '';
const isFinished = document.querySelector('.wl-comment') || '';
if (commentDom) {
return;
}
if (window.location.href.replace(/^.*\/(m)\/.*$/, '$1') == 'm' && !commentDom) {
memoAt.insertAdjacentHTML('afterend', '<div id="waline"><div style="text-align: center;"><p style="color: gray;">评论加载中...</p></div></div>');
addComment();
}
}, 1000);
}
addCss();
startComment();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment