(ページの作成:「→All JavaScript here will be loaded for users of the Citizen skin: mw.hook('wikipage.content').add(function($content) { const relatedBox = $('<div id="related-articles-box"><em>関連記事を読み込み中…</em></div>'); $('#mw-content-text').append(relatedBox); new mw.Api().get({ action: 'query', prop: 'relatedarticles', titles: mw.config.get('wgPageName'), format: 'json' }).then(function(data) { const pages = data?.query?.pages…」) |
編集の要約なし |
||
1行目: | 1行目: | ||
/* All JavaScript here will be loaded for users of the Citizen skin */ | /* All JavaScript here will be loaded for users of the Citizen skin */ | ||
mw.hook('wikipage.content').add(function($content) { | mw.hook('wikipage.content').add(function ($content) { | ||
const relatedBox = $('<div id="related-articles-box"><em>関連記事を読み込み中…</em></div>'); | const relatedBox = $('<div id="related-articles-box"><em>関連記事を読み込み中…</em></div>'); | ||
$('#mw-content-text').append(relatedBox); | $('#mw-content-text').append(relatedBox); | ||
9行目: | 9行目: | ||
titles: mw.config.get('wgPageName'), | titles: mw.config.get('wgPageName'), | ||
format: 'json' | format: 'json' | ||
}).then(function(data) { | }).then(function (data) { | ||
const pages = data?.query?.pages; | const pages = data?.query?.pages; | ||
if (!pages) return; | if (!pages) return; |
2025年4月15日 (火) 03:41時点における最新版
/* All JavaScript here will be loaded for users of the Citizen skin */ mw.hook('wikipage.content').add(function ($content) { const relatedBox = $('<div id="related-articles-box"><em>関連記事を読み込み中…</em></div>'); $('#mw-content-text').append(relatedBox); new mw.Api().get({ action: 'query', prop: 'relatedarticles', titles: mw.config.get('wgPageName'), format: 'json' }).then(function (data) { const pages = data?.query?.pages; if (!pages) return; const pageId = Object.keys(pages)[0]; const articles = pages[pageId].relatedarticles; if (!articles || articles.length === 0) { relatedBox.text('関連記事は見つかりませんでした。'); return; } let html = '<ul>'; for (const a of articles) { html += `<li><a href="/wiki/${encodeURIComponent(a.title)}">${a.title}</a></li>`; } html += '</ul>'; relatedBox.html(html); }); });