fix: 津島ノ宮駅の表示ロジックを削除し、関連コードを整理

This commit is contained in:
harukin-expo-dev-env
2026-08-06 08:06:34 +00:00
parent 39d2be704e
commit 30b8b37343
2 changed files with 0 additions and 130 deletions
-129
View File
@@ -1094,134 +1094,6 @@ const setNewTrainItem = (element,hasProblem,type)=>{
}
}
// 公式サイトの予讃線マスターには通常、臨時駅の津島ノ宮が含まれない。
// 津島ノ宮は交換設備のない棒線駅なので、独立した stationBlock は作らず、
// 海岸寺—詫間の駅間中央レーンへ「みの」と同じ小駅マーカーを複製する。
// 公式の位置データも「海岸寺~詫間」単位のため、この構造なら列車位置を
// 分割せず、そのまま正しく表示できる。
const injectTsushimanomiyaStation = () => {
const disp = document.getElementById('disp');
if (!disp || disp.querySelector('[data-jrs-tsushimanomiya="bar-station"]')) return;
const stationBlocks = Array.from(disp.querySelectorAll(':scope > [id^="stationBlock"]'));
const findStationBlock = (jpName, enName) => stationBlocks.find((block) => {
const stationArea = block.children[1];
const text = ((stationArea && stationArea.textContent) || '').replace(/\\s/g, '');
return text.includes(jpName) || text.toLowerCase().includes(enName.toLowerCase());
});
const kaiganjiBlock = findStationBlock('海岸寺', 'Kaiganji');
const takumaBlock = findStationBlock('詫間', 'Takuma');
if (!kaiganjiBlock || !takumaBlock) return;
const hasBetweenLayout = (element) => {
if (!element) return false;
const parts = element.querySelectorAll(
':scope > [id^="Up"], :scope > [id^="Id"], :scope > [id^="Down"]'
);
return parts.length >= 3;
};
// まず駅名を含む正式な駅間行を探し、見つからない場合だけ
// 海岸寺から詫間までの兄弟要素を構造検査しながら走査する。
let betweenBlock = Array.from(disp.children).find((element) => {
const id = element.id || '';
return id.includes('海岸寺') && id.includes('詫間') && hasBetweenLayout(element);
});
if (!betweenBlock) {
let candidate = kaiganjiBlock.nextElementSibling;
while (candidate && candidate !== takumaBlock && candidate.parentElement === disp) {
if (hasBetweenLayout(candidate)) {
betweenBlock = candidate;
break;
}
candidate = candidate.nextElementSibling;
}
}
if (!betweenBlock) return;
const targetCenterLane = betweenBlock.querySelector(':scope > [id^="Id"]');
if (!targetCenterLane) return;
// 同じ予讃線上の棒線駅「みの」をテンプレートにする。駅間中央レーンの
// 直下だけを調べ、列車の行先表示などに含まれる「みの」は拾わない。
const barStationMarkers = Array.from(disp.querySelectorAll(
':scope > [id*=""] > [id^="Id"] > div'
));
const minoMarker = barStationMarkers.find((marker) => {
const text = ((marker.textContent || '').replace(/\\s/g, ''));
return text.includes('みの') || text.toLowerCase().includes('mino');
});
if (!minoMarker) return;
const stationMarker = minoMarker.cloneNode(true);
stationMarker.setAttribute('data-jrs-tsushimanomiya', 'bar-station');
const replaceText = (root, from, to) => {
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
let node;
while ((node = walker.nextNode())) {
if (node.nodeValue && node.nodeValue.includes(from)) {
node.nodeValue = node.nodeValue.split(from).join(to);
}
}
};
replaceText(stationMarker, 'みの', '津島ノ宮');
replaceText(stationMarker, 'Mino', 'Tsushimanomiya');
// 駅番号が Y / 15 の別テキストノードで組まれている表示に対応する。
replaceText(stationMarker, '15', '13-x');
const tsushimaPdf = 'https://www.jr-shikoku.co.jp/03_news/pdf/20260714_20260805_tsushima-kaki-taisai.pdf';
const rewriteStationValue = (source) => source
.split('みの').join('津島ノ宮')
.split('Mino').join('Tsushimanomiya')
.split('Y15').join('Y13-x');
[stationMarker, ...stationMarker.querySelectorAll('*')].forEach((element) => {
Array.from(element.attributes || []).forEach((attribute) => {
const value = rewriteStationValue(attribute.value);
if (value !== attribute.value) element.setAttribute(attribute.name, value);
});
});
// 複製元と同じIDが残ると駅メニューが誤認するため、ルートIDは必ず固有化する。
stationMarker.id = 'stY13-x津島ノ宮';
// 複製元で付与済みのアプリ側ハンドラーやバッジを持ち越さない。
// 棒線駅は内側にも駅クリック用要素を持つ版があり、そのままだと内側の
// 「みの」ハンドラーが先に発火するため、クリック対象は外側の1つに統一する。
stationMarker.removeAttribute('offclick');
stationMarker.querySelectorAll('*').forEach((element) => {
element.removeAttribute('onclick');
element.removeAttribute('offclick');
element.onclick = null;
if ((element.id || '').indexOf('st') === 0) element.removeAttribute('id');
});
stationMarker.querySelectorAll('.trainstatus').forEach((badge) => badge.remove());
stationMarker.setAttribute(
'onclick',
\"PopUpMenu(event,'13-x','津島ノ宮','\" + tsushimaPdf
+ \"','https://maps.app.goo.gl/dS7waHbBeVRLZxUu9?g_st=ic','','1')\"
);
stationMarker.addEventListener('click', (event) => {
event.preventDefault && event.preventDefault();
event.stopImmediatePropagation && event.stopImmediatePropagation();
window.ReactNativeWebView.postMessage(JSON.stringify({
type: 'PopUpMenu',
event: String(event || ''),
id: '13-x',
name: '津島ノ宮',
pdf: tsushimaPdf,
map: 'https://maps.app.goo.gl/dS7waHbBeVRLZxUu9?g_st=ic',
url: '',
chk: '1'
}));
return false;
}, true);
// 海岸寺~詫間の中央レーンには空のプレースホルダーが残る版がある。
// append すると空区画+津島ノ宮の2ブロックになるため、中央内容を置き換える。
while (targetCenterLane.firstChild) {
targetCenterLane.removeChild(targetCenterLane.firstChild);
}
targetCenterLane.appendChild(stationMarker);
};
//列番付与
const setStrings = () =>{
try {
@@ -1307,7 +1179,6 @@ const setStrings = () =>{
});
}
try { injectTsushimanomiyaStation(); } catch(e) {}
${uiSetting === "tokyo" ? `setNewTrainItemUI();`: ``}
for (let element of elements) {
if(element.getAttribute('offclick')){ continue; }