diff --git a/Apps.js b/Apps.js index 54b0a13..ddeee50 100644 --- a/Apps.js +++ b/Apps.js @@ -14,33 +14,42 @@ export default function Apps (props) { var urlcache=""; const webview = useRef(); const [iconSetting, setIconSetting] = useState(undefined) - useEffect(()=>{ - AsyncStorage.getItem("status") - .then(d=>{ - if(d != "2022/04/14"){ - navigate('news'); - } - }) - .catch(e=>{ - navigate('news'); - }) - },[]) - useEffect(()=>{ - AsyncStorage.getItem("iconSwitch").then( d =>{ - if(d){ - setIconSetting(d); - } - else{ - AsyncStorage.setItem("iconSwitch","true").then(()=>Updates.reloadAsync()) - } - - - }).catch(d=>AsyncStorage.setItem("iconSwitch","true").then(()=>Updates.reloadAsync())) - },[]) + + + const bootData = ` + document.getElementById('header').querySelector('a').style.display = 'none'; + document.getElementById('header').style.height = '50px'; + document.getElementById('main').style.paddingTop = '54px'; -const fTrainIcon = iconSetting == "true" ?`JRF || setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/ef210a.png');`:``; -const trainIcon = iconSetting == "true" ? ` - + document.getElementById('headerStr').style.display = 'none'; + const setReload = () =>{ + try{ + document.getElementById('refreshIcon').click(); + setStrings(); + }catch{ + + } + setTimeout(setReload, 10000); + } + setReload(); +`; + +const trainIconMaker = ` + const setStationIcon = (行き先アイコン,img) =>{ + let newItem = document.createElement("div"); + if(行き先アイコン.getAttribute("style").includes("left")){ + 行き先アイコン.insertAdjacentHTML('beforebegin', ""); + } + else{ + 行き先アイコン.insertAdjacentHTML('beforebegin', ""); + } + 行き先アイコン.remove(); + } +` + + + +const trainIcon = iconSetting == "true" ? ` switch(列番データ){ //しおかぜメイン //8000 ノーマル @@ -457,255 +466,254 @@ switch(列番データ){ default: break; } - ` : ``; -const INJECTED_JAVASCRIPT = ` - const setStationIcon = (行き先アイコン,img) =>{ - let newItem = document.createElement("div"); - if(行き先アイコン.getAttribute("style").includes("left")){ - 行き先アイコン.insertAdjacentHTML('beforebegin', ""); - } - else{ - 行き先アイコン.insertAdjacentHTML('beforebegin', ""); - } - 行き先アイコン.remove(); + +const JRF_icon = iconSetting == "true" ? ` + JRF || setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/ef210a.png'); +` : ``; +const normal_train_name = ` + if(new RegExp(/^4[1-9]\\d\\d[DM]$/).test(列番データ) || new RegExp(/^5[1-7]\\d\\d[DM]$/).test(列番データ)){ + 行き先情報.innerText = "ワンマン\\n"+行き先情報.innerText; + flag=true; } - var observer = new MutationObserver(()=>console.log(elem)); - const elem = document.querySelector('#modal_content'); - console.log(elem); - const config = { - attributes: true, - childList: true, - characterData: true - }; + if(new RegExp(/^49[0-4]\\dD$/).test(列番データ) || new RegExp(/^9[0-4]\\dD$/).test(列番データ)){ + 行き先情報.innerText = "(海経由)"+(flag ? "" : "\\n")+行き先情報.innerText; + } + if(new RegExp(/^46\\d\\dD$/).test(列番データ) || new RegExp(/^6\\d\\dD$/).test(列番データ)){ + 行き先情報.innerText = "(内子経由)"+(flag ? "" : "\\n")+行き先情報.innerText; + } + if(列番データ.indexOf("H") != -1){ + 行き先情報.innerText = 行き先情報.innerText+"試運転\\n"; + } + else if(列番データ.indexOf("R") != -1){ + 行き先情報.innerText = 行き先情報.innerText+"回送\\n"; + } + else if(列番データ.indexOf("S") != -1){ + 行き先情報.innerText = 行き先情報.innerText+"臨時列車\\n"; + } +` +const JRF_name = ` + let JRF = false; + switch(列番データ){ + case "71": + 行き先情報.innerText = "東京(タ)→高松(タ)"+"\\n"+行き先情報.innerText; + break; + case "73": + case "75": + 行き先情報.innerText = "大阪(タ)→高松(タ)"+"\\n"+行き先情報.innerText; + break; + case "3079": + 行き先情報.innerText = "高松(タ)→伊予三島"+"\\n"+行き先情報.innerText; + break; + case "3071": + case "3077": + 行き先情報.innerText = "高松(タ)→新居浜"+"\\n"+行き先情報.innerText; + break; + case "3073": + 行き先情報.innerText = "高松(タ)→松山貨物"+"\\n"+行き先情報.innerText; + break; + case "70": + 行き先情報.innerText = "高松(タ)→東京(タ)"+"\\n"+行き先情報.innerText; + break; + case "74": + case "76": + 行き先情報.innerText = "高松(タ)→大阪(タ)"+"\\n"+行き先情報.innerText; + break; + case "3078": + 行き先情報.innerText = "伊予三島→高松(タ)"+"\\n"+行き先情報.innerText; + break; + case "3070": + 行き先情報.innerText = "新居浜→高松(タ)"+"\\n"+行き先情報.innerText; + break; + case "3076": + 行き先情報.innerText = "新居浜→高松(タ)"+"\\n"+行き先情報.innerText; + break; + case "3072": + 行き先情報.innerText = "松山貨物→高松(タ)"+"\\n"+行き先情報.innerText; + break; + case "9070": + 行き先情報.innerText = "臨時貨物"+"\\n"+行き先情報.innerText; + break; + default: + JRF = true; + } + `+JRF_icon; - observer.observe(elem, config); - document.getElementById('header').querySelector('a').style.display = 'none'; - document.getElementById('header').style.height = '50px'; - document.getElementById('main').style.paddingTop = '54px'; - - document.getElementById('headerStr').style.display = 'none'; + const TKT_name = ` + //安芸行と併結列車を個別に表示、それ以外をdefaultで下りなら既定の行き先を、上りなら奈半利行を設定 + switch(列番データ){ + case "5814D": + case "5816D": + 行き先情報.innerText = "ごめん・なはり線直通\\n快速 奈半利行"; + break; + case "5812D": + 行き先情報.innerText = "ごめん・なはり線直通\\n快速 安芸行"; + break; + case "5874D": + case "5882D": + 行き先情報.innerText = "ごめん・なはり線直通\\n各停 安芸行"; + break; + case "742D": + case "746D": + 行き先情報.innerText = "土佐山田/奈半利行\\n(後免にて解結)\\nごめん・なはり線快速"; + break; + default: + if(new RegExp(/^58[1-3][1,3,5,7,9][DM]$/).test(列番データ)){ + 行き先情報.innerText = "ごめん・なはり線直通\\n快速 "+行き先情報.innerText; + } + else if(new RegExp(/^58[4-9][1,3,5,7,9][DM]$/).test(列番データ)){ + 行き先情報.innerText = "ごめん・なはり線直通\\n各停 "+行き先情報.innerText; + } - setStrings(); - function setStrings(){ - try { - document.getElementById('refreshIcon').click(); - var elements = document.querySelectorAll('[onclick]'); - for (let element of elements) { - if(element.getAttribute('onclick').indexOf('ShowTrainTimeInfo') != -1){ - var 行き先情報 = element.getElementsByTagName("p")[0]; - var 列番データ = element.getAttribute('onclick').split('"')[1]; - var flag=false; - var TrainType = undefined; - `+trainIcon+` - - - - console.log(列番データ); - if(new RegExp(/^4[1-9]\\d\\d[DM]$/).test(列番データ) || new RegExp(/^5[1-7]\\d\\d[DM]$/).test(列番データ)){ - 行き先情報.innerText = "ワンマン\\n"+行き先情報.innerText; - flag=true; - } - if(new RegExp(/^49[0-4]\\dD$/).test(列番データ) || new RegExp(/^9[0-4]\\dD$/).test(列番データ)){ - 行き先情報.innerText = "(海経由)"+(flag ? "" : "\\n")+行き先情報.innerText; - } - if(new RegExp(/^46\\d\\dD$/).test(列番データ) || new RegExp(/^6\\d\\dD$/).test(列番データ)){ - 行き先情報.innerText = "(内子経由)"+(flag ? "" : "\\n")+行き先情報.innerText; - } - if(列番データ.indexOf("H") != -1){ - 行き先情報.innerText = 行き先情報.innerText+"試運転\\n"; - } - else if(列番データ.indexOf("R") != -1){ - 行き先情報.innerText = 行き先情報.innerText+"回送\\n"; - } - else if(列番データ.indexOf("S") != -1){ - 行き先情報.innerText = 行き先情報.innerText+"臨時列車\\n"; - } - - //貨物データ - let JRF = false; - switch(列番データ){ - case "71": - 行き先情報.innerText = "東京(タ)→高松(タ)"+"\\n"+行き先情報.innerText; - break; - case "73": - case "75": - 行き先情報.innerText = "大阪(タ)→高松(タ)"+"\\n"+行き先情報.innerText; - break; - case "3079": - 行き先情報.innerText = "高松(タ)→伊予三島"+"\\n"+行き先情報.innerText; - break; - case "3071": - case "3077": - 行き先情報.innerText = "高松(タ)→新居浜"+"\\n"+行き先情報.innerText; - break; - case "3073": - 行き先情報.innerText = "高松(タ)→松山貨物"+"\\n"+行き先情報.innerText; - break; - case "70": - 行き先情報.innerText = "高松(タ)→東京(タ)"+"\\n"+行き先情報.innerText; - break; - case "74": - case "76": - 行き先情報.innerText = "高松(タ)→大阪(タ)"+"\\n"+行き先情報.innerText; - break; - case "3078": - 行き先情報.innerText = "伊予三島→高松(タ)"+"\\n"+行き先情報.innerText; - break; - case "3070": - 行き先情報.innerText = "新居浜→高松(タ)"+"\\n"+行き先情報.innerText; - break; - case "3076": - 行き先情報.innerText = "新居浜→高松(タ)"+"\\n"+行き先情報.innerText; - break; - case "3072": - 行き先情報.innerText = "松山貨物→高松(タ)"+"\\n"+行き先情報.innerText; - break; - case "9070": - 行き先情報.innerText = "臨時貨物"+"\\n"+行き先情報.innerText; - break; - default: - JRF = true; - } - - //土佐くろ - //安芸行と併結列車を個別に表示、それ以外をdefaultで下りなら既定の行き先を、上りなら奈半利行を設定 - switch(列番データ){ - case "2086D": - 行き先情報.innerText = "[特]あしずり16号\\n高知行"; - break; - case "2088D": - 行き先情報.innerText = "[特]あしずり18号\\n高知行"; - break; - case "5814D": - case "5816D": - 行き先情報.innerText = "ごめん・なはり線直通\\n快速 奈半利行"; - break; - case "5812D": - 行き先情報.innerText = "ごめん・なはり線直通\\n快速 安芸行"; - break; - case "5874D": - case "5882D": - 行き先情報.innerText = "ごめん・なはり線直通\\n各停 安芸行"; - break; - case "742D": - case "746D": - 行き先情報.innerText = "土佐山田/奈半利行\\n(後免にて解結)\\nごめん・なはり線快速"; - break; - default: - if(new RegExp(/^58[1-3][1,3,5,7,9][DM]$/).test(列番データ)){ - 行き先情報.innerText = "ごめん・なはり線直通\\n快速 "+行き先情報.innerText; - } - else if(new RegExp(/^58[4-9][1,3,5,7,9][DM]$/).test(列番データ)){ - 行き先情報.innerText = "ごめん・なはり線直通\\n各停 "+行き先情報.innerText; - } - - else if(new RegExp(/^58[3-4][0,2,4,6,8][DM]$/).test(列番データ)){ - 行き先情報.innerText = "ごめん・なはり線直通\\n快速 奈半利行"; - } - else if(new RegExp(/^58[5-9][0,2,4,6,8][DM]$/).test(列番データ)){ - 行き先情報.innerText = "ごめん・なはり線直通\\n各停 奈半利行"; - } - break; - } - - //列番付与 - 行き先情報.innerText = 行き先情報.innerText+列番データ+(JRF ? "":"レ"); - `+fTrainIcon+` + else if(new RegExp(/^58[3-4][0,2,4,6,8][DM]$/).test(列番データ)){ + 行き先情報.innerText = "ごめん・なはり線直通\\n快速 奈半利行"; } - } - try{ - - for(let d of document.getElementById('disp').childNodes){ - if(d.id == 'pMENU_2'){ - continue; - } - if(d.id == 'pMENU_2_En'){ - continue; - } - if(d.id == 'pMENU_3'){ - continue; - } - if(d.id == 'pMENU_3_En'){ - continue; - } - if(d.id == 'pMENU_k'){ - continue; - } - if(d.id == 'pMENU_k_En'){ - continue; - } - d.style.width = '100vw'; - for(let f of d.childNodes){ - try{ - - if(f.style.alignItems || f.style.textAlign){ - f.style.width = '38vw'; - } - else{ - if(f.id == 'upTrainCrossBar'){ - - f.style.width = '38vw'; - } - else if(f.id == 'dwTrainCrossBar'){ - f.style.left = '62vw'; - f.style.width = '38vw'; - - } - else{ - f.style.width = '0vw'; - } - - } - if(f.style.textAlign == 'center'){ - f.style.width = '24vw'; - f.style.display = 'flex'; - for(let i of f.childNodes){ - i.style.width = 'unset'; - i.style.left = 'unset'; - i.style.top = 'unset'; - i.style.position = 'unset'; - i.style.flex = '1'; - i.style.margin = '5px' - - if(i.style.backgroundColor != 'rgb(247, 247, 247)'){ - for(let m of i.childNodes){ - m.style.width = '20vw' - } - } - } - } - - }catch(e){} - } + else if(new RegExp(/^58[5-9][0,2,4,6,8][DM]$/).test(列番データ)){ + 行き先情報.innerText = "ごめん・なはり線直通\\n各停 奈半利行"; } + break; + } + +` - - document.querySelector('#pMENU_2').style.borderStyle='solid'; - document.querySelector('#pMENU_2').style.borderColor='#00d3e8'; - document.querySelector('#pMENU_2').style.borderWidth='2px'; - document.querySelector('#pMENU_2').style.borderRadius='10%'; - document.querySelector('#pMENU_3').style.borderStyle='solid'; - document.querySelector('#pMENU_3').style.borderColor='#00d3e8'; - document.querySelector('#pMENU_3').style.borderWidth='2px'; - document.querySelector('#pMENU_3').style.borderRadius='10%'; - document.querySelectorAll('#pMENU_2 div').forEach((d)=>d.style.padding = '10px'); - document.querySelectorAll('#pMENU_3 div').forEach((d)=>d.style.padding = '10px'); - document.querySelectorAll('#topHeader div').forEach((d)=>d.style.width = '100vw'); - document.querySelectorAll('#disp div')[0].style.width = '100vw'; - document.getElementById('disp').style.width = '100vw'; - document.getElementById('disp').style.overflowX = 'hidden'; - - - - }catch(e){ - alert("にゃー"); - } - } catch (e) {} - setTimeout(setStrings, 10000); +const textInsert = ` +const setStrings = () =>{ + try { + var elements = document.querySelectorAll('[onclick]'); + for (let element of elements) { + if(element.getAttribute('onclick').indexOf('ShowTrainTimeInfo') == -1) continue; + var 行き先情報 = element.getElementsByTagName("p")[0]; + var 列番データ = element.getAttribute('onclick').split('"')[1]; + var flag=false; + var TrainType = undefined; + if(行き先情報.innerText.includes(列番データ))continue; //回避 + `+trainIcon+normal_train_name+JRF_name+TKT_name+` + //列番付与 + 行き先情報.innerText = 行き先情報.innerText+列番データ+(JRF ? "":"レ"); } -`; + try{ + for(let d of document.getElementById('disp').childNodes){ + switch(d.id){ + case 'pMENU_2': + case 'pMENU_2_En': + case 'pMENU_3': + case 'pMENU_3_En': + case 'pMENU_k': + case 'pMENU_k_En': + continue; + default: + break; + } + d.style.width = '100vw'; + for(let f of d.childNodes){ + try{ + if(f.style.alignItems || f.style.textAlign){ + f.style.width = '38vw'; + } + else{ + if(f.id == 'upTrainCrossBar'){ + f.style.width = '38vw'; + } + else if(f.id == 'dwTrainCrossBar'){ + f.style.left = '62vw'; + f.style.width = '38vw'; + + } + else { + f.style.width = '0vw'; + } + } + if(f.style.textAlign == 'center'){ + f.style.width = '24vw'; + f.style.display = 'flex'; + f.childNodes.forEach(i =>{ + i.style.width = 'unset'; + i.style.left = 'unset'; + i.style.top = 'unset'; + i.style.position = 'unset'; + i.style.flex = '1'; + i.style.margin = '5px' + + if(i.style.backgroundColor != 'rgb(247, 247, 247)'){ + i.childNodes.forEach(m=> m.style.width = '20vw') + } + }) + } + + }catch(e){} + } + } + + + + document.querySelector('#pMENU_2').style.borderStyle='solid'; + document.querySelector('#pMENU_2').style.borderColor='#00d3e8'; + document.querySelector('#pMENU_2').style.borderWidth='2px'; + document.querySelector('#pMENU_2').style.borderRadius='10%'; + document.querySelector('#pMENU_3').style.borderStyle='solid'; + document.querySelector('#pMENU_3').style.borderColor='#00d3e8'; + document.querySelector('#pMENU_3').style.borderWidth='2px'; + document.querySelector('#pMENU_3').style.borderRadius='10%'; + document.querySelectorAll('#pMENU_2 div').forEach((d)=>d.style.padding = '10px'); + document.querySelectorAll('#pMENU_3 div').forEach((d)=>d.style.padding = '10px'); + document.querySelectorAll('#topHeader div').forEach((d)=>d.style.width = '100vw'); + document.querySelectorAll('#disp div')[0].style.width = '100vw'; + document.getElementById('disp').style.width = '100vw'; + document.getElementById('disp').style.overflowX = 'hidden'; + + + + }catch(e){ + alert("にゃーん"); + } + } catch (e) {} + //setTimeout(setStrings,500); +} +const target = document.getElementById('disp'); // body要素を監視 +const observer = new MutationObserver( (mutations) => { + // observer.disconnect(); // 監視を終了 + setStrings(); +}); + +// 監視を開始 +observer.observe(target, { + attributes: true, // 属性変化の監視 + //attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する + //characterData: true, // テキストノードの変化を監視 + //characterDataOldValue: true, // 変化前のテキストを matation.oldValue に格納する + childList: true, // 子ノードの変化を監視 + //subtree: true // 子孫ノードも監視対象に含める +}); +` + +const injectJavascriptData = bootData+trainIconMaker+textInsert; + + + + useEffect(()=>{ + AsyncStorage.getItem("status") + .then(d=>{ + if(d != "2022/04/14"){ + navigate('news'); + } + }) + .catch(e=>{ + navigate('news'); + }) + },[]) + useEffect(()=>{ + AsyncStorage.getItem("iconSwitch").then( d =>{ + if(d){ + setIconSetting(d); + } + else{ + AsyncStorage.setItem("iconSwitch","true").then(()=>Updates.reloadAsync()) + } + + + }).catch(d=>AsyncStorage.setItem("iconSwitch","true").then(()=>Updates.reloadAsync())) + },[]) return ( @@ -739,7 +747,7 @@ const INJECTED_JAVASCRIPT = ` } } onMessage={(event)=>{}} - injectedJavaScript={INJECTED_JAVASCRIPT}/> + injectedJavaScript={injectJavascriptData}/> ); } \ No newline at end of file