279 lines
11 KiB
JavaScript
279 lines
11 KiB
JavaScript
import React, { useRef } from 'react';
|
|
import {View, Platform} from 'react-native';
|
|
import {WebView} from 'react-native-webview';
|
|
import Constants from 'expo-constants';
|
|
import StatusbarDetect from './StatusbarDetect';
|
|
var Status = StatusbarDetect();
|
|
export var webview = null;
|
|
export default function Apps ({ navigation: { navigate } }) {
|
|
var urlcache="";
|
|
const webview = useRef();
|
|
return (
|
|
<View style={{height:"100%",paddingTop: Constants.statusBarHeight,}}>
|
|
{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 =>{
|
|
console.log(event);
|
|
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');
|
|
webview?.current.goBack();
|
|
//Actions.howto();
|
|
}
|
|
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});
|
|
webview?.current.goBack();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
onMessage={(event)=>{}}
|
|
injectedJavaScript={INJECTED_JAVASCRIPT}/>
|
|
</View>
|
|
);
|
|
}
|
|
const INJECTED_JAVASCRIPT = `
|
|
var observer = new MutationObserver(()=>console.log(elem));
|
|
const elem = document.querySelector('#modal_content');
|
|
console.log(elem);
|
|
const config = {
|
|
attributes: true,
|
|
childList: true,
|
|
characterData: true
|
|
};
|
|
|
|
observer.observe(elem, config);
|
|
document.getElementById('header').querySelector('a').style.display = 'none';
|
|
document.getElementById('header').style.height = '50px';
|
|
document.getElementById('main').style.paddingTop = '54px';
|
|
|
|
document.getElementById('headerStr').style.display = 'none';
|
|
|
|
setStrings();
|
|
function setStrings(){
|
|
try {
|
|
document.getElementById('refreshIcon').click();
|
|
var elements = document.querySelectorAll('[onclick]');
|
|
for (let element of elements) {
|
|
if(element.getAttribute('onclick').indexOf('ShowTrainTimeInfo') != -1){
|
|
var 行き先情報 = element.getElementsByTagName("p")[0];
|
|
var 列番データ = element.getAttribute('onclick').split('"')[1];
|
|
var flag=false;
|
|
var TrainType = undefined;
|
|
console.log(列番データ);
|
|
if(new RegExp(/^4[1-9]\\d\\d[DM]$/).test(列番データ) || new RegExp(/^5[1-7]\\d\\d[DM]$/).test(列番データ)){
|
|
行き先情報.innerText = "ワンマン\\n"+行き先情報.innerText;
|
|
flag=true;
|
|
}
|
|
if(new RegExp(/^49[0-4]\\dD$/).test(列番データ) || new RegExp(/^9[0-4]\\dD$/).test(列番データ)){
|
|
行き先情報.innerText = "(海経由)"+(flag ? "" : "\\n")+行き先情報.innerText;
|
|
}
|
|
if(new RegExp(/^46\\d\\dD$/).test(列番データ) || new RegExp(/^6\\d\\dD$/).test(列番データ)){
|
|
行き先情報.innerText = "(内子経由)"+(flag ? "" : "\\n")+行き先情報.innerText;
|
|
}
|
|
if(列番データ.indexOf("H") != -1){
|
|
行き先情報.innerText = 行き先情報.innerText+"試運転\\n";
|
|
}
|
|
else if(列番データ.indexOf("R") != -1){
|
|
行き先情報.innerText = 行き先情報.innerText+"回送\\n";
|
|
}
|
|
else if(列番データ.indexOf("S") != -1){
|
|
行き先情報.innerText = 行き先情報.innerText+"臨時列車\\n";
|
|
}
|
|
|
|
//貨物データ
|
|
let JRF = false;
|
|
switch(列番データ){
|
|
case "71":
|
|
行き先情報.innerText = "東京(タ)→高松(タ)"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "73":
|
|
case "75":
|
|
行き先情報.innerText = "大阪(タ)→高松(タ)"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "3079":
|
|
行き先情報.innerText = "高松(タ)→伊予三島"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "3071":
|
|
case "3077":
|
|
行き先情報.innerText = "高松(タ)→新居浜"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "3073":
|
|
行き先情報.innerText = "高松(タ)→松山貨物"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "70":
|
|
行き先情報.innerText = "高松(タ)→東京(タ)"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "74":
|
|
case "76":
|
|
行き先情報.innerText = "高松(タ)→大阪(タ)"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "3078":
|
|
行き先情報.innerText = "伊予三島→高松(タ)"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "3070":
|
|
行き先情報.innerText = "新居浜→高松(タ)"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "3076":
|
|
行き先情報.innerText = "新居浜→高松(タ)"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "3072":
|
|
行き先情報.innerText = "松山貨物→高松(タ)"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
case "9070":
|
|
行き先情報.innerText = "臨時貨物"+"\\n"+行き先情報.innerText;
|
|
break;
|
|
default:
|
|
JRF = true;
|
|
}
|
|
|
|
//土佐くろ
|
|
//安芸行と併結列車を個別に表示、それ以外をdefaultで下りなら既定の行き先を、上りなら奈半利行を設定
|
|
switch(列番データ){
|
|
case "2086D":
|
|
行き先情報.innerText = "[特]あしずり16号\\n高知行";
|
|
break;
|
|
case "2088D":
|
|
行き先情報.innerText = "[特]あしずり18号\\n高知行";
|
|
break;
|
|
case "5814D":
|
|
case "5816D":
|
|
行き先情報.innerText = "ごめん・なはり線直通\\n快速 奈半利行";
|
|
break;
|
|
case "5812D":
|
|
行き先情報.innerText = "ごめん・なはり線直通\\n快速 安芸行";
|
|
break;
|
|
case "5874D":
|
|
case "5882D":
|
|
行き先情報.innerText = "ごめん・なはり線直通\\n各停 安芸行";
|
|
break;
|
|
case "742D":
|
|
case "746D":
|
|
行き先情報.innerText = "土佐山田/奈半利行\\n(御免にて解結)\\nごめん・なはり線快速";
|
|
break;
|
|
default:
|
|
if(new RegExp(/^58[1-3][1,3,5,7,9][DM]$/).test(列番データ)){
|
|
行き先情報.innerText = "ごめん・なはり線直通\\n快速 "+行き先情報.innerText;
|
|
}
|
|
else if(new RegExp(/^58[4-9][1,3,5,7,9][DM]$/).test(列番データ)){
|
|
行き先情報.innerText = "ごめん・なはり線直通\\n各停 "+行き先情報.innerText;
|
|
}
|
|
|
|
else if(new RegExp(/^58[3-4][0,2,4,6,8][DM]$/).test(列番データ)){
|
|
行き先情報.innerText = "ごめん・なはり線直通\\n快速 奈半利行";
|
|
}
|
|
else if(new RegExp(/^58[5-9][0,2,4,6,8][DM]$/).test(列番データ)){
|
|
行き先情報.innerText = "ごめん・なはり線直通\\n各停 奈半利行";
|
|
}
|
|
break;
|
|
}
|
|
|
|
//列番付与
|
|
行き先情報.innerText = 行き先情報.innerText+列番データ+(JRF ? "":"レ");
|
|
}
|
|
}
|
|
try{
|
|
|
|
for(let d of document.getElementById('disp').childNodes){
|
|
if(d.id == 'pMENU_2'){
|
|
continue;
|
|
}
|
|
if(d.id == 'pMENU_2_En'){
|
|
continue;
|
|
}
|
|
if(d.id == 'pMENU_3'){
|
|
continue;
|
|
}
|
|
if(d.id == 'pMENU_3_En'){
|
|
continue;
|
|
}
|
|
if(d.id == 'pMENU_k'){
|
|
continue;
|
|
}
|
|
if(d.id == 'pMENU_k_En'){
|
|
continue;
|
|
}
|
|
d.style.width = '100vw';
|
|
for(let f of d.childNodes){
|
|
try{
|
|
|
|
if(f.style.alignItems || f.style.textAlign){
|
|
f.style.width = '38vw';
|
|
}
|
|
else{
|
|
if(f.id == 'upTrainCrossBar'){
|
|
|
|
f.style.width = '38vw';
|
|
}
|
|
else if(f.id == 'dwTrainCrossBar'){
|
|
f.style.left = '62vw';
|
|
f.style.width = '38vw';
|
|
|
|
}
|
|
else{
|
|
f.style.width = '0vw';
|
|
}
|
|
|
|
}
|
|
if(f.style.textAlign == 'center'){
|
|
f.style.width = '24vw';
|
|
f.style.display = 'flex';
|
|
for(let i of f.childNodes){
|
|
i.style.width = 'unset';
|
|
i.style.left = 'unset';
|
|
i.style.top = 'unset';
|
|
i.style.position = 'unset';
|
|
i.style.flex = '1';
|
|
i.style.margin = '5px'
|
|
|
|
if(i.style.backgroundColor != 'rgb(247, 247, 247)'){
|
|
for(let m of i.childNodes){
|
|
m.style.width = '20vw'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}catch(e){}
|
|
}
|
|
}
|
|
|
|
|
|
document.querySelector('#pMENU_2').style.borderStyle='solid';
|
|
document.querySelector('#pMENU_2').style.borderColor='#00d3e8';
|
|
document.querySelector('#pMENU_2').style.borderWidth='2px';
|
|
document.querySelector('#pMENU_2').style.borderRadius='10%';
|
|
document.querySelector('#pMENU_3').style.borderStyle='solid';
|
|
document.querySelector('#pMENU_3').style.borderColor='#00d3e8';
|
|
document.querySelector('#pMENU_3').style.borderWidth='2px';
|
|
document.querySelector('#pMENU_3').style.borderRadius='10%';
|
|
document.querySelectorAll('#pMENU_2 div').forEach((d)=>d.style.padding = '10px');
|
|
document.querySelectorAll('#pMENU_3 div').forEach((d)=>d.style.padding = '10px');
|
|
document.querySelectorAll('#topHeader div').forEach((d)=>d.style.width = '100vw');
|
|
document.querySelectorAll('#disp div')[0].style.width = '100vw';
|
|
document.getElementById('disp').style.width = '100vw';
|
|
document.getElementById('disp').style.overflowX = 'hidden';
|
|
|
|
|
|
|
|
}catch(e){
|
|
alert("にゃー");
|
|
}
|
|
} catch (e) {}
|
|
setTimeout(setStrings, 10000);
|
|
}
|
|
`;
|
|
|