スクリプトの大幅な修正/変更/最適化

This commit is contained in:
harukin-DeskMini 2022-06-11 04:49:26 +09:00
parent 6ef66d70e0
commit 2e8e12ba58

216
Apps.js
View File

@ -14,33 +14,42 @@ export default function Apps (props) {
var urlcache=""; var urlcache="";
const webview = useRef(); const webview = useRef();
const [iconSetting, setIconSetting] = useState(undefined) const [iconSetting, setIconSetting] = useState(undefined)
useEffect(()=>{
AsyncStorage.getItem("status")
.then(d=>{ const bootData = `
if(d != "2022/04/14"){ document.getElementById('header').querySelector('a').style.display = 'none';
navigate('news'); document.getElementById('header').style.height = '50px';
document.getElementById('main').style.paddingTop = '54px';
document.getElementById('headerStr').style.display = 'none';
const setReload = () =>{
try{
document.getElementById('refreshIcon').click();
setStrings();
}catch{
} }
}) setTimeout(setReload, 10000);
.catch(e=>{ }
navigate('news'); setReload();
}) `;
},[])
useEffect(()=>{ const trainIconMaker = `
AsyncStorage.getItem("iconSwitch").then( d =>{ const setStationIcon = (行き先アイコン,img) =>{
if(d){ let newItem = document.createElement("div");
setIconSetting(d); if(行き先アイコン.getAttribute("style").includes("left")){
行き先アイコン.insertAdjacentHTML('beforebegin', "<img src="+img+" style='float:left;height:20px;'>");
} }
else{ else{
AsyncStorage.setItem("iconSwitch","true").then(()=>Updates.reloadAsync()) 行き先アイコン.insertAdjacentHTML('beforebegin', "<img src="+img+" style='float:right;height:20px;'>");
} }
行き先アイコン.remove();
}
`
}).catch(d=>AsyncStorage.setItem("iconSwitch","true").then(()=>Updates.reloadAsync()))
},[])
const fTrainIcon = iconSetting == "true" ?`JRF || setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/ef210a.png');`:``;
const trainIcon = iconSetting == "true" ? ` const trainIcon = iconSetting == "true" ? `
switch(列番データ){ switch(列番データ){
//しおかぜメイン //しおかぜメイン
//8000 ノーマル //8000 ノーマル
@ -457,51 +466,12 @@ switch(列番データ){
default: default:
break; break;
} }
` : ``; ` : ``;
const INJECTED_JAVASCRIPT = `
const setStationIcon = (行き先アイコン,img) =>{
let newItem = document.createElement("div");
if(行き先アイコン.getAttribute("style").includes("left")){
行き先アイコン.insertAdjacentHTML('beforebegin', "<img src="+img+" style='float:left;height:20px;'>");
}
else{
行き先アイコン.insertAdjacentHTML('beforebegin', "<img src="+img+" style='float:right;height:20px;'>");
}
行き先アイコン.remove();
}
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); const JRF_icon = iconSetting == "true" ? `
document.getElementById('header').querySelector('a').style.display = 'none'; JRF || setStationIcon(element.getElementsByTagName("img")[0],'http://www.trainfrontview.net/f/ef210a.png');
document.getElementById('header').style.height = '50px'; ` : ``;
document.getElementById('main').style.paddingTop = '54px'; const normal_train_name = `
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;
`+trainIcon+`
console.log(列番データ);
if(new RegExp(/^4[1-9]\\d\\d[DM]$/).test(列番データ) || new RegExp(/^5[1-7]\\d\\d[DM]$/).test(列番データ)){ if(new RegExp(/^4[1-9]\\d\\d[DM]$/).test(列番データ) || new RegExp(/^5[1-7]\\d\\d[DM]$/).test(列番データ)){
行き先情報.innerText = "ワンマン\\n"+行き先情報.innerText; 行き先情報.innerText = "ワンマン\\n"+行き先情報.innerText;
flag=true; flag=true;
@ -521,8 +491,8 @@ const INJECTED_JAVASCRIPT = `
else if(列番データ.indexOf("S") != -1){ else if(列番データ.indexOf("S") != -1){
行き先情報.innerText = 行き先情報.innerText+"臨時列車\\n"; 行き先情報.innerText = 行き先情報.innerText+"臨時列車\\n";
} }
`
//貨物データ const JRF_name = `
let JRF = false; let JRF = false;
switch(列番データ){ switch(列番データ){
case "71": case "71":
@ -567,16 +537,11 @@ const INJECTED_JAVASCRIPT = `
default: default:
JRF = true; JRF = true;
} }
`+JRF_icon;
//土佐くろ const TKT_name = `
//安芸行と併結列車を個別に表示、それ以外をdefaultで下りなら既定の行き先を、上りなら奈半利行を設定 //安芸行と併結列車を個別に表示、それ以外をdefaultで下りなら既定の行き先を、上りなら奈半利行を設定
switch(列番データ){ switch(列番データ){
case "2086D":
行き先情報.innerText = "[特]あしずり16号\\n高知行";
break;
case "2088D":
行き先情報.innerText = "[特]あしずり18号\\n高知行";
break;
case "5814D": case "5814D":
case "5816D": case "5816D":
行き先情報.innerText = "ごめん・なはり線直通\\n快速 奈半利行"; 行き先情報.innerText = "ごめん・なはり線直通\\n快速 奈半利行";
@ -609,42 +574,45 @@ const INJECTED_JAVASCRIPT = `
break; 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 ? "":"レ"); 行き先情報.innerText = 行き先情報.innerText+列番データ+(JRF ? "":"レ");
`+fTrainIcon+`
}
} }
try{ try{
for(let d of document.getElementById('disp').childNodes){ for(let d of document.getElementById('disp').childNodes){
if(d.id == 'pMENU_2'){ switch(d.id){
continue; case 'pMENU_2':
} case 'pMENU_2_En':
if(d.id == 'pMENU_2_En'){ case 'pMENU_3':
continue; case 'pMENU_3_En':
} case 'pMENU_k':
if(d.id == 'pMENU_3'){ case 'pMENU_k_En':
continue;
}
if(d.id == 'pMENU_3_En'){
continue;
}
if(d.id == 'pMENU_k'){
continue;
}
if(d.id == 'pMENU_k_En'){
continue; continue;
default:
break;
} }
d.style.width = '100vw'; d.style.width = '100vw';
for(let f of d.childNodes){ for(let f of d.childNodes){
try{ try{
if(f.style.alignItems || f.style.textAlign){ if(f.style.alignItems || f.style.textAlign){
f.style.width = '38vw'; f.style.width = '38vw';
} }
else{ else{
if(f.id == 'upTrainCrossBar'){ if(f.id == 'upTrainCrossBar'){
f.style.width = '38vw'; f.style.width = '38vw';
} }
else if(f.id == 'dwTrainCrossBar'){ else if(f.id == 'dwTrainCrossBar'){
@ -652,15 +620,14 @@ const INJECTED_JAVASCRIPT = `
f.style.width = '38vw'; f.style.width = '38vw';
} }
else{ else {
f.style.width = '0vw'; f.style.width = '0vw';
} }
} }
if(f.style.textAlign == 'center'){ if(f.style.textAlign == 'center'){
f.style.width = '24vw'; f.style.width = '24vw';
f.style.display = 'flex'; f.style.display = 'flex';
for(let i of f.childNodes){ f.childNodes.forEach(i =>{
i.style.width = 'unset'; i.style.width = 'unset';
i.style.left = 'unset'; i.style.left = 'unset';
i.style.top = 'unset'; i.style.top = 'unset';
@ -669,11 +636,9 @@ const INJECTED_JAVASCRIPT = `
i.style.margin = '5px' i.style.margin = '5px'
if(i.style.backgroundColor != 'rgb(247, 247, 247)'){ if(i.style.backgroundColor != 'rgb(247, 247, 247)'){
for(let m of i.childNodes){ i.childNodes.forEach(m=> m.style.width = '20vw')
m.style.width = '20vw'
}
}
} }
})
} }
}catch(e){} }catch(e){}
@ -681,6 +646,7 @@ const INJECTED_JAVASCRIPT = `
} }
document.querySelector('#pMENU_2').style.borderStyle='solid'; document.querySelector('#pMENU_2').style.borderStyle='solid';
document.querySelector('#pMENU_2').style.borderColor='#00d3e8'; document.querySelector('#pMENU_2').style.borderColor='#00d3e8';
document.querySelector('#pMENU_2').style.borderWidth='2px'; document.querySelector('#pMENU_2').style.borderWidth='2px';
@ -699,13 +665,55 @@ const INJECTED_JAVASCRIPT = `
}catch(e){ }catch(e){
alert("にゃー"); alert("にゃー");
} }
} catch (e) {} } catch (e) {}
setTimeout(setStrings, 10000); //setTimeout(setStrings,500);
} }
`; const target = document.getElementById('disp'); // body要素を監視
const observer = new MutationObserver( (mutations) => {
// observer.disconnect(); // 監視を終了
setStrings();
});
// 監視を開始
observer.observe(target, {
attributes: true, // 属性変化の監視
//attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する
//characterData: true, // テキストノードの変化を監視
//characterDataOldValue: true, // 変化前のテキストを matation.oldValue に格納する
childList: true, // 子ノードの変化を監視
//subtree: true // 子孫ノードも監視対象に含める
});
`
const injectJavascriptData = bootData+trainIconMaker+textInsert;
useEffect(()=>{
AsyncStorage.getItem("status")
.then(d=>{
if(d != "2022/04/14"){
navigate('news');
}
})
.catch(e=>{
navigate('news');
})
},[])
useEffect(()=>{
AsyncStorage.getItem("iconSwitch").then( d =>{
if(d){
setIconSetting(d);
}
else{
AsyncStorage.setItem("iconSwitch","true").then(()=>Updates.reloadAsync())
}
}).catch(d=>AsyncStorage.setItem("iconSwitch","true").then(()=>Updates.reloadAsync()))
},[])
return ( return (
<View style={{height:"100%",paddingTop: Constants.statusBarHeight,}}> <View style={{height:"100%",paddingTop: Constants.statusBarHeight,}}>
@ -739,7 +747,7 @@ const INJECTED_JAVASCRIPT = `
} }
} }
onMessage={(event)=>{}} onMessage={(event)=>{}}
injectedJavaScript={INJECTED_JAVASCRIPT}/> injectedJavaScript={injectJavascriptData}/>
</View> </View>
); );
} }