banner
老孙

老孙博客

资深网民孙先生
mastodon
email

Add Artalk comments to Memos.

In the previous article,

Adding Twikoo Comments to Memos

  • Updated on October 23, 2023 to be compatible with memos v0.16.1 version
    Replace '.resource-wrapper' with '.gap-2'

  • Updated on October 17, 2023 for memos 0.16 version

Custom Script#

Replace '.resource-wrapper' with '.memo-wrapper'

Custom Style#

Hide comment count

.text-sm.text-gray-500.ml-1{display:none !important;}
  • Reminder for update on September 26, 2023: Applicable for memos version 0.15.1 and below

Custom Script#

// Inject JS into the page using 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 = "Loading comments..."
        }
        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://artalk.loliko.cn',
                        site: 'memos',
                        darkMode: 'auto'
                    });
                    Artalk.on('list-loaded', function() {
                        // console.log('Comments loaded');
                        memoLoading.innerHTML = ''
                        startArtalk();
                    });
                }, 1000);
            }
        }
        //console.log(window.location.href);
    }, 1000)
}
startArtalk();

Custom Style#

a.time-text:after { content: '   Comments 💬 '; }
.atk-main-editor { margin-top: 20px; }

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.