(async()=>{const addBookmark=function(targetElement,bookmark,eid){targetElement.insertAdjacentHTML('beforeend',document.getElementById('autoloader-bookmark-item').textContent.replaceAll('{{user_name}}',bookmark.user).replaceAll('{{bookmarked_url}}',bookmark.url).replaceAll('{{user_page_path}}',`/${bookmark.user}/`).replaceAll('{{ sort }}',`recent`).replaceAll('{{profile_image_url}}',`https://cdn.profile-image.st-hatena.com/users/${bookmark.user}/profile.png`).replaceAll('{{ #is_public }}is-hidden{{ /is_public }}',`is-hidden`).replaceAll('{{{comment_expanded}}}',bookmark.comment).replaceAll('{{{tags}}}',`
${bookmark.tags.join('')}`).replaceAll('{{created}}',bookmark.timestamp).replaceAll('{{comment_page_path}}',`/entry/${eid}/comment/${bookmark.user}`).replaceAll('{{#should_nofollow}}nofollow{{/should_nofollow}}','nofollow').replaceAll('{{#enable_button}} is-enabled{{/enable_button}}','is-enabled'))};const targetURLs=[location.href],bookmarksList=[];for(const targetURL of targetURLs){const{bookmarks:bookmarks,entry_url:entry_url,eid:eid}=await(await fetch('https://b.hatena.ne.jp/entry/jsonlite/?url='+encodeURIComponent(targetURL))).json()??{bookmarks:[],entry_url:null,eid:undefined};if(entry_url)targetURLs.push(entry_url);bookmarksList.push([bookmarks,eid])}function addUpstairsBookmark(targetElements){bookmarksList.forEach((([bookmarks,eid])=>{bookmarks.forEach((bookmark=>{const targetUserBookmark=targetElements.find((element=>element.dataset?.userName===bookmark.user));if(!targetUserBookmark)return undefined;const targetElement=[targetUserBookmark,...targetUserBookmark.querySelectorAll(`[data-user-name="${bookmark.user}"]`)].pop();addBookmark(targetElement,bookmark,eid)}))}))}function addMetaBookmark(targetElements){targetElements.forEach((async element=>{const targetURL=element.querySelector('[data-gtm-label="entry-recent-permalink"]').href;const{bookmarks:bookmarks,entry_url:entry_url,eid:eid}=await(await fetch('https://b.hatena.ne.jp/entry/jsonlite/?url='+encodeURIComponent(targetURL))).json()??{bookmarks:[],entry_url:null};if(!bookmarks.length)return undefined;bookmarks.forEach((bookmark=>{addBookmark(element,bookmark,eid)}))}))}addUpstairsBookmark(Array.from(document.querySelectorAll(`.js-bookmarks-recent [data-user-name]`)));addMetaBookmark(Array.from(document.querySelectorAll(`.js-bookmarks-recent [data-user-name]`)));const targetNode=document.querySelector('.js-bookmarks-recent');const upstairsBookmarkMutationConfig={childList:true};const upstairsBookmarkMutationCallback=function(mutationsList,observer){for(const mutation of mutationsList){if(mutation.type==='childList'){addUpstairsBookmark(Array.from(mutation.addedNodes).filter((node=>node.dataset?.userName)))}}};const upstairsBookmarkMutationObserver=new MutationObserver(upstairsBookmarkMutationCallback);upstairsBookmarkMutationObserver.observe(targetNode,upstairsBookmarkMutationConfig);const metaBookmarkMutationConfig={childList:true,subtree:true};const metaBookmarkMutationCallback=function(mutationsList,observer){for(const mutation of mutationsList){if(mutation.type==='childList'){addMetaBookmark(Array.from(mutation.addedNodes).filter((node=>node.dataset?.userName)))}}};const metaBookmarkMutationObserver=new MutationObserver(metaBookmarkMutationCallback);metaBookmarkMutationObserver.observe(targetNode,metaBookmarkMutationConfig)})();