サブを作ったので、そちらのほうでやりたいと思っています。
http://feckless.hatenablog.com/entry/2016/01/15/235611#js-comment-box
▽1
●
a-kuma3 ベストアンサー |
こんな感じでいけると思います。
$(function() { var myid = document.documentElement.dataset.author; $(".comment-user-id span[data-user-name=\"" + myid + "\"]").each(function() { this.parentNode.parentNode.parentNode.style.backgroundColor = "gray"; }); });
背景色を "gray" にしてます。
補足があったサブの方だと、コメントの背景に白のレース模様の画像が指定されているので、左右の脇にしか背景色が反映されません。
レース模様の画像を残したいのであれば、色を変えた画像をもうひとつ用意して、以下のようにすれば良いと思います。
$(function() { var myid = document.documentElement.dataset.author; $(".comment-user-id span[data-user-name=\"" + myid + "\"]").each(function() { this.parentNode.parentNode.parentNode.style.backgroundImage = "url(自分のコメントの背景画像のURL)"; }); });
$(function() { var MutationObserver = window.MutationObserver || window.WebkitMutationObserver; new MutationObserver(function (records) { records.forEach(function (record) { var myid = document.documentElement.dataset.author; $(".comment-user-id span[data-user-name=\"" + myid + "\"]", record.target).each(function() { this.parentNode.parentNode.parentNode.style.backgroundImage = "url(http://cdn-ak.f.st-hatena.com/images/fotolife/M/Michiko_70554148/20160117/20160117014850.png)"; }); }); }).observe(document.body.querySelector(".comment-box > ul.comment"), {childList: true}); });