From 8d5ad6e50e3141cadb9f72bbddc58336f18f5592 Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sat, 5 Nov 2022 19:11:14 +0900 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E7=B7=9A=E8=A1=A8=E7=A4=BA=E3=81=AB?= =?UTF-8?q?=E9=A7=85=E5=90=8D=E6=A8=99=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apps.js | 107 ++++++++++------- TestArea.js | 2 - .../StationDeteilView.js | 1 + components/settings.js | 25 +++- components/発車時刻表/LED_vidion.js | 1 - components/駅名表/Sign.js | 108 +++++++++--------- lib/getStationList.js | 23 +++- lib/webViewInjectjavascript.js | 44 ++++++- menu.js | 2 +- trainbaseview.js | 1 - 10 files changed, 211 insertions(+), 103 deletions(-) diff --git a/Apps.js b/Apps.js index e45574c..f95a933 100644 --- a/Apps.js +++ b/Apps.js @@ -27,6 +27,7 @@ export default function Apps(props) { //画面表示関連 const [iconSetting, setIconSetting] = useState(undefined); const [mapSwitch, setMapSwitch] = useState(undefined); + const [stationMenu, setStationMenu] = useState(undefined); //地図用 const [mapsStationData, setMapsStationData] = useState(undefined); @@ -41,46 +42,14 @@ export default function Apps(props) { const [stationBoardData, setStationBoardData] = useState(undefined); const [originalStationList, setOriginalStationList] = useState(); const [selectedStation, setSelectedStation] = useState(undefined); - useEffect(() => { - getStationList().then(setOriginalStationList); - }, []); - - useEffect(() => { - if (!originalStationList) return () => {}; - const findStationEachLine = (selectLine) => - selectLine.filter((d) => d.Station_JP == selectedStation); - - const lineList = [ - "予讃線", - "松宇線", - "伊予灘線", - "土讃線", - "窪川線", - "高徳線", - "徳島線", - "鳴門線", - ]; - let returnDataBase = lineList - .map((d) => findStationEachLine(originalStationList[d])) - .filter((d) => d.length > 0) - .reduce((pre, current) => { - pre.push(...current); - return pre; - }, []); - if (returnDataBase.length) { - let currentStation = currentStation == undefined ? [] : currentStation; - if (currentStation.toString() != returnDataBase.toString()) { - setStationBoardData(returnDataBase); - StationBoardAcSR.current?.setModalVisible(); - } - } else { - setStationBoardData(undefined); - StationBoardAcSR.current?.hide(); - } - }, [originalStationList, selectedStation]); + useEffect(() => getStationList().then(setOriginalStationList), []); //地図表示テキスト - const injectJavascript = injectJavascriptData(mapSwitch, iconSetting); + const injectJavascript = injectJavascriptData( + mapSwitch, + iconSetting, + stationMenu + ); useEffect(() => { //ニュース表示 @@ -123,6 +92,22 @@ export default function Apps(props) { Updates.reloadAsync() ) ); + //駅メニュースイッチ + AsyncStorage.getItem("stationSwitch") + .then((d) => { + if (d) { + setStationMenu(d); + } else { + AsyncStorage.setItem("stationSwitch", "true").then(() => + Updates.reloadAsync() + ); + } + }) + .catch((d) => + AsyncStorage.setItem("stationSwitch", "true").then(() => + Updates.reloadAsync() + ) + ); }, []); return ( @@ -146,7 +131,6 @@ export default function Apps(props) { allowsBackForwardNavigationGestures={true} setSupportMultipleWindows={true} onNavigationStateChange={(event) => { - console.log(event); if (event.url != urlcache) { //URL二重判定回避 urlcache = event.url; @@ -168,7 +152,50 @@ export default function Apps(props) { } }} onMessage={(event) => { - console.log(event.nativeEvent.data); + if (event.nativeEvent.data.includes("PopUpMenu")) { + const selectedStationPDFAddress = event.nativeEvent.data + .split(",")[3] + .replace("'", "") + .replace("'", ""); + + if (!originalStationList) alert("originalStationListがありません"); + const findStationEachLine = (selectLine) => { + let NearStation = selectLine.filter( + (d) => d.StationTimeTable == selectedStationPDFAddress + ); + return NearStation; + }; + + const lineList = [ + "予讃線", + "松宇線", + "伊予灘線", + "土讃線", + "窪川線", + "高徳線", + "徳島線", + "鳴門線", + "瀬戸大橋線", + ]; + let returnDataBase = lineList + .map((d) => findStationEachLine(originalStationList[d])) + .filter((d) => d.length > 0) + .reduce((pre, current) => { + pre.push(...current); + return pre; + }, []); + if (returnDataBase.length) { + let currentStation = + currentStation == undefined ? [] : currentStation; + setStationBoardData(returnDataBase); + StationBoardAcSR.current?.setModalVisible(); + } else { + setStationBoardData(undefined); + StationBoardAcSR.current?.hide(); + } + + return; + } navigate("trainbase", { info: event.nativeEvent.data }); }} injectedJavaScript={injectJavascript} diff --git a/TestArea.js b/TestArea.js index 55b450a..3d56eb3 100644 --- a/TestArea.js +++ b/TestArea.js @@ -11,7 +11,6 @@ export default function TestArea(props) { useEffect(() => { data == null ? test().then((res) => { - //console.log(res); setdata(res); }) : null; @@ -44,7 +43,6 @@ async function test() { .then((D) => { let d = []; D.forEach((element) => { - console.log(element); d.push( { const { StationBoardAcSR, currentStation, originalStationList } = props; + return ( { AsyncStorage.getItem("iconSwitch").then((d) => { setIconSetting(d); @@ -19,8 +20,10 @@ export default function Setting(props) { AsyncStorage.getItem("mapSwitch").then((d) => { setMapSwitch(d); }); + AsyncStorage.getItem("stationSwitch").then((d) => { + setStationMenu(d); + }); }, []); - console.log(iconSetting); return ( @@ -76,6 +79,25 @@ export default function Setting(props) { onValueChange={(value) => setMapSwitch(value.toString())} /> + + + 駅メニューを表示(beta) + + + setStationMenu(value.toString())} + /> + { Updates.reloadAsync(); }); diff --git a/components/発車時刻表/LED_vidion.js b/components/発車時刻表/LED_vidion.js index 7b426e3..cc9400c 100644 --- a/components/発車時刻表/LED_vidion.js +++ b/components/発車時刻表/LED_vidion.js @@ -60,7 +60,6 @@ export default function LED_vision(props) { const [trainDescriptionSwitch, setTrainDescriptionSwitch] = useState(false); useEffect(() => { - console.log("LED"); fetch( "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=traintimeinfo&arg3=dia", HeaderConfig diff --git a/components/駅名表/Sign.js b/components/駅名表/Sign.js index cbefea4..6f57011 100644 --- a/components/駅名表/Sign.js +++ b/components/駅名表/Sign.js @@ -25,6 +25,7 @@ export default function Sign(props) { "高徳線", "徳島線", "鳴門線", + "瀬戸大橋線", ]; let returnData; lineList.forEach((d) => { @@ -66,9 +67,8 @@ export default function Sign(props) { margin: 10, marginHorizontal: wp("10%"), }} - /* onPress={()=> !stationName.今.JrHpUrl || Linking.openURL(stationName.今.JrHpUrl)} */ onPress={ - oP - } + /* onPress={()=> !stationName.今.JrHpUrl || Linking.openURL(stationName.今.JrHpUrl)} */ + onPress={oP} > JR - {currentStation.map((d, index, array) => ( - { - if (array.length == 1) return 20; - else if (index == 0) return 5; - else if (index == 1) return 35; - else return 20; - })() + "%", - right: "10%", - width: wp("10%"), - height: wp("10%"), - borderColor: "#2E94BB", - borderWidth: parseInt("2%"), - borderRadius: parseInt("100%"), - }} - > - - {d.StationNumber} - - - ))} + {currentStation + .filter((d) => (d.StationNumber != " " ? true : false)) + .map((d, index, array) => ( + { + if (array.length == 1) return 20; + else if (index == 0) return 5; + else if (index == 1) return 35; + else return 20; + })() + "%", + right: "10%", + width: wp("10%"), + height: wp("10%"), + borderColor: "#2E94BB", + borderWidth: parseInt("2%"), + borderRadius: parseInt("100%"), + }} + > + + {d.StationNumber} + + + ))} - {(() => { - return currentStation.map((currentStation) => { + { + currentStation.map((currentStation) => { let [preStation, nexStation] = getPreNextStation(currentStation); return ( ◀ , - - - - {preStation.StationNumber} - - - , + + + {preStation.StationNumber} + + + + ), ); - })[nexPrePosition]; - })()} + })[nexPrePosition] + } ); diff --git a/lib/getStationList.js b/lib/getStationList.js index 8f50a95..419fbfe 100644 --- a/lib/getStationList.js +++ b/lib/getStationList.js @@ -48,6 +48,10 @@ export const getStationList = async (props) => { "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=naruto", HeaderConfig ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=seto", + HeaderConfig + ).then((response) => response.json()), fetch( "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=between", HeaderConfig @@ -67,6 +71,7 @@ export const getStationList = async (props) => { stationList.高徳線, stationList.徳島線, stationList.鳴門線, + stationList.瀬戸大橋線, stationList.駅間リスト, stationList.日英対応表, ] = values; @@ -120,7 +125,6 @@ export const getStationList = async (props) => { return data; }); }; - console.log(stationList.予讃線); stationList.予讃線 = addStationPosition( concatBetweenStations(stationList.予讃線), 予讃線, @@ -160,7 +164,22 @@ export const getStationList = async (props) => { concatBetweenStations(stationList.鳴門線), 鳴門線, stationList.日英対応表 - ); + ); /* + stationList.瀬戸大橋線 = [ + { + Station_JP: "児島", + Station_EN: "Kojima", + MyStation: "0", + StationNumber: "M12", + DispNum: "3", + StationTimeTable: + "http://www.jr-odekake.net/eki/timetable.php?id=0651304", + StationMap: "https://www.google.co.jp/maps/place/34.462562,133.807809", + JrHpUrl: "http://www.jr-odekake.net/eki/top.php?id=0651304", + lat: 34.462562, + lng: 133.807809, + }, + ]; */ status = stationList; return stationList; }); diff --git a/lib/webViewInjectjavascript.js b/lib/webViewInjectjavascript.js index 15ff2e4..da76a3b 100644 --- a/lib/webViewInjectjavascript.js +++ b/lib/webViewInjectjavascript.js @@ -1,4 +1,4 @@ -export const injectJavascriptData = (mapSwitch, iconSetting) => { +export const injectJavascriptData = (mapSwitch, iconSetting, stationMenu) => { const topMenu = mapSwitch != "true" ? ` @@ -693,7 +693,7 @@ observer.observe(target, { }); `; - const modal_content = ` + const makeTrainView = ` const modal_content = document.getElementById('modal_content'); // body要素を監視 const modal_observer = new MutationObserver( (mutations) => { @@ -714,6 +714,44 @@ modal_observer.observe(modal_content, { //subtree: true // 子孫ノードも監視対象に含める }); `; + const makeStationMenu = + stationMenu == "true" + ? ` +const setStationMenuDialog = () =>{ + document.querySelector('#pMENU_2').style.display='none'; +document.querySelector('#pMENU_3').style.display='none'; +document.querySelector('#pMENU_2').style.display='none'; +const data =[]; +document.querySelectorAll('#disp div div').forEach(d=>d.id.indexOf("st")!= -1 && data.push(d)); - return bootData + modal_content + trainIconMaker + textInsert; +for(let d of data ){ + if(!d.offclick){ + d.offclick = d.onclick.toString(); + } + d.onclick = () =>{ + window.ReactNativeWebView.postMessage(d.offclick); + } + } +} + + +const observer3 = new MutationObserver( (mutations) => { +// observer3.disconnect(); // 監視を終了 +setStationMenuDialog(); +}); + +// 監視を開始 +observer3.observe(target, { + attributes: true, // 属性変化の監視 + //attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する + //characterData: true, // テキストノードの変化を監視 + //characterDataOldValue: true, // 変化前のテキストを matation.oldValue に格納する + childList: true, // 子ノードの変化を監視 + //subtree: true // 子孫ノードも監視対象に含める +}); +` + : ``; + return ( + bootData + makeTrainView + trainIconMaker + textInsert + makeStationMenu + ); }; diff --git a/menu.js b/menu.js index 660f483..b651dd3 100644 --- a/menu.js +++ b/menu.js @@ -80,7 +80,6 @@ export default function Menu(props) { const [originalStationList, setOriginalStationList] = useState(); useEffect(() => { getStationList().then((stationList) => { - console.log(stationList); setOriginalStationList(stationList); }); }, []); @@ -116,6 +115,7 @@ export default function Menu(props) { "高徳線", "徳島線", "鳴門線", + "瀬戸大橋線", ]; let returnDataBase = lineList .map((d) => findStationEachLine(originalStationList[d])) diff --git a/trainbaseview.js b/trainbaseview.js index e8be5cd..1e02f35 100644 --- a/trainbaseview.js +++ b/trainbaseview.js @@ -11,7 +11,6 @@ export default function TrainBase({ route }) { `document.getElementsByTagName("html")[0].style['font-size'] = '11px';` }`; //const jss = `alert("ほげ")`; - console.log(info); return ( {Platform.OS == "ios" && }