「利用者:Мин троллга барам」の版間の差分
Golden Bengal (トーク | 投稿記録) ページの作成:「ju」 |
Golden Bengal (トーク | 投稿記録) 編集の要約なし |
||
| 1行目: | 1行目: | ||
mw.loader.using('mediawiki.util').then(function () { | |||
// 現在の利用者名(ログイン中のユーザー)を取得 | |||
var currentUser = mw.config.get('wgUserName'); | |||
console.group("sandbox title"); | |||
console.log("currentUser:",currentUser); | |||
// 現在のページタイトルを取得(例: "利用者:Username/sandbox/..." のサブページ) | |||
var pageTitle = mw.config.get('wgPageName'); | |||
pageTitle = pageTitle.replace(/_/g, " "); | |||
console.log("pageTitle:",pageTitle); | |||
var match = pageTitle.match(/^利用者:([^/]+)/); // "利用者:Username" 部分を取得 | |||
var pageUser = match ? match[1] : null; | |||
console.log("pageUser:"+pageUser); | |||
// 現在のページが自分の利用者ページかどうかをチェック | |||
if (currentUser && pageUser && currentUser === pageUser) { | |||
// サンドボックスやそのサブページかどうかをチェック | |||
if (pageTitle.startsWith('利用者:' + currentUser + '/sandbox')) { | |||
// 0.5秒待ってから処理を実行 | |||
setTimeout(function () { | |||
var customTitleElement = document.getElementById('customTitle'); | |||
if (customTitleElement) { | |||
var newTitle = customTitleElement.textContent.trim(); | |||
console.log('newTitle:', newTitle); | |||
// 元のタイトルを取得 | |||
var heading = document.getElementById('firstHeading') || document.getElementsByClassName('mw-first-heading')[0]; | |||
var title_namespace = document.getElementsByClassName('mw-page-title-namespace')[0]; | |||
var title_separator = document.getElementsByClassName('mw-page-title-separator')[0]; | |||
var title_main = document.getElementsByClassName('mw-page-title-main')[0]; | |||
//サンドボックスのテンプレートを非表示 | |||
var sandboxnotice = document.getElementsByClassName('plainlinks ombox ombox-notice')[0]; | |||
if (sandboxnotice){ sandboxnotice.remove(); } | |||
let originalTitle = ""; | |||
if (title_main) { | |||
if (title_namespace) { | |||
originalTitle = title_namespace.textContent.trim()+":"+title_main.textContent.trim(); | |||
} else { | |||
originalTitle = title_main.textContent.trim(); | |||
} | |||
console.log('originalTitle:', originalTitle); | |||
// タイトルが空でないことを確認 | |||
if (originalTitle) { | |||
// タイトルを変更(新しいタイトル + (元のタイトル)) | |||
if (newTitle) { | |||
// ブラウザタブのタイトルを変更 | |||
document.title = newTitle + ' (' + originalTitle + ')'; | |||
// ページ内のタイトルも変更し、元のタイトルを小さく表示 | |||
heading.innerHTML = newTitle + ' <small style="font-size:0.5em; color:gray;">(' + originalTitle + ')</small>'; | |||
} | |||
} else { | |||
console.log('元のタイトルが空です'); | |||
} | |||
document.getElementById("customTitlebox").remove(); | |||
} else { | |||
console.log('ページのタイトル要素が見つかりませんでした'); | |||
} | |||
} | |||
}, 500); | |||
} | |||
} | |||
console.groupEnd("sandbox title"); | |||
}); | |||