在Blogger或其它寫作平台放置LikeCoin Button、Writing NFT widget (半自動化)

Trigger Warning

本站已於 2024 年年底由 Blogger 遷離。雖然本文內容依然有效,但此頁的渲染不再使用相同的程式碼產生。

likecoin-writing-nft-widget-on-blogger

前言

我也加入 Writing NFT 的作者行列了!

這篇文章教各位在 Blogger 每篇文的文末自動產生 LikeCoin Button ,並且,只要在文章中加入 ISCN ,LikeCoin Button 就會變成 Writing NFT widget!

所謂的「半自動化」,是指你需要手動為文章產生 ISCN 並加入文章內,其餘都是自動化的喔!

Widget 外觀

插入程式碼

使用方式

在沒有出版為 Writing NFT 的時候

它會顯示為讚賞按鈕,自動的,什麼都不用做!

在出版為 Writing NFT 的時候

各位理解後一定能記住它


<div id="iscn" hidden>iscn://likecoin-chain/iQ5NQdeCLXQ66evbflzBGgc908rbt0xlfH15cQLdlSQ/1</div>


綠色: div 標籤本體,它是<div></div>的形式
橘色: 這個標籤的 id,用做程式碼的識別,這 id 就叫做 iscn
黃色: hidden ,設定這個標籤在頁面上隱藏不顯示
紫色: ISCN 的內容,程式會把這個內容拿去產生 Writing NFT widget

通用程式碼

以下提供 html encode 前的程式碼,可以在其它的寫作平台使用

<div id="likerContainer" style="background: white; box-shadow: inset 0 0 16px 11px #000000; width: 360px; margin: 0px auto;" ></div>
<script type="text/javascript">
    var container = document.getElementById('likerContainer');
    var iscn = document.getElementById('iscn')?.innerHTML.trim();
    var likerid = '[LikerID]';
    if (iscn) {
        container.innerHTML =
            `<iframe frameborder='0' sandbox='allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-storage-access-by-user-activation' scrolling='no' src='https://button.like.co/in/embed/iscn/button?iscn_id=${encodeURIComponent(iscn)}' style='max-height: 440px; height: 103vw; width: 100%;'/>`;
        console.log('ISCN: ' + iscn);
    } else {
        container.innerHTML =
            `<iframe frameborder='0' sandbox='allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-storage-access-by-user-activation' scrolling='no' src='https://button.like.co/in/embed/${likerid}/button?referrer=${encodeURIComponent(location.href.split('?')[0].split('#')[0])}' style='height: 200px; width: 100%;'/>`;
    }
</script>

參考資料

↓下面這一個就是用此方法產生的 widget↓

Comments

You can comment on this blog post by publicly replying to this post using a Mastodon or other ActivityPub/Fediverse account. Known non-private replies are displayed below.

Open Post