「MediaWiki:Gadget-TemplateInshokuten.js」の版間の差分
MediaWikiインターフェイスページ
その他の操作
編集の要約なし |
編集の要約なし |
||
| 1行目: | 1行目: | ||
// 店舗/飲食店テンプレート用JavaScript | |||
if ( document.querySelector('.template-tenpo') ) { | if ( document.querySelector('.template-tenpo') ) { | ||
const twitterdiv = document.querySelector('.twitter-id'); | |||
if(twitterdiv) { | |||
const username = twitterdiv.textContent.trim(); | |||
if(username) { // 空文字なら生成しない | |||
const a = document.createElement('a'); | |||
a.href = `https://twitter.com/${username}?ref_src=twsrc%5Etfw`; | |||
a.className = "twitter-follow-button"; | |||
a.dataset.showCount = "false"; | |||
a.textContent = `Follow @${username}`; | |||
twitterdiv.parentNode.replaceChild(a, twitterdiv); | |||
const script = document.createElement('script'); | |||
script.async = true; | |||
script.src = "https://platform.twitter.com/widgets.js"; | |||
script.charset = "utf-8"; | |||
document.body.appendChild(script); | |||
} | |||
} | |||
const instagramdiv = document.querySelector('.instagram-id'); | |||
if(instagramdiv) { | |||
const username = instagramdiv.textContent.trim(); | |||
if(username) { | |||
const a = document.createElement('a'); | |||
a.href = `https://instagram.com/${username}/`; | |||
a.target = "_blank"; | |||
a.rel = "noopener noreferrer"; | |||
const img = document.createElement('img'); | |||
img.src = "/images/3/3d/Instagram_Glyph_Gradient.png"; | |||
img.alt = "Instagram"; | |||
img.style.width = "50px"; | |||
img.style.height = "50px"; | |||
img.style.marginRight = "15px"; | |||
a.appendChild(img); | |||
instagramdiv.parentNode.replaceChild(a, instagramdiv); | |||
} | |||
} | |||
const tictokdiv = document.querySelector('.tictok-id'); | |||
if(tictokdiv) { | |||
const username = tictokdiv.textContent.trim(); | |||
if(username) { | |||
const a = document.createElement('a'); | |||
a.href = `https://tictok.com/@${username}/`; | |||
a.target = "_blank"; | |||
a.rel = "noopener noreferrer"; | |||
const img = document.createElement('img'); | |||
img.src = "/images/f/fa/TikTok-logo-RGB-Tag.png"; | |||
img.alt = "TicTok"; | |||
img.style.width = "50px"; | |||
img.style.height = "50px"; | |||
img.style.marginRight = "15px"; | |||
a.appendChild(img); | |||
tictokdiv.parentNode.replaceChild(a, tictokdiv); | |||
} | |||
} | |||
const facebookdiv = document.querySelector('.facebook-id'); | |||
if(facebookdiv) { | |||
const username = facebookdiv.textContent.trim(); | |||
if(username) { | |||
const a = document.createElement('a'); | |||
a.href = `https://facebook.com/${username}/`; | |||
a.target = "_blank"; | |||
a.rel = "noopener noreferrer"; | |||
const img = document.createElement('img'); | |||
img.src = "/images/8/82/Facebook_Logo_Primary.png"; | |||
img.alt = "Facebook"; | |||
img.style.width = "50px"; | |||
img.style.height = "50px"; | |||
a.appendChild(img); | |||
facebookdiv.parentNode.replaceChild(a, facebookdiv); | |||
} | |||
} | |||
document.querySelectorAll(".wikitable p").forEach(function(p) { | |||
if (!p.textContent.trim()) { | |||
p.remove(); | |||
} | |||
}); | |||
document.querySelectorAll(".wikitable tr").forEach(function(tr) { | |||
const th = tr.querySelector("th"); | |||
const td = tr.querySelector("td"); | |||
if (!th || !td) return; | |||
if (th.textContent.trim() === "郵便番号") { | |||
// 郵便番号らしい数字のみ抽出 | |||
const match = td.textContent.replace(/\D/g, "").match(/^(\d{3})(\d{4})$/); | |||
if (match) { | |||
td.textContent = match[1] + "-" + match[2]; | |||
} | |||
} | |||
}); | |||
} | } | ||
2025年12月5日 (金) 10:46時点における版
// 店舗/飲食店テンプレート用JavaScript
if ( document.querySelector('.template-tenpo') ) {
const twitterdiv = document.querySelector('.twitter-id');
if(twitterdiv) {
const username = twitterdiv.textContent.trim();
if(username) { // 空文字なら生成しない
const a = document.createElement('a');
a.href = `https://twitter.com/${username}?ref_src=twsrc%5Etfw`;
a.className = "twitter-follow-button";
a.dataset.showCount = "false";
a.textContent = `Follow @${username}`;
twitterdiv.parentNode.replaceChild(a, twitterdiv);
const script = document.createElement('script');
script.async = true;
script.src = "https://platform.twitter.com/widgets.js";
script.charset = "utf-8";
document.body.appendChild(script);
}
}
const instagramdiv = document.querySelector('.instagram-id');
if(instagramdiv) {
const username = instagramdiv.textContent.trim();
if(username) {
const a = document.createElement('a');
a.href = `https://instagram.com/${username}/`;
a.target = "_blank";
a.rel = "noopener noreferrer";
const img = document.createElement('img');
img.src = "/images/3/3d/Instagram_Glyph_Gradient.png";
img.alt = "Instagram";
img.style.width = "50px";
img.style.height = "50px";
img.style.marginRight = "15px";
a.appendChild(img);
instagramdiv.parentNode.replaceChild(a, instagramdiv);
}
}
const tictokdiv = document.querySelector('.tictok-id');
if(tictokdiv) {
const username = tictokdiv.textContent.trim();
if(username) {
const a = document.createElement('a');
a.href = `https://tictok.com/@${username}/`;
a.target = "_blank";
a.rel = "noopener noreferrer";
const img = document.createElement('img');
img.src = "/images/f/fa/TikTok-logo-RGB-Tag.png";
img.alt = "TicTok";
img.style.width = "50px";
img.style.height = "50px";
img.style.marginRight = "15px";
a.appendChild(img);
tictokdiv.parentNode.replaceChild(a, tictokdiv);
}
}
const facebookdiv = document.querySelector('.facebook-id');
if(facebookdiv) {
const username = facebookdiv.textContent.trim();
if(username) {
const a = document.createElement('a');
a.href = `https://facebook.com/${username}/`;
a.target = "_blank";
a.rel = "noopener noreferrer";
const img = document.createElement('img');
img.src = "/images/8/82/Facebook_Logo_Primary.png";
img.alt = "Facebook";
img.style.width = "50px";
img.style.height = "50px";
a.appendChild(img);
facebookdiv.parentNode.replaceChild(a, facebookdiv);
}
}
document.querySelectorAll(".wikitable p").forEach(function(p) {
if (!p.textContent.trim()) {
p.remove();
}
});
document.querySelectorAll(".wikitable tr").forEach(function(tr) {
const th = tr.querySelector("th");
const td = tr.querySelector("td");
if (!th || !td) return;
if (th.textContent.trim() === "郵便番号") {
// 郵便番号らしい数字のみ抽出
const match = td.textContent.replace(/\D/g, "").match(/^(\d{3})(\d{4})$/);
if (match) {
td.textContent = match[1] + "-" + match[2];
}
}
});
}