// ==UserScript== // @name 2つのブコメを比較(はてな記法版) // @description 比較したいブコメページを入力→コメントを比較したテキストをはてな記法で出力 // @include https://b.hatena.ne.jp/entry/* // ==/UserScript== /* * @title 2つのブコメを比較(はてな記法版) * @description 比較したいブコメページを入力→コメントを比較したテキストをはてな記法で出力 * @include https://b.hatena.ne.jp/entry/* * @license CC0 * @javascript_url */ (async () => { const regexpEscape = s => s.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&') const regexp = new RegExp(regexpEscape("https://b.hatena.ne.jp/entry/") + "(s/)*(.+)") const BtoURL = s => s.replace(regexp, (_, p1, p2) => (p1 ? "https://" : "http://") + p2) const { bookmarks, eid } = (await (await fetch('https://b.hatena.ne.jp/entry/jsonlite/?url=' + encodeURIComponent(BtoURL(prompt('比較ブクマURL', ''))))).json()) const { bookmarks:origBookmarks, eid:origEid } = (await (await fetch('https://b.hatena.ne.jp/entry/jsonlite/?url=' + encodeURIComponent(BtoURL(location.href)))).json()) const blob = new Blob([ bookmarks.flatMap(bookmark => { const origBookmark = origBookmarks.find(origBookmark=>origBookmark.user===bookmark.user) if (!origBookmark) return [] return [`
* ${bookmark.user} >> ${bookmark.comment} https://b.hatena.ne.jp/entry/${eid}/comment/${bookmark.user} << >> ${origBookmark.comment} https://b.hatena.ne.jp/entry/${origEid}/comment/${origBookmark.user} <<`] }).join('') ], { type: "text/html;charset=utf-8" }) const url = URL.createObjectURL(blob) window.open(url) URL.revokeObjectURL(url) })()