「MediaWiki:Common.js」の版間の差分
編集の要約なし |
|||
| (同じ利用者による、間の34版が非表示) | |||
| 1行目: | 1行目: | ||
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */ | /* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */ | ||
/* PCスキンでサブタイトルを消す処理 */ | |||
const targetNode = document.getElementById('contentSub'); | |||
const config = { childList: true, subtree: true }; | |||
function | const callback = function(mutationsList, observer) { | ||
const | for (const mutation of mutationsList) { | ||
if (mutation.type === 'childList') { | |||
const subtitleElement = document.getElementById('mw-content-subtitle'); | |||
if (subtitleElement) { | |||
const childNodes = subtitleElement.childNodes; | |||
const lastChildNode = childNodes[childNodes.length - 1]; | |||
if (lastChildNode && lastChildNode.nodeType === Node.TEXT_NODE) { | |||
lastChildNode.remove(); | |||
observer.disconnect(); | |||
return; | |||
} | |||
} | |||
} | } | ||
} | |||
}; | |||
const observer = new MutationObserver(callback); | |||
if (targetNode) { | |||
observer.observe(targetNode, config); | |||
} | } | ||
/* PCスキンでサブタイトルを消す処理 ここまで */ | |||
/* beta2 */ | |||
const pageTitle = mw.config.get('wgPageName') | |||
const pageNo = mw.config.get('wgRevisionId') | |||
const url = `https://${location.hostname}/w/api.php?action=query&format=json&prop=revisions&formatversion=2&revids=${pageNo}&rvprop=user`; | |||
const updaterElement = document.getElementById('last-updater-name'); | |||
fetch(url) | |||
.then(response => { | |||
if (!response.ok) { | |||
throw new Error(`HTTP${response.status}`); | |||
} | |||
return response.json(); | |||
}) | |||
.then(data => { | |||
if (!updaterElement) return; | |||
const pages = data.query.pages; | |||
const pageId = Object.keys(pages)[0]; | |||
const pageData = pages[pageId]; | |||
if (pageData.missing) { | |||
updaterElement.textContent = 'null'; | |||
return; | |||
} | |||
const revisions = pageData.revisions; | |||
if (revisions && revisions.length > 0) { | |||
const lastUpdater = revisions[0].user; | |||
updaterElement.textContent = lastUpdater.charAt(0).toLowerCase() + lastUpdater.slice(1); | |||
} else { | |||
updaterElement.textContent = 'null'; | |||
} | |||
}) | |||
.catch(error => { | |||
console.error('エラー:', error); | |||
if (updaterElement) { | |||
updaterElement.textContent = '[取得エラー]'; | |||
} | |||
}); | |||
/* beta2 ここまで */ | |||
/* スマホめにゅー */ | |||
(function() { | |||
function injectCustomMenu() { | |||
if ($('#p-custom-links').length) return | |||
if (!(mw.config.get('skin') === "minerva")) return | |||
var $navUl = $('#p-navigation'); | |||
var $personalUl = $('#p-personal'); | |||
if ($navUl.length && $personalUl.length) { | |||
var items = [ | |||
{ label: '方針', url: '/wiki/Wiki:方針', icon: 'expand' }, | |||
{ label: '特別ページ一覧', url: '/wiki/特別:特別ページ一覧', icon: 'star' }, | |||
{ label: '全てのページ', url: '/wiki/特別:ページ一覧', icon: 'listBullet' }, | |||
{ label: '最近の更新', url: '/wiki/特別:最近の更新', icon: 'history' } | |||
]; | |||
var html = '<ul id="p-custom-links" class="toggle-list__list">'; | |||
items.forEach(function(item) { | |||
html += '<li class="toggle-list-item">' + | |||
'<a href="' + item.url + '" class="toggle-list-item__anchor menu__item--' + item.icon + '">' + | |||
'<span class="minerva-icon minerva-icon--' + item.icon + '"></span>' + | |||
'<span class="toggle-list-item__label">' + item.label + '</span>' + | |||
'</a>' + | |||
'</li>'; | |||
}); | |||
html += '</ul>'; | |||
$navUl.after(html); | |||
} | |||
} | |||
$(document).ready(injectCustomMenu); | |||
var timer = setInterval(injectCustomMenu, 500); | |||
setTimeout(function() { clearInterval(timer); }, 5000); | |||
})(); | |||
console.log("OK Common.js") | |||