Skip to content

Instantly share code, notes, and snippets.

@peketamin
Last active May 13, 2021 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peketamin/a8fea064e07f72a92b72ed2deef23d87 to your computer and use it in GitHub Desktop.
Save peketamin/a8fea064e07f72a92b72ed2deef23d87 to your computer and use it in GitHub Desktop.
ブラウザ版はてブのお気に入りユーザーのコメントを一括表示するブックマークレット (説明: https://peketamin.hatenablog.jp/entry/2021/05/12/221554)
if(typeof(String.prototype.trim) === "undefined")
{
String.prototype.trim = function()
{
return String(this).replace(/^\s+|\s+$/g, '');
};
}
class PCHateBuCommentStyle {
constructor () {
PCHateBuCommentStyle.makeStyle();
PCHateBuCommentStyle.applyStyle();
}
static makeStyle() {
const newRule = `
ul.following-bookmarks {
display: list-item;
}
ul.following-bookmarks > li {
border-bottom: 1px solid #ccc;
padding: 0 0 2px 0;
}
ul.following-bookmarks > li > span.pc-hatebu-comment-row {
font-size: small;
padding: 2px;
}
`;
const style = document.createElement('style');
if(style.styleSheet){
style.styleSheet.cssText = newRule;
}else{
style.appendChild(document.createTextNode(newRule));
}
document.getElementsByTagName('head')[0].appendChild(style);
}
static applyStyle() {
const followingBookmarkElms = document.querySelectorAll(".following-bookmarks > li");
for (const targetElm of followingBookmarkElms) {
let origCommentElm = targetElm.querySelector(".following-bookmark-comment");
let customCommentElm = document.createElement("span");
customCommentElm.classList.add("pc-hatebu-comment-row");
customCommentElm.appendChild(targetElm.querySelector(".following-bookmark-username"));
customCommentElm.appendChild(targetElm.querySelector(".following-bookmark-timestamp"));
if (origCommentElm) {
customCommentElm.appendChild(document.createElement("br"));
customCommentElm.appendChild(origCommentElm);
}
targetElm.appendChild(customCommentElm);
}
}
}
let pchbcs = new PCHateBuCommentStyle();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment