Skip to content

Instantly share code, notes, and snippets.

@khsk
Last active August 22, 2017 03:41
Show Gist options
  • Save khsk/1e7dd3d6beb21da52e4e18b310202392 to your computer and use it in GitHub Desktop.
Save khsk/1e7dd3d6beb21da52e4e18b310202392 to your computer and use it in GitHub Desktop.
新はてなブックマークで本文をトップに表示する&お気に入りユーザーのコメントをポップアップさせるユーザースクリプト ref: http://qiita.com/khsk/items/5ae8b489a8f16cf637b8
// ==UserScript==
// @name move entory-about to top
// @namespace khsk
// @description 本文とタグをトップに移動
// @include http://b.hatena.ne.jp/entry/*
// @include https://b.hatena.ne.jp/entry/*
// @version 1
// @grant none
// ==/UserScript==
const ea = document.querySelector('section.entry-about');
const emb = document.querySelector('div.entry-myBookmark');
emb.parentNode.insertBefore(ea.cloneNode(true), emb);
// ==UserScript==
// @name popup favorite users comment
// @namespace khsk
// @include http://b.hatena.ne.jp/entry/*
// @include https://b.hatena.ne.jp/entry/*
// @version 1
// @grant none
// ==/UserScript==
const target = document.querySelector('ul.entry-info-favorite');
if (!target){
return;
}
const observer = new MutationObserver((mutations) => {
mutations[0].target.querySelectorAll('li').forEach((li) => {
const popup = li.querySelector('span')
popup.innerText += ' \n ' + li.dataset.bookmarkComment + '\n\n' + li.dataset.bookmarkTags;
// 後から追記すると最初の\nによる<br>が削除される謎現象が起きているので空タグでも改行をつけることにする↑
// if (li.dataset.bookmarkTags) {
// popup.innerText += '\n\n' + li.dataset.bookmarkTags;
// }
// ここきれいにアイコンの上付きできないからなんとかして 適当に大きくしとくね
popup.style.top = '-135px';
popup.style.width = '165px';
// 個人的 横幅が狭いと最初のポップアップが見切れるから右にプラス移動 上下合わせて微調整は個人で
popup.style.right = 0
popup.style.left = 0
});
observer.disconnect();
});
const config = { attributes: true, /*attributeFilter: ['children'],*/childList: true, };
observer.observe(target, config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment