From 10b37d61db19fd2b22934be96d82d0c9983dd040 Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sat, 8 Oct 2022 18:43:40 +0900 Subject: [PATCH 01/15] =?UTF-8?q?=E9=A7=85=E3=83=A1=E3=83=8B=E3=83=A5?= =?UTF-8?q?=E3=83=BC=E3=81=AE=E3=82=B3=E3=83=B3=E3=83=9D=E3=83=BC=E3=83=8D?= =?UTF-8?q?=E3=83=B3=E3=83=88=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StationDeteilView.js | 42 +++++ components/atom/TextBox.js | 23 +++ components/atom/TicketBox.js | 24 +++ components/atom/UsefulBox.js | 22 +++ menu.js | 149 ++---------------- 5 files changed, 120 insertions(+), 140 deletions(-) create mode 100644 components/atom/TextBox.js create mode 100644 components/atom/TicketBox.js create mode 100644 components/atom/UsefulBox.js diff --git a/components/ActionSheetComponents/StationDeteilView.js b/components/ActionSheetComponents/StationDeteilView.js index 541e641..408b6d6 100644 --- a/components/ActionSheetComponents/StationDeteilView.js +++ b/components/ActionSheetComponents/StationDeteilView.js @@ -1,4 +1,46 @@ +import React, { Component, useRef, useState, useEffect } from "react"; +import { + StatusBar, + Platform, + View, + LayoutAnimation, + ScrollView, + Linking, + Text, + TouchableOpacity, +} from "react-native"; +import Image from "react-native-remote-svg"; +import Constants from "expo-constants"; +import { List, ListItem } from "native-base"; +import Icon from "react-native-vector-icons/Entypo"; +import * as Location from "expo-location"; +import StatusbarDetect from "../../StatusbarDetect"; +var Status = StatusbarDetect(); +import { useNavigation } from "@react-navigation/native"; +import AutoHeightImage from "react-native-auto-height-image"; +import { + widthPercentageToDP as wp, + heightPercentageToDP as hp, +} from "react-native-responsive-screen"; +import { + FontAwesome, + Fontisto, + Foundation, + Ionicons, + MaterialCommunityIcons, +} from "@expo/vector-icons"; +import * as WebBrowser from "expo-web-browser"; +import ActionSheet from "react-native-actions-sheet"; +import LottieView from "lottie-react-native"; +import SvgUri from "react-native-svg-uri"; +import Sign from "../../components/駅名表/Sign"; + +import { UsefulBox } from "../atom/UsefulBox"; +import { TicketBox } from "../atom/TicketBox"; +import { TextBox } from "../atom/TextBox"; + export const StationDeteilView = (props) => { + const { StationBoardAcSR, currentStation, originalStationList } = props; return ( { + const { backgroundColor, flex, onPressButton, children } = props; + return ( + + + {children} + + + ); +}; diff --git a/components/atom/TicketBox.js b/components/atom/TicketBox.js new file mode 100644 index 0000000..6d34b95 --- /dev/null +++ b/components/atom/TicketBox.js @@ -0,0 +1,24 @@ +import { TouchableOpacity, Text } from "react-native"; + +export const TicketBox = (props) => { + const { icon, backgroundColor, flex, onPressButton, children } = props; + return ( + + + {children} + + {icon} + + ); +}; diff --git a/components/atom/UsefulBox.js b/components/atom/UsefulBox.js new file mode 100644 index 0000000..afab4cd --- /dev/null +++ b/components/atom/UsefulBox.js @@ -0,0 +1,22 @@ +import { TouchableOpacity, Text } from "react-native"; +import { MaterialCommunityIcons } from "@expo/vector-icons"; +export const UsefulBox = (props) => { + const { icon, backgroundColor, flex, onPressButton, children } = props; + return ( + + + + {children} + + + ); +}; diff --git a/menu.js b/menu.js index b087a52..cbba030 100644 --- a/menu.js +++ b/menu.js @@ -33,6 +33,7 @@ import * as WebBrowser from "expo-web-browser"; import ActionSheet from "react-native-actions-sheet"; import LottieView from "lottie-react-native"; import SvgUri from "react-native-svg-uri"; +import { StationDeteilView } from "./components/ActionSheetComponents/StationDeteilView"; import 予讃線 from "./assets/四国旅客鉄道予讃線.json"; import 土讃線 from "./assets/四国旅客鉄道土讃線.json"; @@ -43,70 +44,9 @@ import 鳴門線 from "./assets/四国旅客鉄道鳴門線.json"; import LED_vision from "./components/発車時刻表/LED_vidion"; import Sign from "./components/駅名表/Sign"; -const UsefulBox = (props) => { - const { icon, backgroundColor, flex, onPressButton, children } = props; - return ( - - - - {children} - - - ); -}; -const TicketBox = (props) => { - const { icon, backgroundColor, flex, onPressButton, children } = props; - return ( - - - {children} - - {icon} - - ); -}; - -const TextBox = (props) => { - const { backgroundColor, flex, onPressButton, children } = props; - return ( - - - {children} - - - ); -}; +import { UsefulBox } from "./components/atom/UsefulBox"; +import { TicketBox } from "./components/atom/TicketBox"; +import { TextBox } from "./components/atom/TextBox"; export default function Menu(props) { const { @@ -850,6 +790,11 @@ export default function Menu(props) { source={require("./assets/トレインビジョン関係/1.svg")} /> */} + - {}} - > - - - - - - {currentStation && ( - Linking.openURL(currentStation[0].StationTimeTable)} - /> - )} - {currentStation && ( - - {!currentStation[0].JrHpUrl || ( - } - flex={1} - onPressButton={() => - Linking.openURL(currentStation[0].JrHpUrl) - } - > - web - - )} - {!currentStation[0].StationTimeTable || ( - } - flex={1} - onPressButton={() => - Linking.openURL(currentStation[0].StationTimeTable) - } - > - 時刻表 - - )} - {!currentStation[0].StationMap || ( - } - flex={1} - onPressButton={() => - Linking.openURL(currentStation[0].StationMap) - } - > - GoogleMap - - )} - - )} - - - ); } From 7b2b2eb6309567a6eccd15ea866c95678074f1cb Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sat, 8 Oct 2022 23:41:23 +0900 Subject: [PATCH 02/15] =?UTF-8?q?stationList=E4=BD=9C=E6=88=90=E9=96=A2?= =?UTF-8?q?=E6=95=B0=E3=81=AE=E5=88=86=E9=9B=A2=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/getStationList.js | 167 ++++++++++++++++++++++++++++++++++++++++++ menu.js | 156 +-------------------------------------- 2 files changed, 170 insertions(+), 153 deletions(-) create mode 100644 lib/getStationList.js diff --git a/lib/getStationList.js b/lib/getStationList.js new file mode 100644 index 0000000..8f50a95 --- /dev/null +++ b/lib/getStationList.js @@ -0,0 +1,167 @@ +import 予讃線 from "../assets/四国旅客鉄道予讃線.json"; +import 土讃線 from "../assets/四国旅客鉄道土讃線.json"; +import 高徳線 from "../assets/四国旅客鉄道高徳線.json"; +import 内子線 from "../assets/四国旅客鉄道内子線.json"; +import 徳島線 from "../assets/四国旅客鉄道徳島線.json"; +import 鳴門線 from "../assets/四国旅客鉄道鳴門線.json"; + +let status = undefined; + +export const getStationList = async (props) => { + if (status) return status; + //駅リストイニシャライズ + const HeaderConfig = { + headers: { + referer: "https://train.jr-shikoku.co.jp/sp.html", + }, + }; + return await Promise.all([ + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=yosan", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima2", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan2", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=koutoku", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=tokushima", + HeaderConfig + ).then((response) => response.json()), + fetch( + "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=between", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=line&arg2=train_lang", + HeaderConfig + ).then((response) => response.json()), + ]).then((values) => { + let stationList = {}; + [ + stationList.予讃線, + stationList.松宇線, + stationList.伊予灘線, + stationList.土讃線, + stationList.窪川線, + stationList.高徳線, + stationList.徳島線, + stationList.鳴門線, + stationList.駅間リスト, + stationList.日英対応表, + ] = values; + const concatBetweenStations = (eachRouteData) => { + let additional = []; + eachRouteData.forEach((routeData, routeIndex) => { + try { + const currentStationID = parseInt( + routeData.StationNumber.replace(/[A-Z]/g, "") + ); + const nextStationID = parseInt( + eachRouteData[routeIndex + 1].StationNumber.replace(/[A-Z]/g, "") + ); + if (nextStationID - currentStationID != 1) { + stationList.駅間リスト.forEach((betweenList) => { + if ( + betweenList.BetweenStation == + routeData.Station_JP + + "~" + + eachRouteData[routeIndex + 1].Station_JP + ) { + additional = additional.concat(betweenList.Datas); + } + }); + } + } catch (e) {} + }); + return eachRouteData + .concat(additional) + .sort((a, b) => (a.StationNumber > b.StationNumber ? 1 : -1)); + }; + const addStationPosition = (setDataBase, geoJson, EnJpList) => { + return setDataBase.map((data) => { + let stationName; + if (data.hasOwnProperty("Station_JP")) stationName = data.Station_JP; + else if (data.hasOwnProperty("StationName")) { + stationName = data.StationName; + data.Station_JP = data.StationName; + data.Station_EN = EnJpList.find( + (d) => d.Station_JP == data.Station_JP + ).Station_EN; + } + geoJson.features + .filter((d) => d.geometry.type == "Point") + .forEach((element) => { + if (element.properties.name == stationName) { + data.lat = element.geometry.coordinates[1]; + data.lng = element.geometry.coordinates[0]; + } + }); + return data; + }); + }; + console.log(stationList.予讃線); + stationList.予讃線 = addStationPosition( + concatBetweenStations(stationList.予讃線), + 予讃線, + stationList.日英対応表 + ); + stationList.松宇線 = addStationPosition( + concatBetweenStations(stationList.松宇線), + 予讃線, + stationList.日英対応表 + ); + stationList.伊予灘線 = addStationPosition( + concatBetweenStations(stationList.伊予灘線), + 予讃線, + stationList.日英対応表 + ); + stationList.土讃線 = addStationPosition( + concatBetweenStations(stationList.土讃線), + 土讃線, + stationList.日英対応表 + ); + stationList.窪川線 = addStationPosition( + concatBetweenStations(stationList.窪川線), + 土讃線, + stationList.日英対応表 + ); + stationList.高徳線 = addStationPosition( + concatBetweenStations(stationList.高徳線), + 高徳線, + stationList.日英対応表 + ); + stationList.徳島線 = addStationPosition( + concatBetweenStations(stationList.徳島線), + 徳島線, + stationList.日英対応表 + ); + stationList.鳴門線 = addStationPosition( + concatBetweenStations(stationList.鳴門線), + 鳴門線, + stationList.日英対応表 + ); + status = stationList; + return stationList; + }); +}; diff --git a/menu.js b/menu.js index cbba030..3702776 100644 --- a/menu.js +++ b/menu.js @@ -47,6 +47,7 @@ import Sign from "./components/駅名表/Sign"; import { UsefulBox } from "./components/atom/UsefulBox"; import { TicketBox } from "./components/atom/TicketBox"; import { TextBox } from "./components/atom/TextBox"; +import { getStationList } from "./lib/getStationList"; export default function Menu(props) { const { @@ -78,159 +79,8 @@ export default function Menu(props) { const [originalStationList, setOriginalStationList] = useState(); useEffect(() => { - //駅リストイニシャライズ - const HeaderConfig = { - headers: { - referer: "https://train.jr-shikoku.co.jp/sp.html", - }, - }; - Promise.all([ - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=yosan", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima2", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan2", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=koutoku", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=tokushima", - HeaderConfig - ).then((response) => response.json()), - fetch( - "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=between", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=line&arg2=train_lang", - HeaderConfig - ).then((response) => response.json()), - ]).then((values) => { - let stationList = {}; - [ - stationList.予讃線, - stationList.松宇線, - stationList.伊予灘線, - stationList.土讃線, - stationList.窪川線, - stationList.高徳線, - stationList.徳島線, - stationList.鳴門線, - stationList.駅間リスト, - stationList.日英対応表, - ] = values; - - const concatBetweenStations = (eachRouteData) => { - let additional = []; - eachRouteData.forEach((routeData, routeIndex) => { - try { - const currentStationID = parseInt( - routeData.StationNumber.replace(/[A-Z]/g, "") - ); - const nextStationID = parseInt( - eachRouteData[routeIndex + 1].StationNumber.replace(/[A-Z]/g, "") - ); - if (nextStationID - currentStationID != 1) { - stationList.駅間リスト.forEach((betweenList) => { - if ( - betweenList.BetweenStation == - routeData.Station_JP + - "~" + - eachRouteData[routeIndex + 1].Station_JP - ) { - additional = additional.concat(betweenList.Datas); - } - }); - } - } catch (e) {} - }); - return eachRouteData - .concat(additional) - .sort((a, b) => (a.StationNumber > b.StationNumber ? 1 : -1)); - }; - const addStationPosition = (setDataBase, geoJson, EnJpList) => { - return setDataBase.map((data) => { - let stationName; - if (data.hasOwnProperty("Station_JP")) stationName = data.Station_JP; - else if (data.hasOwnProperty("StationName")) { - stationName = data.StationName; - data.Station_JP = data.StationName; - data.Station_EN = EnJpList.find( - (d) => d.Station_JP == data.Station_JP - ).Station_EN; - } - geoJson.features - .filter((d) => d.geometry.type == "Point") - .forEach((element) => { - if (element.properties.name == stationName) { - data.lat = element.geometry.coordinates[1]; - data.lng = element.geometry.coordinates[0]; - } - }); - return data; - }); - }; - stationList.予讃線 = addStationPosition( - concatBetweenStations(stationList.予讃線), - 予讃線, - stationList.日英対応表 - ); - stationList.松宇線 = addStationPosition( - concatBetweenStations(stationList.松宇線), - 予讃線, - stationList.日英対応表 - ); - stationList.伊予灘線 = addStationPosition( - concatBetweenStations(stationList.伊予灘線), - 予讃線, - stationList.日英対応表 - ); - stationList.土讃線 = addStationPosition( - concatBetweenStations(stationList.土讃線), - 土讃線, - stationList.日英対応表 - ); - stationList.窪川線 = addStationPosition( - concatBetweenStations(stationList.窪川線), - 土讃線, - stationList.日英対応表 - ); - stationList.高徳線 = addStationPosition( - concatBetweenStations(stationList.高徳線), - 高徳線, - stationList.日英対応表 - ); - stationList.徳島線 = addStationPosition( - concatBetweenStations(stationList.徳島線), - 徳島線, - stationList.日英対応表 - ); - stationList.鳴門線 = addStationPosition( - concatBetweenStations(stationList.鳴門線), - 鳴門線, - stationList.日英対応表 - ); - + getStationList().then((stationList) => { + console.log(stationList); setOriginalStationList(stationList); }); }, []); From 0c4a4921c6572bae701098def619f1d9fab28850 Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sat, 8 Oct 2022 23:41:50 +0900 Subject: [PATCH 03/15] =?UTF-8?q?webView=E5=8A=A0=E5=B7=A5=E6=96=87?= =?UTF-8?q?=E5=AD=97=E5=88=97=E3=81=AE=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apps.js | 786 +-------------------------------- lib/webViewInjectjavascript.js | 719 ++++++++++++++++++++++++++++++ 2 files changed, 736 insertions(+), 769 deletions(-) create mode 100644 lib/webViewInjectjavascript.js diff --git a/Apps.js b/Apps.js index c596e98..718d60f 100644 --- a/Apps.js +++ b/Apps.js @@ -10,6 +10,9 @@ import { WebView } from "react-native-webview"; import Constants from "expo-constants"; import AsyncStorage from "@react-native-async-storage/async-storage"; import { news } from "./config/newsUpdate"; +import { getStationList } from "./lib/getStationList"; +import { StationDeteilView } from "./components/ActionSheetComponents/StationDeteilView"; +import { injectJavascriptData } from "./lib/webViewInjectjavascript"; /* import StatusbarDetect from './StatusbarDetect'; var Status = StatusbarDetect(); */ @@ -24,778 +27,17 @@ export default function Apps(props) { const [mapSwitch, setMapSwitch] = useState(undefined); const [stationData, setStationData] = useState(undefined); + const StationBoardAcSR = useRef(null); + const [currentStation, setCurrentStation] = useState(undefined); + const [originalStationList, setOriginalStationList] = useState(); useEffect(() => { - const HeaderConfig = { - headers: { referer: "https://train.jr-shikoku.co.jp/sp.html" }, - }; - - Promise.all([ - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=yosan", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima2", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan2", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=koutoku", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=tokushima", - HeaderConfig - ).then((response) => response.json()), - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=naruto", - HeaderConfig - ).then((response) => response.json()), - ]).then((values) => { - let stationList = {}; - [ - stationList.yosan, - stationList.uwajima, - stationList.uwajima2, - stationList.dosan, - stationList.dosan2, - stationList.koutoku, - stationList.tokushima, - stationList.naruto, - ] = values; - setStationData(stationList); + getStationList().then((stationList) => { + console.log(stationList); + setOriginalStationList(stationList); }); }, []); - const topMenu = - mapSwitch != "true" - ? ` -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'; -` - : ` -document.getElementsByClassName('accordionClass')[0].style.display = 'none'; -document.getElementById('header').style.display = 'none'; -document.getElementById('main').style.paddingTop = '0px'; -document.getElementById('headerStr').style.display = 'none'; -`; - const bootData = - topMenu + - ` - 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 ノーマル - case "2M": - case "4M": - case "6M": - case "14M": - case "16M": - case "18M": - case "26M": - case "28M": - case "30M": - case "1M": - case "3M": - case "5M": - case "13M": - case "15M": - case "17M": - case "25M": - case "27M": - case "29M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8000nr.png'); - break; - //8000 アンパン - case "10M": - case "22M": - case "9M": - case "21M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s8000ap.png'); - break; - - - //8600 - case "8M": - case "12M": - case "20M": - case "24M": - case "7M": - case "11M": - case "19M": - case "23M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8600.png'); - break; - - //いしづちメイン - //8000 ノーマル - - case "1004M": - case "1006M": - case "1014M": - case "1016M": - case "1018M": - case "1026M": - case "1028M": - case "1030M": - case "1001M": - case "1003M": - case "1005M": - case "1013M": - case "1015M": - case "1017M": - case "1025M": - case "1027M": - case "1029M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8000no.png'); - break; - - //8000 アンパン - case "1010M": - case "1022M": - case "1009M": - case "1021M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s8000ap.png'); - break; - - //8600 - case "1008M": - case "1012M": - case "1020M": - case "1024M": - case "1007M": - case "1011M": - case "1019M": - case "1023M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8600_isz.png'); - break; - - //MEXP - //8000 - case "1092M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8000no.png'); - break; - //8600 - case "1091M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8600_isz.png'); - break; - //三桁いしづち - //8000 アンパン - case "1041M": - case "1044M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s8000ap.png'); - break; - //8600 - case "1043M": - case "1042M": - case "1046M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8600_isz.png'); - break; - - - //南風 2700ノーマル - case "34D": - case "38D": - case "40D": - case "42D": - case "46D": - case "50D": - case "52D": - case "54D": - case "58D": - case "31D": - case "35D": - case "39D": - case "41D": - case "43D": - case "47D": - case "51D": - case "53D": - case "55D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2700.png'); - break; - //2700アンパン - case "32D": - case "36D": - case "44D": - case "48D": - case "56D": - case "33D": - case "37D": - case "45D": - case "49D": - case "57D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s2700apr.png'); - break; - - - - //うずしお - //2700 - case "5006D": - case "5022D": - case "5013D": - case "5029D": - case "3002D": - case "3004D": - case "3010D": - case "3012D": - case "3016D": - case "3018D": - case "3024D": - case "3028D": - case "3030D": - case "3003D": - case "3005D": - case "3007D": - case "3015D": - case "3019D": - case "3021D": - case "3025D": - case "3027D": - case "3031D": - case "3033D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2700_uzu.png'); - break; - - //2600 - case "3008D": - case "3014D": - case "3020D": - case "3026D": - case "3001D": - case "3011D": - case "3017D": - case "3023D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2600.png'); - break; - - //キハ185 - case "3009D": - case "3032D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185tu_uzu.png'); - break; - - //マリンライナー - case "3104M": - case "3106M": - case "3108M": - case "3110M": - case "3112M": - case "3114M": - case "3116M": - case "3118M": - case "3120M": - case "3122M": - case "3124M": - case "3126M": - case "3128M": - case "3130M": - case "3132M": - case "3134M": - case "3136M": - case "3138M": - case "3140M": - case "3142M": - case "3144M": - case "3146M": - case "3148M": - case "3150M": - case "3152M": - case "3154M": - case "3156M": - case "3158M": - case "3160M": - case "3162M": - case "3164M": - case "3166M": - case "3168M": - case "3170M": - case "3105M": - case "3107M": - case "3109M": - case "3111M": - case "3113M": - case "3115M": - case "3117M": - case "3119M": - case "3121M": - case "3123M": - case "3125M": - case "3127M": - case "3129M": - case "3131M": - case "3133M": - case "3135M": - case "3137M": - case "3139M": - case "3141M": - case "3143M": - case "3145M": - case "3147M": - case "3149M": - case "3151M": - case "3153M": - case "3155M": - case "3157M": - case "3159M": - case "3161M": - case "3163M": - case "3165M": - case "3167M": - case "3169M": - case "3175M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s5001.png'); - break; - case "3102M": - case "3101M": - case "3103M": - case "3171M": - case "3173M": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s5001k.png'); - break; - - //サンライズ瀬戸 - case "5032M": - case "5031M": - case "8041M": //琴平延長高松迄 - case "8031M": //琴平延長高松以降 - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/w285.png'); - break; - - //宇和海 - //2000 ノーマル - case "1052D": - case "1056D": - case "1058D": - case "1064D": - case "1070D": - case "1074D": - case "1076D": - case "1078D": - case "1080D": - case "1082D": - case "1051D": - case "1059D": - case "1065D": - case "1069D": - case "1071D": - case "1073D": - case "1075D": - case "1077D": - case "1079D": - case "1053D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2000_uwa.png'); - break; - //2000 アンパン込み - case "1054D": - case "1060D": - case "1062D": - case "1066D": - case "1068D": - case "1072D": - case "1055D": - case "1057D": - case "1061D": - case "1063D": - case "1067D": - case "1081D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s2002a.png'); - break; - //しまんと - case "2002D": - case "2004D": - case "2006D": - case "2008D": - case "2001D": - case "2003D": - case "2005D": - case "2007D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2700_smn.png'); - break; - - //あしずり 2000 - case "2074D": - case "2076D": - case "2080D": - case "2084D": - case "2086D": - case "2071D": - case "2075D": - case "2077D": - case "2081D": - case "2083D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2000_asi.png'); - break; - - //あしずり 2700 - case "2078D": - case "2082D": - case "2088D": - case "2073D": - case "2079D": - case "2085D": - case "2072D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2700_asi.png'); - break; - //剣山 - case "4002D": - case "4004D": - case "4006D": - case "4008D": - case "4010D": - case "4001D": - case "4003D": - case "4005D": - case "4007D": - case "4009D": - case "4011D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185tu.png'); - break; - //むろと - case "5051D": - case "5052D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185_mrt.png'); - break; - - - //よしのがわトロッコ - case "8452D": - case "8451D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s185to_ai.png'); - break; - - //岡山高松アントロ - case "8176D": - case "8179D": - //岡山琴平アントロ - case "8277D": - case "8278D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s32to4.png'); - break; - - //伊予灘ものがたり - case "8901D": - case "8903D": - case "8902D": - case "8904D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185iyoy.png'); - break; - - - //千年ものがたり - case "8011D": - case "8012D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185mm1.png'); - break; - - //夜明けものがたり - case "8053D": - case "8054D": - case "8062D": - case "8063D": - setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185ym1.png'); - break; - default: - break; -} -` - : ``; - - 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; - } - 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; - - 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; - } - - 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; - } - -`; - - 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 modal_content = ` - -const modal_content = document.getElementById('modal_content'); // body要素を監視 -const modal_observer = new MutationObserver( (mutations) => { - // observer.disconnect(); // 監視を終了 - for(let d of modal_content.getElementsByTagName("button") ){ - const data = d.onclick.toString().split("\\"")[1]; - d.onclick = () => window.ReactNativeWebView.postMessage(data) - } -}); - -// 監視を開始 -modal_observer.observe(modal_content, { - //attributes: true, // 属性変化の監視 - //attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する - //characterData: true, // テキストノードの変化を監視 - //characterDataOldValue: true, // 変化前のテキストを matation.oldValue に格納する - childList: true, // 子ノードの変化を監視 - //subtree: true // 子孫ノードも監視対象に含める -}); -`; - - const injectJavascriptData = - bootData + modal_content + trainIconMaker + textInsert; + const injectJavascript = injectJavascriptData(mapSwitch, iconSetting); useEffect(() => { AsyncStorage.getItem("status") @@ -888,7 +130,7 @@ modal_observer.observe(modal_content, { console.log(event.nativeEvent.data); navigate("trainbase", { info: event.nativeEvent.data }); }} - injectedJavaScript={injectJavascriptData} + injectedJavaScript={injectJavascript} /> navigate("trainMenu", { webview, stationData })} @@ -924,6 +166,12 @@ modal_observer.observe(modal_content, { + + ); } diff --git a/lib/webViewInjectjavascript.js b/lib/webViewInjectjavascript.js new file mode 100644 index 0000000..15ff2e4 --- /dev/null +++ b/lib/webViewInjectjavascript.js @@ -0,0 +1,719 @@ +export const injectJavascriptData = (mapSwitch, iconSetting) => { + const topMenu = + mapSwitch != "true" + ? ` +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'; +` + : ` +document.getElementsByClassName('accordionClass')[0].style.display = 'none'; +document.getElementById('header').style.display = 'none'; +document.getElementById('main').style.paddingTop = '0px'; +document.getElementById('headerStr').style.display = 'none'; +`; + const bootData = + topMenu + + ` +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 ノーマル +case "2M": +case "4M": +case "6M": +case "14M": +case "16M": +case "18M": +case "26M": +case "28M": +case "30M": +case "1M": +case "3M": +case "5M": +case "13M": +case "15M": +case "17M": +case "25M": +case "27M": +case "29M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8000nr.png'); + break; +//8000 アンパン +case "10M": +case "22M": +case "9M": +case "21M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s8000ap.png'); + break; + + +//8600 +case "8M": +case "12M": +case "20M": +case "24M": +case "7M": +case "11M": +case "19M": +case "23M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8600.png'); + break; + +//いしづちメイン +//8000 ノーマル + +case "1004M": +case "1006M": +case "1014M": +case "1016M": +case "1018M": +case "1026M": +case "1028M": +case "1030M": +case "1001M": +case "1003M": +case "1005M": +case "1013M": +case "1015M": +case "1017M": +case "1025M": +case "1027M": +case "1029M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8000no.png'); + break; + +//8000 アンパン +case "1010M": +case "1022M": +case "1009M": +case "1021M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s8000ap.png'); + break; + +//8600 +case "1008M": +case "1012M": +case "1020M": +case "1024M": +case "1007M": +case "1011M": +case "1019M": +case "1023M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8600_isz.png'); + break; + +//MEXP +//8000 +case "1092M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8000no.png'); + break; +//8600 +case "1091M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8600_isz.png'); + break; +//三桁いしづち +//8000 アンパン +case "1041M": +case "1044M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s8000ap.png'); + break; +//8600 +case "1043M": +case "1042M": +case "1046M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s8600_isz.png'); + break; + + +//南風 2700ノーマル +case "34D": +case "38D": +case "40D": +case "42D": +case "46D": +case "50D": +case "52D": +case "54D": +case "58D": +case "31D": +case "35D": +case "39D": +case "41D": +case "43D": +case "47D": +case "51D": +case "53D": +case "55D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2700.png'); + break; +//2700アンパン +case "32D": +case "36D": +case "44D": +case "48D": +case "56D": +case "33D": +case "37D": +case "45D": +case "49D": +case "57D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s2700apr.png'); + break; + + + +//うずしお +//2700 +case "5006D": +case "5022D": +case "5013D": +case "5029D": +case "3002D": +case "3004D": +case "3010D": +case "3012D": +case "3016D": +case "3018D": +case "3024D": +case "3028D": +case "3030D": +case "3003D": +case "3005D": +case "3007D": +case "3015D": +case "3019D": +case "3021D": +case "3025D": +case "3027D": +case "3031D": +case "3033D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2700_uzu.png'); + break; + +//2600 +case "3008D": +case "3014D": +case "3020D": +case "3026D": +case "3001D": +case "3011D": +case "3017D": +case "3023D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2600.png'); + break; + +//キハ185 +case "3009D": +case "3032D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185tu_uzu.png'); + break; + +//マリンライナー +case "3104M": +case "3106M": +case "3108M": +case "3110M": +case "3112M": +case "3114M": +case "3116M": +case "3118M": +case "3120M": +case "3122M": +case "3124M": +case "3126M": +case "3128M": +case "3130M": +case "3132M": +case "3134M": +case "3136M": +case "3138M": +case "3140M": +case "3142M": +case "3144M": +case "3146M": +case "3148M": +case "3150M": +case "3152M": +case "3154M": +case "3156M": +case "3158M": +case "3160M": +case "3162M": +case "3164M": +case "3166M": +case "3168M": +case "3170M": +case "3105M": +case "3107M": +case "3109M": +case "3111M": +case "3113M": +case "3115M": +case "3117M": +case "3119M": +case "3121M": +case "3123M": +case "3125M": +case "3127M": +case "3129M": +case "3131M": +case "3133M": +case "3135M": +case "3137M": +case "3139M": +case "3141M": +case "3143M": +case "3145M": +case "3147M": +case "3149M": +case "3151M": +case "3153M": +case "3155M": +case "3157M": +case "3159M": +case "3161M": +case "3163M": +case "3165M": +case "3167M": +case "3169M": +case "3175M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s5001.png'); + break; +case "3102M": +case "3101M": +case "3103M": +case "3171M": +case "3173M": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s5001k.png'); + break; + +//サンライズ瀬戸 +case "5032M": +case "5031M": +case "8041M": //琴平延長高松迄 +case "8031M": //琴平延長高松以降 + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/w285.png'); + break; + +//宇和海 +//2000 ノーマル +case "1052D": +case "1056D": +case "1058D": +case "1064D": +case "1070D": +case "1074D": +case "1076D": +case "1078D": +case "1080D": +case "1082D": +case "1051D": +case "1059D": +case "1065D": +case "1069D": +case "1071D": +case "1073D": +case "1075D": +case "1077D": +case "1079D": +case "1053D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2000_uwa.png'); +break; +//2000 アンパン込み +case "1054D": +case "1060D": +case "1062D": +case "1066D": +case "1068D": +case "1072D": +case "1055D": +case "1057D": +case "1061D": +case "1063D": +case "1067D": +case "1081D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s2002a.png'); +break; +//しまんと +case "2002D": +case "2004D": +case "2006D": +case "2008D": +case "2001D": +case "2003D": +case "2005D": +case "2007D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2700_smn.png'); +break; + +//あしずり 2000 +case "2074D": +case "2076D": +case "2080D": +case "2084D": +case "2086D": +case "2071D": +case "2075D": +case "2077D": +case "2081D": +case "2083D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2000_asi.png'); +break; + +//あしずり 2700 +case "2078D": +case "2082D": +case "2088D": +case "2073D": +case "2079D": +case "2085D": +case "2072D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s2700_asi.png'); +break; +//剣山 +case "4002D": +case "4004D": +case "4006D": +case "4008D": +case "4010D": +case "4001D": +case "4003D": +case "4005D": +case "4007D": +case "4009D": +case "4011D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185tu.png'); +break; +//むろと +case "5051D": +case "5052D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185_mrt.png'); +break; + + +//よしのがわトロッコ +case "8452D": +case "8451D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s185to_ai.png'); +break; + +//岡山高松アントロ +case "8176D": +case "8179D": +//岡山琴平アントロ +case "8277D": +case "8278D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/s32to4.png'); +break; + +//伊予灘ものがたり +case "8901D": +case "8903D": +case "8902D": +case "8904D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185iyoy.png'); +break; + + +//千年ものがたり +case "8011D": +case "8012D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185mm1.png'); +break; + +//夜明けものがたり +case "8053D": +case "8054D": +case "8062D": +case "8063D": + setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/b/s185ym1.png'); +break; +default: + break; +} +` + : ``; + + 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; +} +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; + + 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; + } + + 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; + } + +`; + + 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 modal_content = ` + +const modal_content = document.getElementById('modal_content'); // body要素を監視 +const modal_observer = new MutationObserver( (mutations) => { +// observer.disconnect(); // 監視を終了 +for(let d of modal_content.getElementsByTagName("button") ){ + const data = d.onclick.toString().split("\\"")[1]; + d.onclick = () => window.ReactNativeWebView.postMessage(data) +} +}); + +// 監視を開始 +modal_observer.observe(modal_content, { + //attributes: true, // 属性変化の監視 + //attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する + //characterData: true, // テキストノードの変化を監視 + //characterDataOldValue: true, // 変化前のテキストを matation.oldValue に格納する + childList: true, // 子ノードの変化を監視 + //subtree: true // 子孫ノードも監視対象に含める +}); +`; + + return bootData + modal_content + trainIconMaker + textInsert; +}; From 9135ad350422d7142c4cb21e672684417fbf7525 Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sun, 9 Oct 2022 00:03:45 +0900 Subject: [PATCH 04/15] =?UTF-8?q?=E5=9C=B0=E5=9B=B3=E7=94=A8=E9=A7=85?= =?UTF-8?q?=E3=83=AA=E3=82=B9=E3=83=88=E3=82=92=E5=86=8D=E8=A8=AD=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apps.js | 31 ++++++++++++++++-------- lib/getStationList2.js | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 lib/getStationList2.js diff --git a/Apps.js b/Apps.js index 718d60f..6c215ba 100644 --- a/Apps.js +++ b/Apps.js @@ -13,6 +13,7 @@ import { news } from "./config/newsUpdate"; import { getStationList } from "./lib/getStationList"; import { StationDeteilView } from "./components/ActionSheetComponents/StationDeteilView"; import { injectJavascriptData } from "./lib/webViewInjectjavascript"; +import { getStationList2 } from "./lib/getStationList2"; /* import StatusbarDetect from './StatusbarDetect'; var Status = StatusbarDetect(); */ @@ -23,10 +24,19 @@ export default function Apps(props) { } = props; var urlcache = ""; const webview = useRef(); + //画面表示関連 const [iconSetting, setIconSetting] = useState(undefined); const [mapSwitch, setMapSwitch] = useState(undefined); - const [stationData, setStationData] = useState(undefined); + //地図用 + const [mapsStationData, setMapsStationData] = useState(undefined); + useEffect(() => { + getStationList2().then((data) => { + setMapsStationData(data); + }); + }, []); + + //駅情報画面用 const StationBoardAcSR = useRef(null); const [currentStation, setCurrentStation] = useState(undefined); const [originalStationList, setOriginalStationList] = useState(); @@ -37,20 +47,18 @@ export default function Apps(props) { }); }, []); + //地図表示テキスト const injectJavascript = injectJavascriptData(mapSwitch, iconSetting); useEffect(() => { + //ニュース表示 AsyncStorage.getItem("status") .then((d) => { - if (d != news) { - navigate("news"); - } + if (d != news) navigate("news"); }) - .catch((e) => { - navigate("news"); - }); - }, []); - useEffect(() => { + .catch((e) => navigate("news")); + + //列車アイコンスイッチ AsyncStorage.getItem("iconSwitch") .then((d) => { if (d) { @@ -67,6 +75,7 @@ export default function Apps(props) { ) ); + //地図スイッチ AsyncStorage.getItem("mapSwitch") .then((d) => { if (d) { @@ -133,7 +142,9 @@ export default function Apps(props) { injectedJavaScript={injectJavascript} /> navigate("trainMenu", { webview, stationData })} + onPress={() => + navigate("trainMenu", { webview, stationData: mapsStationData }) + } style={{ position: "absolute", top: Platform.OS == "ios" ? Constants.statusBarHeight : 0, diff --git a/lib/getStationList2.js b/lib/getStationList2.js new file mode 100644 index 0000000..8de3a41 --- /dev/null +++ b/lib/getStationList2.js @@ -0,0 +1,55 @@ +let status = undefined; +export const getStationList2 = async (props) => { + if (status) return status; + const HeaderConfig = { + headers: { referer: "https://train.jr-shikoku.co.jp/sp.html" }, + }; + + return await Promise.all([ + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=yosan", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima2", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan2", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=koutoku", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=tokushima", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=naruto", + HeaderConfig + ).then((response) => response.json()), + ]).then((values) => { + let stationList = {}; + [ + stationList.yosan, + stationList.uwajima, + stationList.uwajima2, + stationList.dosan, + stationList.dosan2, + stationList.koutoku, + stationList.tokushima, + stationList.naruto, + ] = values; + return stationList; + }); +}; From dd78cdd3c7274df23c25c0365d14e3e0a480733d Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sun, 9 Oct 2022 00:31:05 +0900 Subject: [PATCH 05/15] =?UTF-8?q?=E9=A7=85=E3=83=A1=E3=83=8B=E3=83=A5?= =?UTF-8?q?=E3=83=BC=E3=81=AE=E6=A9=9F=E8=83=BD=E6=BA=96=E5=82=99=E5=AE=8C?= =?UTF-8?q?=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Apps.js | 51 +++++++++++++++++++++++++++++++++++++++++++-------- menu.js | 9 --------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Apps.js b/Apps.js index 6c215ba..e45574c 100644 --- a/Apps.js +++ b/Apps.js @@ -38,15 +38,47 @@ export default function Apps(props) { //駅情報画面用 const StationBoardAcSR = useRef(null); - const [currentStation, setCurrentStation] = useState(undefined); + const [stationBoardData, setStationBoardData] = useState(undefined); const [originalStationList, setOriginalStationList] = useState(); + const [selectedStation, setSelectedStation] = useState(undefined); useEffect(() => { - getStationList().then((stationList) => { - console.log(stationList); - setOriginalStationList(stationList); - }); + 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]); + //地図表示テキスト const injectJavascript = injectJavascriptData(mapSwitch, iconSetting); @@ -142,8 +174,11 @@ export default function Apps(props) { injectedJavaScript={injectJavascript} /> - navigate("trainMenu", { webview, stationData: mapsStationData }) + onPress={ + () => navigate("trainMenu", { webview, stationData: mapsStationData }) + /* { + setSelectedStation("松山"); + } */ } style={{ position: "absolute", @@ -180,7 +215,7 @@ export default function Apps(props) { diff --git a/menu.js b/menu.js index 3702776..1386db1 100644 --- a/menu.js +++ b/menu.js @@ -117,15 +117,6 @@ export default function Menu(props) { "徳島線", "鳴門線", ]; - console.log( - lineList - .map((d) => findStationEachLine(originalStationList[d])) - .filter((d) => d.length > 0) - .reduce((pre, current) => { - pre.push(...current); - return pre; - }, []) - ); let returnDataBase = lineList .map((d) => findStationEachLine(originalStationList[d])) .filter((d) => d.length > 0) From 762195e8e8a0e16e2ed21aa0a227f400e8c19706 Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Mon, 10 Oct 2022 15:05:06 +0900 Subject: [PATCH 06/15] =?UTF-8?q?=E5=88=97=E8=BB=8A=E9=81=85=E5=BB=B6?= =?UTF-8?q?=E9=80=9F=E5=A0=B1EX=E3=82=92=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ActionSheetComponents/JRSTraInfo.js | 167 ++++++++++++++++++ menu.js | 142 +-------------- 2 files changed, 176 insertions(+), 133 deletions(-) create mode 100644 components/ActionSheetComponents/JRSTraInfo.js diff --git a/components/ActionSheetComponents/JRSTraInfo.js b/components/ActionSheetComponents/JRSTraInfo.js new file mode 100644 index 0000000..a333206 --- /dev/null +++ b/components/ActionSheetComponents/JRSTraInfo.js @@ -0,0 +1,167 @@ +import React, { Component, useRef, useState, useEffect } from "react"; +import { + StatusBar, + Platform, + View, + LayoutAnimation, + ScrollView, + Linking, + Text, + TouchableOpacity, +} from "react-native"; +import Image from "react-native-remote-svg"; +import Constants from "expo-constants"; +import { List, ListItem } from "native-base"; +import Icon from "react-native-vector-icons/Entypo"; +import * as Location from "expo-location"; +import StatusbarDetect from "../../StatusbarDetect"; +var Status = StatusbarDetect(); +import { useNavigation } from "@react-navigation/native"; +import AutoHeightImage from "react-native-auto-height-image"; +import { + widthPercentageToDP as wp, + heightPercentageToDP as hp, +} from "react-native-responsive-screen"; +import { + FontAwesome, + Fontisto, + Foundation, + Ionicons, + MaterialCommunityIcons, +} from "@expo/vector-icons"; +import * as WebBrowser from "expo-web-browser"; +import ActionSheet from "react-native-actions-sheet"; +import LottieView from "lottie-react-native"; +import SvgUri from "react-native-svg-uri"; +export const JRSTraInfo = (props) => { + const { + JRSTraInfoEXAcSR, + getTime, + loadingDelayData, + setLoadingDelayData, + delayData, + LottieRef2, + } = props; + return ( + {}} + > + + + + + + + 列車遅延速報EX + + + {/* {doFetch()}}> + 最新の情報へ更新 + */} + + {getTime + ? getTime.toLocaleTimeString("ja-JP").split(":")[0] + + ":" + + getTime.toLocaleTimeString("ja-JP").split(":")[1] + : NaN}{" "} + + { + LayoutAnimation.easeInEaseOut(), setLoadingDelayData(true); + }} + /> + + + + {loadingDelayData ? ( + + + + ) : delayData ? ( + delayData.map((d) => { + let data = d.split(" "); + return ( + + + {data[0].replace("\n", "")} + + {data[1]} + {data[3]} + + ); + }) + ) : ( + 現在、5分以上の遅れはありません。 + )} + + + + + 列車遅延情報EXについて + + + 列車遅延情報をJR四国公式列車運行情報より5分毎に取得します。Twitterにて投稿している内容と同一のものとなります。 + + + Linking.openURL("https://twitter.com/JRSTrainfoEX")} + > + + + + TwitterBOTはこちら! + + + + → + + + + + + ); +}; diff --git a/menu.js b/menu.js index 1386db1..05694ae 100644 --- a/menu.js +++ b/menu.js @@ -48,6 +48,7 @@ import { UsefulBox } from "./components/atom/UsefulBox"; import { TicketBox } from "./components/atom/TicketBox"; import { TextBox } from "./components/atom/TextBox"; import { getStationList } from "./lib/getStationList"; +import { JRSTraInfo } from "./components/ActionSheetComponents/JRSTraInfo"; export default function Menu(props) { const { @@ -136,11 +137,6 @@ export default function Menu(props) { } }, [location, originalStationList]); - useEffect(() => { - console.log("test"); - console.log(currentStation); - }, [currentStation]); - const LottieRef = useRef(null); const LottieRef2 = useRef(null); const [count, setCount] = useState(0); @@ -636,134 +632,14 @@ export default function Menu(props) { currentStation={currentStation} originalStationList={originalStationList} /> - {}} - > - - - - - - - 列車遅延速報EX - - - {/* {doFetch()}}> - 最新の情報へ更新 - */} - - {getTime - ? getTime.toLocaleTimeString("ja-JP").split(":")[0] + - ":" + - getTime.toLocaleTimeString("ja-JP").split(":")[1] - : NaN}{" "} - - { - LayoutAnimation.easeInEaseOut(), setLoadingDelayData(true); - }} - /> - - - - {loadingDelayData ? ( - - - - ) : delayData ? ( - delayData.map((d) => { - let data = d.split(" "); - return ( - - - {data[0].replace("\n", "")} - - {data[1]} - {data[3]} - - ); - }) - ) : ( - 現在、5分以上の遅れはありません。 - )} - - - - - 列車遅延情報EXについて - - - 列車遅延情報をJR四国公式列車運行情報より5分毎に取得します。Twitterにて投稿している内容と同一のものとなります。 - - - - Linking.openURL("https://twitter.com/JRSTrainfoEX") - } - > - - - - TwitterBOTはこちら! - - - - → - - - - - + ); } From 4d921854c9df82f13895984cfde1c55157d96c0e Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Mon, 10 Oct 2022 19:14:03 +0900 Subject: [PATCH 07/15] =?UTF-8?q?=E8=B6=85=E3=83=AA=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/発車時刻表/LED_vidion.js | 302 ++++++++++------------- menu.js | 123 +++++---- 2 files changed, 194 insertions(+), 231 deletions(-) diff --git a/components/発車時刻表/LED_vidion.js b/components/発車時刻表/LED_vidion.js index 5c0c632..2b2759b 100644 --- a/components/発車時刻表/LED_vidion.js +++ b/components/発車時刻表/LED_vidion.js @@ -59,6 +59,7 @@ export default function LED_vision(props) { const [trainIDSwitch, setTrainIDSwitch] = useState(false); const [trainDescriptionSwitch, setTrainDescriptionSwitch] = useState(false); useEffect(() => { + console.log("LED"); fetch( "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=traintimeinfo&arg3=dia", HeaderConfig @@ -66,49 +67,47 @@ export default function LED_vision(props) { .then((response) => response.text()) .then((d) => { const val = d.replace("[\r\n", "").split(",\r\n"); - let returnData = {}; + let trainDiagram = {}; val.forEach((element) => { try { let data = JSON.parse(element); - Object.keys(data).forEach((key) => (returnData[key] = data[key])); + Object.keys(data).forEach((key) => (trainDiagram[key] = data[key])); } catch (e) {} }); - return returnData; + setTrainDiagram(trainDiagram); + return trainDiagram; }) .then((trainDiagram) => { let returnData = {}; - if (trainDiagram) { - Object.keys(trainDiagram).forEach((key) => { - if (trainDiagram[key].match(props.station.Station_JP)) { - returnData[key] = trainDiagram[key]; - } - }); + if (!trainDiagram) { + setStationDiagram(returnData); + return; } - setTrainDiagram(trainDiagram); + Object.keys(trainDiagram).forEach((key) => { + if (trainDiagram[key].match(props.station.Station_JP)) { + returnData[key] = trainDiagram[key]; + } + }); setStationDiagram(returnData); }); }, []); const getTime = () => { const returnData = []; - const date = new Date(); Object.keys(stationDiagram).forEach((d) => { - let a = (() => { - let returnData = {}; - stationDiagram[d].split("#").forEach((data) => { - if (data.match("着")) { - returnData.lastStation = data.split(",着,")[0]; + let a = {}; + stationDiagram[d].split("#").forEach((data) => { + if (data.match("着")) { + a.lastStation = data.split(",着,")[0]; + } + if (data.match(props.station.Station_JP)) { + if (data.match(",発,")) { + a.time = data.split(",発,")[1]; + } else { + a.time = data.split(",着,")[1]; + a.lastStation = "当駅止"; } - if (data.match(props.station.Station_JP)) { - if (data.match(",発,")) { - returnData.time = data.split(",発,")[1]; - } else { - returnData.time = data.split(",着,")[1]; - returnData.lastStation = "当駅止"; - } - } - }); - return returnData; - })(); + } + }); returnData.push({ train: d, time: a.time, lastStation: a.lastStation }); }); @@ -141,42 +140,26 @@ export default function LED_vision(props) { .then((d) => d.map((x) => ({ num: x.TrainNum, delay: x.delay }))) .then((d) => setCurrentTrain(d)); getCurrentTrain(); - const currentTrainInterval = setInterval(() => getCurrentTrain(), 15000); + const currentTrainInterval = setInterval(getCurrentTrain, 15000); return () => clearInterval(currentTrainInterval); }, []); - const filtering = (d) => currentTrain.map((m) => m.num).includes(d.train); - console.log(new Date()); const timeFiltering = (d) => { const date = new Date(); const newDate = new Date(); let data = d.time.split(":"); - let delay = isNaN( - currentTrain.filter((data) => data.num == d.train)[0].delay - ) + let delay = isNaN(currentTrain.filter((t) => t.num == d.train)[0].delay) ? 0 - : currentTrain.filter((data) => data.num == d.train)[0].delay; + : currentTrain.filter((t) => t.num == d.train)[0].delay; date.setHours(parseInt(data[0])); date.setMinutes(parseInt(data[1]) + parseInt(delay)); - console.log(date); - console.log(newDate); if (!(newDate > date)) { return true; } return false; }; - const finalFiltering = (d) => { - if (finalSwitch) { - return true; - } else { - if (d.lastStation == "当駅止") { - return false; - } - return true; - } - }; return ( currentTrain.map((m) => m.num).includes(d.train)) .filter(timeFiltering) - .filter(finalFiltering) - .map((d, index) => [ - - - { - if ( - customTrainDataDetector(d.train).trainName.length > 6 - ) { - return 15; - } else { - return 20; - } - })(), - color: (() => { - switch (customTrainDataDetector(d.train).type) { - case "Rapid": - return "aqua"; - case "LTDEXP": - return "red"; - case "NightLTDEXP": - return "red"; - case "Normal": - return "white"; - } - })(), - fontWeight: "bold", - }} - > - {trainIDSwitch - ? d.train - : (() => { - switch (customTrainDataDetector(d.train).type) { + .filter((d) => !!finalSwitch || d.lastStation != "当駅止") + .map((d, index) => { + const train = customTrainDataDetector(d.train); + return [ + + + 6 ? 15 : 20, + color: (() => { + switch (train.type) { case "Rapid": - return "快速"; + return "aqua"; case "LTDEXP": - return "特急"; + return "red"; case "NightLTDEXP": - return "寝台特急"; + return "red"; case "Normal": - return "普通列車"; + return "white"; } - })() + - " " + - customTrainDataDetector(d.train).trainName + - (() => { - if ( - customTrainDataDetector(d.train).trainNumDistance != - null - ) { - return ( - parseInt( + })(), + fontWeight: "bold", + }} + > + {trainIDSwitch + ? d.train + : (() => { + switch (train.type) { + case "Rapid": + return "快速"; + case "LTDEXP": + return "特急"; + case "NightLTDEXP": + return "寝台特急"; + case "Normal": + return "普通列車"; + } + })() + + " " + + train.trainName + + (!train.trainNumDistance + ? "" + : parseInt( d.train.replace("M", "").replace("D", "") ) - - customTrainDataDetector(d.train) - .trainNumDistance + - "号" - ); - } else { - return ""; - } - })()} - - - - 4 ? 15 : 20, - color: "white", - fontWeight: "bold", - }} - > - {d.lastStation} - - - - - {d.time} - - - - - {(() => { - let data = currentTrain.filter( - (data) => data.num == d.train - )[0].delay; - if (isNaN(data)) { - return data; - } else if (data == 0) { - return "定刻通り"; - } else { - return data + "分遅れ"; - } - })()} - - - , - Boolean(trainDescriptionSwitch) && - Boolean(customTrainDataDetector(d.train).info) && ( + train.trainNumDistance + + "号")} + + + + 4 ? 15 : 20, + color: "white", + fontWeight: "bold", + }} + > + {d.lastStation} + + + + + {d.time} + + + + + {(() => { + const delay = currentTrain.filter( + (a) => a.num == d.train + )[0].delay; + switch (true) { + case isNaN(delay): + return delay; + case delay == 0: + return "定刻通り"; + default: + return delay + "分遅れ"; + } + })()} + + + , + trainDescriptionSwitch && !!train.info && ( {" "} - > {customTrainDataDetector(d.train).info} + > {train.info} ), - ]) + ]; + }) : null} 種別名 / 列番 - setTrainIDSwitch(!trainIDSwitch)} - /> + - setTrainDescriptionSwitch(!trainDescriptionSwitch) - } + onValueChange={setTrainDescriptionSwitch} /> 当駅止表示 - setFinalSwitch(!finalSwitch)} - /> + ); diff --git a/menu.js b/menu.js index 05694ae..660f483 100644 --- a/menu.js +++ b/menu.js @@ -15,7 +15,6 @@ import { List, ListItem } from "native-base"; import Icon from "react-native-vector-icons/Entypo"; import * as Location from "expo-location"; import StatusbarDetect from "./StatusbarDetect"; -var Status = StatusbarDetect(); import { useNavigation } from "@react-navigation/native"; import AutoHeightImage from "react-native-auto-height-image"; import { @@ -173,7 +172,7 @@ export default function Menu(props) { paddingTop: Platform.OS == "ios" ? Constants.statusBarHeight : 0, }} > - {Status} + Linking.openURL("https://www.jr-shikoku.co.jp")} @@ -514,7 +513,7 @@ export default function Menu(props) { size={30} /> - 公式Twitter一族 + JR四国公式Twitter一族 - - Linking.openURL("https://twitter.com/JRshikoku_tokyo") - } - > - JR四国 東京営業情報【公式】 - - - - - Linking.openURL("https://twitter.com/JRshikoku_osaka") - } - > - JR四国 大阪営業部【公式】 - - - - Linking.openURL("https://twitter.com/shikoku_DC")} - > - JR四国営業部 四国DC情報【公式】 - - - - - Linking.openURL("https://twitter.com/jr_shikoku_info") - } - > - JR四国運行情報Twitter - - - - - Linking.openURL("https://twitter.com/Smile_Eki_Chan") - } - > - JR四国いそうろう妖精 すまいるえきちゃん♡【公式】 - - - - - Linking.openURL("https://twitter.com/JR_Shikoku_DPT") - } - > - JR四国デザインPT♡ - - - - Linking.openURL("https://twitter.com/PT2nd_Yuki")} - > - JR四国デザインPT弐号◇ - - - + {((data) => + data.map((d) => ( + Linking.openURL(d.url)}> + {d.name} + + + + )))([ + { + url: "https://twitter.com/JRshikoku_eigyo", + name: "JR四国営業部【公式】", + }, + { + url: "https://twitter.com/JRshikoku_tokyo", + name: "JR四国 東京営業情報【公式】", + }, + { + url: "https://twitter.com/JRshikoku_osaka", + name: "JR四国 大阪営業部【公式】", + }, + { + url: "https://twitter.com/jr_shikoku_info", + name: "JR四国列車運行情報【公式】", + }, + { + url: "https://twitter.com/Smile_Eki_Chan", + name: "すまいるえきちゃん♡JR四国【公式】", + }, + { + url: "https://twitter.com/jrs_matsuyama", + name: "JR四国 松山駅 【公式】", + }, + { + url: "https://twitter.com/jrshikoku_kochi", + name: "JR四国 高知駅【公式】", + }, + { + url: "https://twitter.com/jr_tokust", + name: "JR四国 徳島駅【公式】", + }, + { + url: "https://twitter.com/jrshikoku_uwjm", + name: "JR四国 宇和島駅【公式】", + }, + { + url: "https://twitter.com/JRshikoku_wkoch", + name: "JR四国 ワープ高知支店【公式】", + }, + { + url: "https://twitter.com/jrshikoku_nihaw", + name: "JR四国 ワープ新居浜営業所【公式】", + }, + { + url: "https://twitter.com/Yoakemonogatari", + name: "志国土佐 時代の夜明けのものがたり【公式】", + }, + ])} @@ -592,8 +589,6 @@ export default function Menu(props) { このアプリはXprocess(HARUKIN)が製作しているJR四国の完全非公式アシストアプリケーションです。このアプリに関することでのJR四国公式へ問合せすることはお控えください。以下のTwitterよりお願いします。 - 2022/4/14 4.1公開!列車アイコン表示が開始しました。 - 2021/6/23 4.0公開!ホーム画面を大改造しました。 Date: Mon, 10 Oct 2022 19:26:15 +0900 Subject: [PATCH 08/15] =?UTF-8?q?=E5=B0=8F=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/発車時刻表/LED_vidion.js | 25 +++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/components/発車時刻表/LED_vidion.js b/components/発車時刻表/LED_vidion.js index 2b2759b..7b426e3 100644 --- a/components/発車時刻表/LED_vidion.js +++ b/components/発車時刻表/LED_vidion.js @@ -58,6 +58,7 @@ export default function LED_vision(props) { const [finalSwitch, setFinalSwitch] = useState(false); const [trainIDSwitch, setTrainIDSwitch] = useState(false); const [trainDescriptionSwitch, setTrainDescriptionSwitch] = useState(false); + useEffect(() => { console.log("LED"); fetch( @@ -91,6 +92,7 @@ export default function LED_vision(props) { setStationDiagram(returnData); }); }, []); + const getTime = () => { const returnData = []; Object.keys(stationDiagram).forEach((d) => { @@ -112,20 +114,15 @@ export default function LED_vision(props) { }); return returnData.sort((a, b) => { - if (parseInt(a.time.split(":")[0]) < parseInt(b.time.split(":")[0])) { - return -1; - } else if ( - parseInt(a.time.split(":")[0]) > parseInt(b.time.split(":")[0]) - ) { - return 1; - } else if ( - parseInt(a.time.split(":")[1]) < parseInt(b.time.split(":")[1]) - ) { - return -1; - } else if ( - parseInt(a.time.split(":")[1]) > parseInt(b.time.split(":")[1]) - ) { - return 1; + switch (true) { + case parseInt(a.time.split(":")[0]) < parseInt(b.time.split(":")[0]): + return -1; + case parseInt(a.time.split(":")[0]) > parseInt(b.time.split(":")[0]): + return 1; + case parseInt(a.time.split(":")[1]) < parseInt(b.time.split(":")[1]): + return -1; + case parseInt(a.time.split(":")[1]) > parseInt(b.time.split(":")[1]): + return 1; } }); }; From 8d5ad6e50e3141cadb9f72bbddc58336f18f5592 Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sat, 5 Nov 2022 19:11:14 +0900 Subject: [PATCH 09/15] =?UTF-8?q?=E8=B7=AF=E7=B7=9A=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E3=81=AB=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" && } From 48a8dba1c099169f953d41ccf81d4e5c7a5378b8 Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sat, 5 Nov 2022 20:38:47 +0900 Subject: [PATCH 10/15] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.js | 60 ++--- Apps.js | 7 +- TestArea.js | 72 ------ components/駅名表/Sign.js | 419 +++++++++++++++-------------------- 4 files changed, 200 insertions(+), 358 deletions(-) delete mode 100644 TestArea.js diff --git a/App.js b/App.js index d25b83c..ffc9ddf 100644 --- a/App.js +++ b/App.js @@ -14,7 +14,6 @@ import trainbase from "./trainbaseview"; import howto from "./howto"; import menu from "./menu"; import News from "./components/news.js"; -import TestArea from "./TestArea.js"; import Setting from "./components/settings.js"; import trainMenu from "./components/trainMenu.js"; const Stack = createStackNavigator(); @@ -26,7 +25,6 @@ if (Platform.OS === "android") { } export default function App() { const navigationRef = useRef(); - var platform = Platform.OS === "android" ? 70 : 50; useEffect(() => UpdateAsync(), []); return ( @@ -38,9 +36,7 @@ export default function App() { tabBarLabel: "位置情報", headerTransparent: true, gestureEnabled: true, - tabBarIcon: ({ color, size }) => ( - - ), + tabBarIcon: () => , }} /> ( - - ), + tabBarIcon: () => , }} /> ( - - ), + tabBarIcon: () => , }} /> @@ -97,35 +89,14 @@ function top() { component={howto} options={{ title: "使い方", - gestureEnabled: true, - ...TransitionPresets.ModalPresentationIOS, - cardOverlayEnabled: true, - headerTransparent: true, - headerShown: false, - }} - /> - - + ); @@ -142,17 +113,14 @@ function menuPage() { headerTransparent: true, }} /> - + ); } +const optionData = { + gestureEnabled: true, + ...TransitionPresets.ModalPresentationIOS, + cardOverlayEnabled: true, + headerTransparent: true, + headerShown: false, +}; diff --git a/Apps.js b/Apps.js index f95a933..ae40bf8 100644 --- a/Apps.js +++ b/Apps.js @@ -201,11 +201,8 @@ export default function Apps(props) { injectedJavaScript={injectJavascript} /> navigate("trainMenu", { webview, stationData: mapsStationData }) - /* { - setSelectedStation("松山"); - } */ + onPress={() => + navigate("trainMenu", { webview, stationData: mapsStationData }) } style={{ position: "absolute", diff --git a/TestArea.js b/TestArea.js deleted file mode 100644 index 3d56eb3..0000000 --- a/TestArea.js +++ /dev/null @@ -1,72 +0,0 @@ -import React, { Component, useEffect, useState } from "react"; -import { StatusBar, View, ScrollView, Linking, Text } from "react-native"; -import Constants from "expo-constants"; -import { ListItem } from "react-native-elements"; -import Icon from "react-native-vector-icons/Entypo"; -import StatusbarDetect from "./StatusbarDetect"; -var Status = StatusbarDetect(); -let a = []; -export default function TestArea(props) { - const [data, setdata] = useState(null); - useEffect(() => { - data == null - ? test().then((res) => { - setdata(res); - }) - : null; - }, [data]); - return ( - - {Status} - - TEST AREA!! - {data} - - - ); -} - -async function test() { - return fetch("https://train.jr-shikoku.co.jp/g?arg1=train&arg2=train", { - headers: { - authority: "train.jr-shikoku.co.jp", - "cache-control": "no-cache", - pragma: "no-cache", - "if-modified-since": "Thu, 01 Jun 1970 00:00:00 GMT", - accept: "*/*", - "sec-fetch-site": "same-origin", - "sec-fetch-mode": "cors", - referer: "https://train.jr-shikoku.co.jp/sp.html", - }, - }) - .then((res) => res.json()) - .then((D) => { - let d = []; - D.forEach((element) => { - d.push( - - ); - }); - a = d; - return d; - }); -} diff --git a/components/駅名表/Sign.js b/components/駅名表/Sign.js index 6f57011..ccbc20a 100644 --- a/components/駅名表/Sign.js +++ b/components/駅名表/Sign.js @@ -58,252 +58,61 @@ export default function Sign(props) { } }, [currentStation]); return ( - !stationName.今.JrHpUrl || Linking.openURL(stationName.今.JrHpUrl)} */ - onPress={oP} - > - - - JR - - {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} - - - ))} - - - - {/* {stationName.今.LineName} */} - - {currentStation[0].Station_JP} - - - {currentStation[0].Station_EN} - - - - - + + + + JR + + { currentStation.map((currentStation) => { let [preStation, nexStation] = getPreNextStation(currentStation); return ( - - - {preStation && [ - - ◀ - , - preStation.StationNumber != " " && ( - + + + {preStation && ( + <> + + {preStation.StationNumber != " " && ( + + + + {preStation.StationNumber} + + + + )} + + + )} + + + {nexStation && ( + <> + + - {preStation.StationNumber} + {nexStation.StationNumber} - ), - - - {preStation.Station_JP} - - - {preStation.Station_EN} - - , - ]} - - - {nexStation && [ - - - {nexStation.Station_JP} - - - {nexStation.Station_EN} - - , - - - - {nexStation.StationNumber} - - - , - - ▶ - , - ]} + + + )} ); @@ -313,3 +122,143 @@ export default function Sign(props) { ); } + +const StationNumberMaker = (props) => { + return props.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} + + + )); +}; + +const StationNameArea = (props) => { + const { currentStation } = props; + return ( + + + + {/* {stationName.今.LineName} */} + + {currentStation[0].Station_JP} + + + {currentStation[0].Station_EN} + + + + + ); +}; + +const StationName = (props) => { + const { stringData, ss } = props; + return ( + + {stringData.Station_JP} + {stringData.Station_EN} + + ); +}; + +const styleSheet = { + 外枠: { + width: wp("80%"), + height: (wp("80%") / 20) * 9, + borderColor: "#2E94BB", + borderWidth: 1, + margin: 10, + marginHorizontal: wp("10%"), + }, + 下帯: { + position: "absolute", + bottom: "0%", + left: "0%", + width: "100%", + height: "30%", + backgroundColor: "#2E94BB", + }, + JRStyle: { + position: "absolute", + top: "2%", + left: "2%", + fontWeight: "bold", + fontSize: parseInt("30%"), + color: "#2E94BB", + }, + stationNameAreaOverWrap: { + position: "absolute", + top: "10%", + alignContent: "center", + flexDirection: "row", + }, + Station_JP: { + fontWeight: "bold", + fontSize: parseInt("40%"), + color: "#005170", + }, + Station_EN: { + fontWeight: "bold", + fontSize: parseInt("15%"), + color: "#005170", + }, + 下帯内容: { + position: "absolute", + bottom: "0%", + height: "30%", + width: "100%", + alignItems: "center", + flexDirection: "column", + }, + 下枠フレーム: { + flex: 1, + flexDirection: "row", + alignContent: "center", + }, + 下枠左右マーク: { + fontWeight: "bold", + fontSize: parseInt("20%"), + color: "white", + paddingHorizontal: 10, + textAlignVertical: "center", + }, + 下枠駅ナンバー: { + alignContent: "center", + alignItems: "center", + width: wp("8%"), + height: wp("8%"), + margin: wp("1%"), + borderColor: "white", + borderWidth: parseInt("2%"), + borderRadius: parseInt("100%"), + }, + 下枠駅名: { + fontWeight: "bold", + fontSize: parseInt("15%"), + color: "white", + flex: 1, + textAlignVertical: "center", + }, +}; From 343a0ad06e7d37d053c4c51fe241b72143400bdc Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sat, 5 Nov 2022 22:11:23 +0900 Subject: [PATCH 11/15] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.js | 2 +- components/settings.js | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/App.js b/App.js index ffc9ddf..f03ea13 100644 --- a/App.js +++ b/App.js @@ -25,7 +25,7 @@ if (Platform.OS === "android") { } export default function App() { const navigationRef = useRef(); - useEffect(() => UpdateAsync(), []); + useEffect(UpdateAsync, []); return ( diff --git a/components/settings.js b/components/settings.js index 80d5092..c0cd1a4 100644 --- a/components/settings.js +++ b/components/settings.js @@ -14,15 +14,9 @@ export default function Setting(props) { const [mapSwitch, setMapSwitch] = useState(undefined); const [stationMenu, setStationMenu] = useState(undefined); useEffect(() => { - AsyncStorage.getItem("iconSwitch").then((d) => { - setIconSetting(d); - }); - AsyncStorage.getItem("mapSwitch").then((d) => { - setMapSwitch(d); - }); - AsyncStorage.getItem("stationSwitch").then((d) => { - setStationMenu(d); - }); + AsyncStorage.getItem("iconSwitch").then(setIconSetting); + AsyncStorage.getItem("mapSwitch").then(setMapSwitch); + AsyncStorage.getItem("stationSwitch").then(setStationMenu); }, []); return ( From 75b5f9b3269d2a791f78ad2e044b3adb63b0d980 Mon Sep 17 00:00:00 2001 From: harukin-OneMix4 Date: Fri, 18 Nov 2022 19:28:40 +0900 Subject: [PATCH 12/15] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AB=E3=81=AA?= =?UTF-8?q?=E3=81=A3=E3=81=9FLottieRef=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ActionSheetComponents/JRSTraInfo.js | 10 +- menu.js | 128 ++++++++---------- 2 files changed, 63 insertions(+), 75 deletions(-) diff --git a/components/ActionSheetComponents/JRSTraInfo.js b/components/ActionSheetComponents/JRSTraInfo.js index a333206..3444367 100644 --- a/components/ActionSheetComponents/JRSTraInfo.js +++ b/components/ActionSheetComponents/JRSTraInfo.js @@ -40,13 +40,12 @@ export const JRSTraInfo = (props) => { loadingDelayData, setLoadingDelayData, delayData, - LottieRef2, } = props; return ( {}} + CustomHeaderComponent={() => { }} > { {getTime ? getTime.toLocaleTimeString("ja-JP").split(":")[0] + - ":" + - getTime.toLocaleTimeString("ja-JP").split(":")[1] + ":" + + getTime.toLocaleTimeString("ja-JP").split(":")[1] : NaN}{" "} { {loadingDelayData ? ( diff --git a/menu.js b/menu.js index b651dd3..f1d1633 100644 --- a/menu.js +++ b/menu.js @@ -64,7 +64,7 @@ export default function Menu(props) { Location.requestForegroundPermissionsAsync().then((data) => { if (data.status !== "granted") { setErrorMsg("Permission to access location was denied"); - return () => {}; + return () => { }; } Location.getCurrentPositionAsync({}).then((location) => setLocation(location) @@ -87,8 +87,8 @@ export default function Menu(props) { const [stationName, setStationName] = useState(undefined); const [currentStation, setCurrentStation] = useState(undefined); useEffect(() => { - if (!location) return () => {}; - if (!originalStationList) return () => {}; + if (!location) return () => { }; + if (!originalStationList) return () => { }; const findStationEachLine = (selectLine) => { const searchArea = 0.0015; const _calcDistance = (from, to) => { @@ -136,8 +136,6 @@ export default function Menu(props) { } }, [location, originalStationList]); - const LottieRef = useRef(null); - const LottieRef2 = useRef(null); const [count, setCount] = useState(0); const [delayData, setDelayData] = useState(undefined); const [getTime, setGetTime] = useState(new Date()); @@ -148,22 +146,12 @@ export default function Menu(props) { "https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec" ) .then((response) => response.text()) - .then((data) => { - if (data != "") { - setDelayData(data.split("^")); - } else setDelayData(null); - }) - .then((data) => LayoutAnimation.easeInEaseOut()) + .then(data => setDelayData(data !== "" ? data.split("^") : null)) + .then(() => LayoutAnimation.easeInEaseOut()) .then(() => setGetTime(new Date())) .finally(() => setLoadingDelayData(false)); }, [loadingDelayData]); - useEffect(() => { - try { - LottieRef?.current.play(); - LottieRef2?.current.play(); - } catch (e) {} - }); return ( {getTime ? getTime.toLocaleTimeString("ja-JP").split(":")[0] + - ":" + - getTime.toLocaleTimeString("ja-JP").split(":")[1] + ":" + + getTime.toLocaleTimeString("ja-JP").split(":")[1] : NaN} )))([ - { - url: "https://twitter.com/JRshikoku_eigyo", - name: "JR四国営業部【公式】", - }, - { - url: "https://twitter.com/JRshikoku_tokyo", - name: "JR四国 東京営業情報【公式】", - }, - { - url: "https://twitter.com/JRshikoku_osaka", - name: "JR四国 大阪営業部【公式】", - }, - { - url: "https://twitter.com/jr_shikoku_info", - name: "JR四国列車運行情報【公式】", - }, - { - url: "https://twitter.com/Smile_Eki_Chan", - name: "すまいるえきちゃん♡JR四国【公式】", - }, - { - url: "https://twitter.com/jrs_matsuyama", - name: "JR四国 松山駅 【公式】", - }, - { - url: "https://twitter.com/jrshikoku_kochi", - name: "JR四国 高知駅【公式】", - }, - { - url: "https://twitter.com/jr_tokust", - name: "JR四国 徳島駅【公式】", - }, - { - url: "https://twitter.com/jrshikoku_uwjm", - name: "JR四国 宇和島駅【公式】", - }, - { - url: "https://twitter.com/JRshikoku_wkoch", - name: "JR四国 ワープ高知支店【公式】", - }, - { - url: "https://twitter.com/jrshikoku_nihaw", - name: "JR四国 ワープ新居浜営業所【公式】", - }, - { - url: "https://twitter.com/Yoakemonogatari", - name: "志国土佐 時代の夜明けのものがたり【公式】", - }, - ])} + { + url: "https://twitter.com/JRshikoku_eigyo", + name: "JR四国営業部【公式】", + }, + { + url: "https://twitter.com/JRshikoku_tokyo", + name: "JR四国 東京営業情報【公式】", + }, + { + url: "https://twitter.com/JRshikoku_osaka", + name: "JR四国 大阪営業部【公式】", + }, + { + url: "https://twitter.com/jr_shikoku_info", + name: "JR四国列車運行情報【公式】", + }, + { + url: "https://twitter.com/Smile_Eki_Chan", + name: "すまいるえきちゃん♡JR四国【公式】", + }, + { + url: "https://twitter.com/jrs_matsuyama", + name: "JR四国 松山駅 【公式】", + }, + { + url: "https://twitter.com/jrshikoku_kochi", + name: "JR四国 高知駅【公式】", + }, + { + url: "https://twitter.com/jr_tokust", + name: "JR四国 徳島駅【公式】", + }, + { + url: "https://twitter.com/jrshikoku_uwjm", + name: "JR四国 宇和島駅【公式】", + }, + { + url: "https://twitter.com/JRshikoku_wkoch", + name: "JR四国 ワープ高知支店【公式】", + }, + { + url: "https://twitter.com/jrshikoku_nihaw", + name: "JR四国 ワープ新居浜営業所【公式】", + }, + { + url: "https://twitter.com/Yoakemonogatari", + name: "志国土佐 時代の夜明けのものがたり【公式】", + }, + ])} @@ -633,7 +622,6 @@ export default function Menu(props) { loadingDelayData={loadingDelayData} setLoadingDelayData={setLoadingDelayData} delayData={delayData} - LottieRef2={LottieRef2} /> ); From 06c51022257416b128e766b240f53ebadd7a8cc2 Mon Sep 17 00:00:00 2001 From: harukin-OneMix4 Date: Fri, 18 Nov 2022 20:28:43 +0900 Subject: [PATCH 13/15] rererefactoring --- menu.js | 133 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 66 insertions(+), 67 deletions(-) diff --git a/menu.js b/menu.js index f1d1633..7539815 100644 --- a/menu.js +++ b/menu.js @@ -64,7 +64,7 @@ export default function Menu(props) { Location.requestForegroundPermissionsAsync().then((data) => { if (data.status !== "granted") { setErrorMsg("Permission to access location was denied"); - return () => { }; + return () => {}; } Location.getCurrentPositionAsync({}).then((location) => setLocation(location) @@ -87,8 +87,8 @@ export default function Menu(props) { const [stationName, setStationName] = useState(undefined); const [currentStation, setCurrentStation] = useState(undefined); useEffect(() => { - if (!location) return () => { }; - if (!originalStationList) return () => { }; + if (!location) return () => {}; + if (!originalStationList) return () => {}; const findStationEachLine = (selectLine) => { const searchArea = 0.0015; const _calcDistance = (from, to) => { @@ -146,7 +146,7 @@ export default function Menu(props) { "https://script.google.com/macros/s/AKfycbyKxch7z7l8e07LXulRHqxjVoIiB13kcgvoToLE-rqlxLmLSKdlmqz0FI1F2EuA7Zfg/exec" ) .then((response) => response.text()) - .then(data => setDelayData(data !== "" ? data.split("^") : null)) + .then((data) => setDelayData(data !== "" ? data.split("^") : null)) .then(() => LayoutAnimation.easeInEaseOut()) .then(() => setGetTime(new Date())) .finally(() => setLoadingDelayData(false)); @@ -224,18 +224,16 @@ export default function Menu(props) { {currentStation && ( - StationBoardAcSR.current?.setModalVisible()} - /> + <> + + + )} - {currentStation && } - { - JRSTraInfoEXAcSR.current?.setModalVisible(); - }} - > + {getTime ? getTime.toLocaleTimeString("ja-JP").split(":")[0] + - ":" + - getTime.toLocaleTimeString("ja-JP").split(":")[1] + ":" + + getTime.toLocaleTimeString("ja-JP").split(":")[1] : NaN} { - LayoutAnimation.easeInEaseOut(), setLoadingDelayData(true); + LayoutAnimation.easeInEaseOut(); + setLoadingDelayData(true); }} /> @@ -521,55 +520,55 @@ export default function Menu(props) { )))([ - { - url: "https://twitter.com/JRshikoku_eigyo", - name: "JR四国営業部【公式】", - }, - { - url: "https://twitter.com/JRshikoku_tokyo", - name: "JR四国 東京営業情報【公式】", - }, - { - url: "https://twitter.com/JRshikoku_osaka", - name: "JR四国 大阪営業部【公式】", - }, - { - url: "https://twitter.com/jr_shikoku_info", - name: "JR四国列車運行情報【公式】", - }, - { - url: "https://twitter.com/Smile_Eki_Chan", - name: "すまいるえきちゃん♡JR四国【公式】", - }, - { - url: "https://twitter.com/jrs_matsuyama", - name: "JR四国 松山駅 【公式】", - }, - { - url: "https://twitter.com/jrshikoku_kochi", - name: "JR四国 高知駅【公式】", - }, - { - url: "https://twitter.com/jr_tokust", - name: "JR四国 徳島駅【公式】", - }, - { - url: "https://twitter.com/jrshikoku_uwjm", - name: "JR四国 宇和島駅【公式】", - }, - { - url: "https://twitter.com/JRshikoku_wkoch", - name: "JR四国 ワープ高知支店【公式】", - }, - { - url: "https://twitter.com/jrshikoku_nihaw", - name: "JR四国 ワープ新居浜営業所【公式】", - }, - { - url: "https://twitter.com/Yoakemonogatari", - name: "志国土佐 時代の夜明けのものがたり【公式】", - }, - ])} + { + url: "https://twitter.com/JRshikoku_eigyo", + name: "JR四国営業部【公式】", + }, + { + url: "https://twitter.com/JRshikoku_tokyo", + name: "JR四国 東京営業情報【公式】", + }, + { + url: "https://twitter.com/JRshikoku_osaka", + name: "JR四国 大阪営業部【公式】", + }, + { + url: "https://twitter.com/jr_shikoku_info", + name: "JR四国列車運行情報【公式】", + }, + { + url: "https://twitter.com/Smile_Eki_Chan", + name: "すまいるえきちゃん♡JR四国【公式】", + }, + { + url: "https://twitter.com/jrs_matsuyama", + name: "JR四国 松山駅 【公式】", + }, + { + url: "https://twitter.com/jrshikoku_kochi", + name: "JR四国 高知駅【公式】", + }, + { + url: "https://twitter.com/jr_tokust", + name: "JR四国 徳島駅【公式】", + }, + { + url: "https://twitter.com/jrshikoku_uwjm", + name: "JR四国 宇和島駅【公式】", + }, + { + url: "https://twitter.com/JRshikoku_wkoch", + name: "JR四国 ワープ高知支店【公式】", + }, + { + url: "https://twitter.com/jrshikoku_nihaw", + name: "JR四国 ワープ新居浜営業所【公式】", + }, + { + url: "https://twitter.com/Yoakemonogatari", + name: "志国土佐 時代の夜明けのものがたり【公式】", + }, + ])} From 448b0696acee8f490f6772e1398c18f91a1a8590 Mon Sep 17 00:00:00 2001 From: harukin-OneMix4 Date: Sat, 19 Nov 2022 00:36:56 +0900 Subject: [PATCH 14/15] =?UTF-8?q?=E9=A7=85=E5=90=8D=E6=A8=99=E3=81=AE?= =?UTF-8?q?=E5=8B=95=E4=BD=9C=E3=81=8C=E4=B8=8D=E5=AE=8C=E5=85=A8=E3=81=A0?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/発車時刻表/LED_vidion.js | 26 +++--- components/駅名表/Sign.js | 112 +++++++++++------------ lib/getStationList.js | 46 ++++++++-- lib/useInterval.js | 45 +++++++++ 4 files changed, 150 insertions(+), 79 deletions(-) create mode 100644 lib/useInterval.js diff --git a/components/発車時刻表/LED_vidion.js b/components/発車時刻表/LED_vidion.js index cc9400c..6314246 100644 --- a/components/発車時刻表/LED_vidion.js +++ b/components/発車時刻表/LED_vidion.js @@ -14,6 +14,7 @@ import { heightPercentageToDP as hp, } from "react-native-responsive-screen"; import { customTrainDataDetector } from "../custom-train-data"; +import { useInterval } from "../../lib/useInterval"; let diagramData = undefined; @@ -126,19 +127,18 @@ export default function LED_vision(props) { }); }; const trainTimeAndNumber = stationDiagram != null ? getTime() : null; - useEffect(() => { - const getCurrentTrain = () => - fetch( - "https://train.jr-shikoku.co.jp/g?arg1=train&arg2=train", - HeaderConfig - ) - .then((response) => response.json()) - .then((d) => d.map((x) => ({ num: x.TrainNum, delay: x.delay }))) - .then((d) => setCurrentTrain(d)); - getCurrentTrain(); - const currentTrainInterval = setInterval(getCurrentTrain, 15000); - return () => clearInterval(currentTrainInterval); - }, []); + const getCurrentTrain = () => + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=train&arg2=train", + HeaderConfig + ) + .then((response) => response.json()) + .then((d) => d.map((x) => ({ num: x.TrainNum, delay: x.delay }))) + .then(setCurrentTrain); + + useEffect(getCurrentTrain, []); + + useInterval(getCurrentTrain, 15000); const timeFiltering = (d) => { const date = new Date(); diff --git a/components/駅名表/Sign.js b/components/駅名表/Sign.js index ccbc20a..4517c54 100644 --- a/components/駅名表/Sign.js +++ b/components/駅名表/Sign.js @@ -12,6 +12,7 @@ import { widthPercentageToDP as wp, heightPercentageToDP as hp, } from "react-native-responsive-screen"; +import { useInterval } from "../../lib/useInterval"; export default function Sign(props) { const { currentStation, originalStationList, oP } = props; @@ -42,21 +43,12 @@ export default function Sign(props) { return returnData; }; const [nexPrePosition, setNexPrePosition] = useState(0); - useEffect(() => { - if (currentStation) { - if (currentStation.length > 1) { - let stationCount = setInterval(() => { - LayoutAnimation.easeInEaseOut(); - if (nexPrePosition + 1 == currentStation.length) { - setNexPrePosition(0); - } else { - setNexPrePosition(nexPrePosition + 1); - } - }, 1000); - return () => clearInterval(stationCount); - } - } - }, [currentStation]); + useInterval(() => { + LayoutAnimation.easeInEaseOut(); + setNexPrePosition( + nexPrePosition + 1 == currentStation.length ? 0 : nexPrePosition + 1 + ); + }, 2000); return ( @@ -64,43 +56,45 @@ export default function Sign(props) { JR - { - currentStation.map((currentStation) => { - let [preStation, nexStation] = getPreNextStation(currentStation); - return ( + {(() => { + let [preStation, nexStation] = getPreNextStation( + currentStation[nexPrePosition] + ); + return ( + - - {preStation && ( - <> - - {preStation.StationNumber != " " && ( - - - - {preStation.StationNumber} - - - - )} - - - )} - - - {nexStation && ( - <> - + {preStation && ( + <> + + {preStation.StationNumber && ( + + + + {preStation.StationNumber} + + + + )} + + + )} + + + {nexStation && ( + <> + + {nexStation.StationNumber && ( - - - )} - + )} + + + )} - ); - })[nexPrePosition] - } + + ); + })()} ); @@ -125,7 +119,7 @@ export default function Sign(props) { const StationNumberMaker = (props) => { return props.currentStation - .filter((d) => (d.StationNumber != " " ? true : false)) + .filter((d) => (d.StationNumber ? true : false)) .map((d, index, array) => ( { 高徳線, stationList.日英対応表 ); - stationList.徳島線 = addStationPosition( - concatBetweenStations(stationList.徳島線), - 徳島線, - stationList.日英対応表 - ); stationList.鳴門線 = addStationPosition( concatBetweenStations(stationList.鳴門線), 鳴門線, stationList.日英対応表 - ); /* + ); + const tokushimaCurrent = addStationPosition( + concatBetweenStations(stationList.徳島線), + 徳島線, + stationList.日英対応表 + ); + stationList.徳島線 = [ + tokushimaCurrent[tokushimaCurrent.length - 1], + ...tokushimaCurrent, + ]; + stationList.徳島線.pop(); stationList.瀬戸大橋線 = [ + { + Station_JP: "坂出", + Station_EN: "Sakaide", + MyStation: "3", + StationNumber: null, + DispNum: "3", + StationTimeTable: + "http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/sakaide.pdf", + StationMap: "https://www.google.co.jp/maps/place/34.313222,133.856325", + JrHpUrl: "http://www.jr-shikoku.co.jp/01_trainbus/kakueki/sakaide/", + lat: 34.313222, + lng: 133.856325, + }, + { Station_JP: "児島", Station_EN: "Kojima", @@ -179,7 +198,20 @@ export const getStationList = async (props) => { lat: 34.462562, lng: 133.807809, }, - ]; */ + { + Station_JP: "宇多津", + Station_EN: "Utazu", + MyStation: "0", + StationNumber: null, + DispNum: "3", + StationTimeTable: + "http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/utazu.pdf", + StationMap: "https://www.google.co.jp/maps/place/34.306379,133.813784", + JrHpUrl: "http://www.jr-shikoku.co.jp/01_trainbus/kakueki/utazu/", + lat: 34.306379, + lng: 133.813784, + }, + ]; status = stationList; return stationList; }); diff --git a/lib/useInterval.js b/lib/useInterval.js new file mode 100644 index 0000000..a646862 --- /dev/null +++ b/lib/useInterval.js @@ -0,0 +1,45 @@ +import { useEffect, useRef, useState } from "react"; + +// type Control = { +// start: () => void; +// stop: () => void; +// }; + +// type State = 'RUNNING' | 'STOPPED'; + +// type Fn = () => void; + +export const useInterval = (fn, interval, autostart = true) => { + const onUpdateRef = useRef(); + const [state, setState] = useState("RUNNING"); + const start = () => { + setState("RUNNING"); + }; + const stop = () => { + setState("STOPPED"); + }; + useEffect(() => { + onUpdateRef.current = fn; + }, [fn]); + useEffect(() => { + if (autostart) { + setState("RUNNING"); + } + }, [autostart]); + useEffect(() => { + let timerId; + if (state === "RUNNING") { + timerId = setInterval(() => { + onUpdateRef.current?.(); + }, interval); + } else { + timerId && clearInterval(timerId); + } + return () => { + timerId && clearInterval(timerId); + }; + }, [interval, state]); + return [state, { start, stop }]; +}; + +export default useInterval; From cbce84a9ab1a79f4302c1b7c65a23a0263e78905 Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sat, 19 Nov 2022 15:34:14 +0900 Subject: [PATCH 15/15] init for 4.4.2 --- components/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/settings.js b/components/settings.js index c0cd1a4..67a796d 100644 --- a/components/settings.js +++ b/components/settings.js @@ -102,7 +102,7 @@ export default function Setting(props) { textAlignVertical: "center", }} > - 内部バージョン: 4.4.1 + 内部バージョン: 4.4.2