No Title

Author: 3f9bc9d798

Expires in 2 days

06 November 2026

Views: 8

(() => {
// レス数をスレタイの前に
const style = document.createElement("style");
// `(レス数)`の位置を変更したい場合は`.title::before`を変更
style.textContent = `
.title::before {
content: attr(data-res-count) " ";
display: inline;
font-size: inherit;
font-weight: inherit;
line-height: normal;
color: inherit;
}

.title .res-count-original {
font-size: 0 !important;
line-height: 0 !important;
}
`;
document.head.appendChild(style);

function formatTitle(title) {
if (title.dataset.resCountFormatted === "true") return;

const text = title.textContent;
// 末尾の「半角スペース+(数字)」だけ対象にする
const match = text.match(/ \(\d+\)$/);
if (!match) return;

const countText = match[0].slice(1); // 「(15)」など。
const start = text.length - match[0].length; // 手前の半角スペースを残したい場合はここを変更。
const end = text.length;

// タイトル内のテキストノードから、レス数部分を Range で囲む
const walker = document.createTreeWalker(title, NodeFilter.SHOW_TEXT);
let node;
let position = 0;
let startNode, startOffset, endNode, endOffset;

while ((node = walker.nextNode())) {
const nextPosition = position + node.data.length;

if (!startNode && start >= position && start <= nextPosition) {
startNode = node;
startOffset = start - position;
}
if (end >= position && end <= nextPosition) {
endNode = node;
endOffset = end - position;
break;
}
position = nextPosition;
}

if (!startNode || !endNode) return;

const range = document.createRange();
range.setStart(startNode, startOffset);
range.setEnd(endNode, endOffset);

const originalCount = document.createElement("span");
originalCount.className = "res-count-original";
range.surroundContents(originalCount);

title.dataset.resCount = countText;
title.dataset.resCountFormatted = "true";
}

function formatTitles(root = document) {
root.querySelectorAll(".title").forEach(formatTitle);
}

formatTitles();

// 後から追加されるスレ一覧にも適用
const observer = new MutationObserver((records) => {
for (const record of records) {
for (const node of record.addedNodes) {
if (node.nodeType !== Node.ELEMENT_NODE) continue;
if (node.matches?.(".title")) formatTitle(node);
formatTitles(node);
}
}
});

observer.observe(document.body, { childList: true, subtree: true });
})();


Edit Code:

Please enter an edit code

Edit codes must be at least 20 characters

Share