PublishBUKOME
@@ -8,29 +8,29 @@
javascript:(function(){
/* 1. データの抽出 */
- const doc = document;
- const url = doc.querySelector('link[rel="canonical"]')?.href || location.href;
- const entryTitle = doc.querySelector('.comment-entry-title a')?.innerText || '';
- const entryUrl = doc.querySelector('.comment-entry-title a')?.href || '';
- const userId = doc.documentElement.dataset.stableRequestUrl?.split('/').pop() || '';
- const userIcon = doc.querySelector('.comment-body-username img')?.src || '';
- const commentText = doc.querySelector('.comment-body-text')?.innerText || '';
- const timestamp = doc.querySelector('.comment-body-date a')?.innerText || '';
- const anchorUrl = doc.querySelector('.comment-body-date a')?.href || '';
-
- /* 2. タグの抽出と加工 */
- const tags = Array.from(doc.querySelectorAll('.comment-body-tags li a')).map(a => `[${a.innerText}]`);
- const tagHtml = tags.length > 0
- ? `<ul class="comment-tag" style="list-style: none; margin: 0px;">\n<li style="float: left">🏷️</li>\n${tags.map(t => `<li style="float: left">${t}</li>`).join('\n')}\n</ul>`
- : '';
-
- /* 3. テキストの組み立て */
- const result = `<blockquote class="hatena-bookmark-comment">
-<a class="comment-info" href="${url}" data-user-id="${userId}" data-entry-url="${entryUrl}" data-original-href="${entryUrl}" data-user-icon="${userIcon.replace('https://cdn.profile-image.st-hatena.com', '')}">${entryTitle}</a>
+ const getMeta = (attr) => document.documentElement.getAttribute(attr);
+ const entryUrl = getMeta('data-entry-url');
+ const entryTitle = document.querySelector('.comment-entry-title a')?.innerText || '';
+ const userId = getMeta('data-stable-request-url')?.split('/').pop() || '';
+ const userIcon = document.querySelector('.comment-body-username img')?.src || '';
+ const commentText = document.querySelector('.comment-body-text')?.innerText || '';
+ const timestampText = document.querySelector('.comment-body-date a')?.innerText || '';
+ const permalink = document.querySelector('.comment-body-date a')?.href || '';
+
+ /* タグの取得と成形 */
+ const tags = Array.from(document.querySelectorAll('.comment-body-tags li a'))
+ .map(a => `<li style="float: left">[${a.innerText}]</li>`).join('\n');
+
+ /* 2. テキストの組み立て */
+ const output = `<blockquote class="hatena-bookmark-comment">
+<a class="comment-info" href="${entryUrl}" data-user-id="${userId}" data-entry-url="${entryUrl}" data-original-href="${entryUrl}" data-entry-favicon="https://cdn-ak2.favicon.st-hatena.com/64?url=${encodeURIComponent(entryUrl)}" data-user-icon="/users/${userId}/profile.png">${entryTitle}</a>
<a href="http://b.hatena.ne.jp/entry/${entryUrl}" target="_blank"><img border="0" src="http://b.hatena.ne.jp/entry/image/${entryUrl}" alt="" /></a>
<br>
-${tagHtml}
+<ul class="comment-tag" style="list-style: none; margin: 0px;">
+<li style="float: left">🏷️</li>
+${tags}
+</ul>
<br>
<p style="clear: left">
@@ -40,16 +40,16 @@
<br>
${commentText}
</p>
-<a class="datetime" href="${anchorUrl}">
-<span class="datetime-body">${timestamp}</span>
+<a class="datetime" href="${permalink}">
+<span class="datetime-body">${timestampText}</span>
</a>
</blockquote>`;
- /* 4. クリップボードへのコピー */
- navigator.clipboard.writeText(result).then(() => {
- alert('テキストをクリップボードにコピーしました!');
+ /* 3. クリップボードへのコピーと通知 */
+ console.log(output);
+ navigator.clipboard.writeText(output).then(() => {
+ alert('テキストをコピーしました。');
}).catch(err => {
- console.log(result);
- alert('コピーに失敗しました。コンソール出力をご確認ください。');
+ alert('コピーに失敗しました。コンソールを確認してください。');
});
-})();
+})();
/*
* @title PublishBUKOME
* @コメント一覧ページで「パーマリンク」アイコンを押して開いたブックマークコメントページで実行すると「埋め込みコード」を一部簡略(タグのリンクURL削除など)してクリップボードにコピーする
* @include http://*
* @license MIT License
* @require
*/
javascript:(function(){
/* 1. データの抽出 */
const getMeta = (attr) => document.documentElement.getAttribute(attr);
const entryUrl = getMeta('data-entry-url');
const entryTitle = document.querySelector('.comment-entry-title a')?.innerText || '';
const userId = getMeta('data-stable-request-url')?.split('/').pop() || '';
const userIcon = document.querySelector('.comment-body-username img')?.src || '';
const commentText = document.querySelector('.comment-body-text')?.innerText || '';
const timestampText = document.querySelector('.comment-body-date a')?.innerText || '';
const permalink = document.querySelector('.comment-body-date a')?.href || '';
/* タグの取得と成形 */
const tags = Array.from(document.querySelectorAll('.comment-body-tags li a'))
.map(a => `<li style="float: left">[${a.innerText}]</li>`).join('\n');
/* 2. テキストの組み立て */
const output = `<blockquote class="hatena-bookmark-comment">
<a class="comment-info" href="${entryUrl}" data-user-id="${userId}" data-entry-url="${entryUrl}" data-original-href="${entryUrl}" data-entry-favicon="https://cdn-ak2.favicon.st-hatena.com/64?url=${encodeURIComponent(entryUrl)}" data-user-icon="/users/${userId}/profile.png">${entryTitle}</a>
<a href="http://b.hatena.ne.jp/entry/${entryUrl}" target="_blank"><img border="0" src="http://b.hatena.ne.jp/entry/image/${entryUrl}" alt="" /></a>
<br>
<ul class="comment-tag" style="list-style: none; margin: 0px;">
<li style="float: left">🏷️</li>
${tags}
</ul>
<br>
<p style="clear: left">
<span class="comment-body-username">
<a href="/${userId}/bookmark"><img src="${userIcon}" alt="${userId}">${userId}</a>
</span>
<br>
${commentText}
</p>
<a class="datetime" href="${permalink}">
<span class="datetime-body">${timestampText}</span>
</a>
</blockquote>`;
/* 3. クリップボードへのコピーと通知 */
console.log(output);
navigator.clipboard.writeText(output).then(() => {
alert('テキストをコピーしました。');
}).catch(err => {
alert('コピーに失敗しました。コンソールを確認してください。');
});
})();
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。