newsを変数管理式に変更
This commit is contained in:
parent
69de6e358a
commit
197765e7f1
176
Apps.js
176
Apps.js
@ -1,20 +1,22 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import {View, Platform,ToastAndroid} from 'react-native';
|
||||
import {WebView} from 'react-native-webview';
|
||||
import Constants from 'expo-constants';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import { View, Platform, ToastAndroid } from "react-native";
|
||||
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 StatusbarDetect from './StatusbarDetect';
|
||||
var Status = StatusbarDetect(); */
|
||||
|
||||
export var webview = null;
|
||||
|
||||
export default function Apps (props) {
|
||||
const { navigation: { navigate } } = props;
|
||||
var urlcache="";
|
||||
export default function Apps(props) {
|
||||
const {
|
||||
navigation: { navigate },
|
||||
} = props;
|
||||
var urlcache = "";
|
||||
const webview = useRef();
|
||||
const [iconSetting, setIconSetting] = useState(undefined)
|
||||
|
||||
const [iconSetting, setIconSetting] = useState(undefined);
|
||||
|
||||
const bootData = `
|
||||
document.getElementById('header').querySelector('a').style.display = 'none';
|
||||
@ -34,7 +36,7 @@ export default function Apps (props) {
|
||||
setReload();
|
||||
`;
|
||||
|
||||
const trainIconMaker = `
|
||||
const trainIconMaker = `
|
||||
const setStationIcon = (行き先アイコン,img) =>{
|
||||
let newItem = document.createElement("div");
|
||||
if(行き先アイコン.getAttribute("style").includes("left")){
|
||||
@ -45,11 +47,11 @@ const trainIconMaker = `
|
||||
}
|
||||
行き先アイコン.remove();
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
|
||||
|
||||
const trainIcon = iconSetting == "true" ? `
|
||||
const trainIcon =
|
||||
iconSetting == "true"
|
||||
? `
|
||||
switch(列番データ){
|
||||
//しおかぜメイン
|
||||
//8000 ノーマル
|
||||
@ -466,12 +468,16 @@ switch(列番データ){
|
||||
default:
|
||||
break;
|
||||
}
|
||||
` : ``;
|
||||
`
|
||||
: ``;
|
||||
|
||||
const JRF_icon = iconSetting == "true" ? `
|
||||
const JRF_icon =
|
||||
iconSetting == "true"
|
||||
? `
|
||||
JRF || setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/ef210a.png');
|
||||
` : ``;
|
||||
const normal_train_name = `
|
||||
`
|
||||
: ``;
|
||||
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;
|
||||
@ -491,8 +497,9 @@ const normal_train_name = `
|
||||
else if(列番データ.indexOf("S") != -1){
|
||||
行き先情報.innerText = 行き先情報.innerText+"臨時列車\\n";
|
||||
}
|
||||
`
|
||||
const JRF_name = `
|
||||
`;
|
||||
const JRF_name =
|
||||
`
|
||||
let JRF = false;
|
||||
switch(列番データ){
|
||||
case "71":
|
||||
@ -537,7 +544,7 @@ const JRF_name = `
|
||||
default:
|
||||
JRF = true;
|
||||
}
|
||||
`+JRF_icon;
|
||||
` + JRF_icon;
|
||||
|
||||
const TKT_name = `
|
||||
//安芸行と併結列車を個別に表示、それ以外をdefaultで下りなら既定の行き先を、上りなら奈半利行を設定
|
||||
@ -574,9 +581,10 @@ const JRF_name = `
|
||||
break;
|
||||
}
|
||||
|
||||
`
|
||||
`;
|
||||
|
||||
const textInsert = `
|
||||
const textInsert =
|
||||
`
|
||||
const setStrings = () =>{
|
||||
try {
|
||||
var elements = document.querySelectorAll('[onclick]');
|
||||
@ -587,7 +595,12 @@ const setStrings = () =>{
|
||||
var flag=false;
|
||||
var TrainType = undefined;
|
||||
if(行き先情報.innerText.includes(列番データ))continue; //回避
|
||||
`+trainIcon+normal_train_name+JRF_name+TKT_name+`
|
||||
` +
|
||||
trainIcon +
|
||||
normal_train_name +
|
||||
JRF_name +
|
||||
TKT_name +
|
||||
`
|
||||
//列番付与
|
||||
行き先情報.innerText = 行き先情報.innerText+列番データ+(JRF ? "":"レ");
|
||||
}
|
||||
@ -685,69 +698,84 @@ observer.observe(target, {
|
||||
childList: true, // 子ノードの変化を監視
|
||||
//subtree: true // 子孫ノードも監視対象に含める
|
||||
});
|
||||
`
|
||||
`;
|
||||
|
||||
const injectJavascriptData = bootData+trainIconMaker+textInsert;
|
||||
const injectJavascriptData = bootData + trainIconMaker + textInsert;
|
||||
|
||||
|
||||
|
||||
useEffect(()=>{
|
||||
useEffect(() => {
|
||||
AsyncStorage.getItem("status")
|
||||
.then(d=>{
|
||||
if(d != "2022/06/11"){
|
||||
navigate('news');
|
||||
}
|
||||
})
|
||||
.catch(e=>{
|
||||
navigate('news');
|
||||
})
|
||||
},[])
|
||||
useEffect(()=>{
|
||||
AsyncStorage.getItem("iconSwitch").then( d =>{
|
||||
if(d){
|
||||
setIconSetting(d);
|
||||
}
|
||||
else{
|
||||
AsyncStorage.setItem("iconSwitch","true").then(()=>Updates.reloadAsync())
|
||||
}
|
||||
|
||||
|
||||
}).catch(d=>AsyncStorage.setItem("iconSwitch","true").then(()=>Updates.reloadAsync()))
|
||||
},[])
|
||||
.then((d) => {
|
||||
if (d != news) {
|
||||
navigate("news");
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
navigate("news");
|
||||
});
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
AsyncStorage.getItem("iconSwitch")
|
||||
.then((d) => {
|
||||
if (d) {
|
||||
setIconSetting(d);
|
||||
} else {
|
||||
AsyncStorage.setItem("iconSwitch", "true").then(() =>
|
||||
Updates.reloadAsync()
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((d) =>
|
||||
AsyncStorage.setItem("iconSwitch", "true").then(() =>
|
||||
Updates.reloadAsync()
|
||||
)
|
||||
);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View style={{height:"100%",paddingTop: Platform.OS == "ios" ? Constants.statusBarHeight: 0,}}>
|
||||
<View
|
||||
style={{
|
||||
height: "100%",
|
||||
paddingTop: Platform.OS == "ios" ? Constants.statusBarHeight : 0,
|
||||
}}
|
||||
>
|
||||
{/* {Status} */}
|
||||
<WebView
|
||||
useWebKit={true}
|
||||
ref={webview}
|
||||
source={{uri: 'https://train.jr-shikoku.co.jp/sp.html'}}
|
||||
originWhitelist={['https://train.jr-shikoku.co.jp','https://train.jr-shikoku.co.jp/sp.html']}
|
||||
mixedContentMode={'compatibility'}
|
||||
javaScriptEnabled={true}
|
||||
allowsBackForwardNavigationGestures={true}
|
||||
setSupportMultipleWindows={false}
|
||||
onNavigationStateChange={
|
||||
event =>{
|
||||
<WebView
|
||||
useWebKit={true}
|
||||
ref={webview}
|
||||
source={{ uri: "https://train.jr-shikoku.co.jp/sp.html" }}
|
||||
originWhitelist={[
|
||||
"https://train.jr-shikoku.co.jp",
|
||||
"https://train.jr-shikoku.co.jp/sp.html",
|
||||
]}
|
||||
mixedContentMode={"compatibility"}
|
||||
javaScriptEnabled={true}
|
||||
allowsBackForwardNavigationGestures={true}
|
||||
setSupportMultipleWindows={false}
|
||||
onNavigationStateChange={(event) => {
|
||||
console.log(event);
|
||||
if(event.url != urlcache){//URL二重判定回避
|
||||
if (event.url != urlcache) {
|
||||
//URL二重判定回避
|
||||
urlcache = event.url;
|
||||
|
||||
if (event.url.includes("https://train.jr-shikoku.co.jp/usage.htm")) {
|
||||
if(Platform.OS==="android")navigate('howto');
|
||||
|
||||
if (
|
||||
event.url.includes("https://train.jr-shikoku.co.jp/usage.htm")
|
||||
) {
|
||||
if (Platform.OS === "android") navigate("howto");
|
||||
webview?.current.goBack();
|
||||
//Actions.howto();
|
||||
}
|
||||
else if (event.url.includes("https://train.jr-shikoku.co.jp/train.html")) {
|
||||
} else if (
|
||||
event.url.includes("https://train.jr-shikoku.co.jp/train.html")
|
||||
) {
|
||||
//Actions.trainbase({info: event.url});
|
||||
if(Platform.OS==="android")navigate('trainbase', {info: event.url});
|
||||
if (Platform.OS === "android")
|
||||
navigate("trainbase", { info: event.url });
|
||||
webview?.current.goBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
onMessage={(event)=>{}}
|
||||
injectedJavaScript={injectJavascriptData}/>
|
||||
}}
|
||||
onMessage={(event) => {}}
|
||||
injectedJavaScript={injectJavascriptData}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
@ -1,19 +1,45 @@
|
||||
import React, { } from 'react';
|
||||
import {View,Text,TouchableOpacity } from 'react-native';
|
||||
import {WebView} from 'react-native-webview';
|
||||
import StatusbarDetect from '../StatusbarDetect';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import React from "react";
|
||||
import { View, Text, TouchableOpacity } from "react-native";
|
||||
import { WebView } from "react-native-webview";
|
||||
import StatusbarDetect from "../StatusbarDetect";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { news } from "../config/newsUpdate";
|
||||
var Status = StatusbarDetect();
|
||||
export default function News(props){
|
||||
const { navigation: { navigate } } = props;
|
||||
return(
|
||||
<View style={{height:"100%",backgroundColor:"#0099CC"}}>
|
||||
<WebView useWebKit={true} source={{uri: 'https://nexcloud.haruk.in/sites/press-harukin/JRShikokuApps/2022-6-11'}} mixedContentMode={'compatibility'} javaScriptEnabled={true}/>
|
||||
<TouchableOpacity style={{padding:10,flexDirection:"row",borderColor:"white",borderWidth:1,margin:10,borderRadius:5,alignItems:"center"}} onPress={()=>{AsyncStorage.setItem('status', "2022/04/14");navigate('Apps');}}>
|
||||
<View style={{flex:1}} />
|
||||
<Text style={{fontSize:25,fontWeight:"bold",color:"white"}}>更新情報を閉じる</Text>
|
||||
<View style={{flex:1}} />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
export default function News(props) {
|
||||
const {
|
||||
navigation: { navigate },
|
||||
} = props;
|
||||
return (
|
||||
<View style={{ height: "100%", backgroundColor: "#0099CC" }}>
|
||||
<WebView
|
||||
useWebKit={true}
|
||||
source={{
|
||||
uri: `https://nexcloud.haruk.in/sites/press-harukin/JRShikokuApps/${news}`,
|
||||
}}
|
||||
mixedContentMode={"compatibility"}
|
||||
javaScriptEnabled={true}
|
||||
/>
|
||||
<TouchableOpacity
|
||||
style={{
|
||||
padding: 10,
|
||||
flexDirection: "row",
|
||||
borderColor: "white",
|
||||
borderWidth: 1,
|
||||
margin: 10,
|
||||
borderRadius: 5,
|
||||
alignItems: "center",
|
||||
}}
|
||||
onPress={() => {
|
||||
AsyncStorage.setItem("status", news);
|
||||
navigate("Apps");
|
||||
}}
|
||||
>
|
||||
<View style={{ flex: 1 }} />
|
||||
<Text style={{ fontSize: 25, fontWeight: "bold", color: "white" }}>
|
||||
更新情報を閉じる
|
||||
</Text>
|
||||
<View style={{ flex: 1 }} />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
1
config/newsUpdate.js
Normal file
1
config/newsUpdate.js
Normal file
@ -0,0 +1 @@
|
||||
export const news = "2022/06/11";
|
Loading…
Reference in New Issue
Block a user