2026/11/17

QooQのシェアボタンをカスタマイズしてMastodon・Misskeyへのシェアとクリップボードへのコピーを追加

ブログ

B!
QooQのデフォルトのシェアボタンは
Twitter/facebook/はてなブックマーク/Pocket/LINE
の5つなんですが、これを
Twitter/はてなブックマーク/Mastodon/Misskey/クリップボードにコピー
に変更しました。

目次

CSS

<head></head>の中に追加。
見た目は好みのものに変更してください。
/* SNSボタン */
#single-footer .single-share{
  margin-top: 4em;
  margin-bottom: 4em;
}

.single-share{
  display: flex;
  justify-content: center;
}

.single-share-twitter,
.single-share-hatena,
.single-share-mastodon,
.single-share-misskey,
.single-share-copy{
  width: 20%;
  height: 30px;
  margin-bottom: 8px;
  color: #fff;
  text-align: center;
  text-decoration: none;
  letter-spacing: .04em;
  border-radius: 4px;
  transition: all .3s;
  padding-top: 1%;
}

.single-share-twitter{
  background: #55acee;
  box-shadow: 0 4px #0c8ff3;
}
.single-share-twitter:hover {
  transform: translateY(4px);
  box-shadow: 0 0 #333;
}

.single-share-hatena{
  background: #008fde;
  box-shadow: 0 4px #0068a1;
}
.single-share-hatena:hover {
  transform: translateY(4px);
  box-shadow: 0 0 #333;
}

.single-share-mastodon{
  box-shadow: 0 4px #372291;
  background-color: #563acc;
}
.single-share-mastodon:hover {
  transform: translateY(4px);
  box-shadow: 0 0 #333;
}

.single-share-misskey{
  box-shadow: 0 4px #90c034;
  background: url(Misskeyアイコンの画像URL) no-repeat center;
  background-size: 1.5em;
  background-color: #c5ef76;
}
.single-share-misskey:hover {
  transform: translateY(4px);
  box-shadow: 0 0 #333;
}

.single-share-copy {
  background: #2669cf;
  box-shadow: 0 4px #144185;
}
.single-share-copy:hover {
  transform: translateY(4px);
  box-shadow: 0 0 #333;
}

@media screen and (max-width: 680px) {
.single-share-twitter,
.single-share-hatena,
.single-share-mastodon,
.single-share-misskey,
.single-share-copy{
    width: 20%;
  }
}
Misskeyはフォントアイコンがないので、アセット集のアイコンを投稿からアップロードして使用。
single-share-misskeyの『Misskeyアイコンの画像URL』の部分を自分でアップロードした画像URLに変更してください。

HTML

シェアボタン表示部分

<div class='single-share'></div>の間を置き換える。
はてなブックマークとMisskey以外はFont Awesomeを使用。

Misskeyのシェア用URLは共有ボタンジェネレーターで作成。
上記コードでは、おすすめサーバードメインはmisskey.ioになっています。
<a class='single-share-twitter' expr:href='&quot;https://twitter.com/intent/tweet?url=&quot; + data:post.canonicalUrl + &quot;&amp;text=&quot; + data:post.title + &quot; - &quot; + data:title' target='_blank' title='ツイッターでつぶやく'><i class='fa-brands fa-twitter'/></a>
<a class='single-share-hatena' expr:href='&quot;http://b.hatena.ne.jp/add?mode=confirm&amp;url=&quot; + data:post.canonicalUrl' title='はてなブックマークに追加'>B!</a>
<a class='single-share-mastodon' expr:href='&quot;https://donshare.net/share.html?url=&quot; + data:post.canonicalUrl + &quot;&amp;text=&quot; + data:post.title + &quot; - &quot; + data:title' target='_blank' title='Mastodonでトゥート'><i class='fa-brands fa-mastodon'/></a>
<a class='single-share-misskey' expr:href='&quot;https://misskey-hub.net/share/?url=&quot; + data:post.canonicalUrl + &quot;&amp;text=&quot; + data:post.title + &quot; - &quot; + data:title + &quot;&amp;visibility=public&amp;localOnly=0&amp;manualInstance=misskey.io&quot;' target='_blank' title='Misskeyでノート'/>
<a class='single-share-copy' expr:data-title='data:post.title + &quot; - &quot; + data:title' expr:data-url='data:post.canonicalUrl' href='#' onclick='copyArticleInfo(this); return false;' title='記事タイトルとURLをコピー'><i class='fa-solid fa-paperclip fa-sm'/></a>

クリップボードにコピーする機能

</body>の直前に追加する。
<!-- クリップボードにコピーするボタン -->
<script>
//<![CDATA[
function copyArticleInfo(button) {
    var title = button.getAttribute("data-title");
    var url = button.getAttribute("data-url");
    var text = title + "\n" + url;

    // 通常のクリップボードAPIを使用
    if (navigator.clipboard && window.isSecureContext) {
        navigator.clipboard.writeText(text).then(function() {
            alert("コピーしました!");
        }).catch(function() {
            copyFallback(text);
        });
    } else {
        copyFallback(text);
    }
}

// 代替コピー処理
function copyFallback(text) {
    var textarea = document.createElement("textarea");
    textarea.value = text;
    textarea.style.position = "fixed";
    textarea.style.opacity = "0";

    document.body.appendChild(textarea);
    textarea.select();

    try {
        if (document.execCommand("copy")) {
            alert("コピーしました!");
        } else {
            alert("コピーに失敗しました。");
        }
    } catch (e) {
        alert("コピーに失敗しました。");
    }

    document.body.removeChild(textarea);
}
//]]>
</script>


プロフィール


ティアリ

https://hassaku74kg.comから
https://hassaku74kg.blogspot.comに移行しました。


Mastodon(Fedibird)  : hassaku74kg@fedibird.com  Twitter : teali_op

最新記事

このブログを検索

QooQ