observerの設置変更

This commit is contained in:
harukin-OneMix4 2023-07-01 13:36:12 +09:00
parent 0ff05f911c
commit cdea9a1e05

View File

@ -23,9 +23,7 @@ export const injectJavascriptData = (
`; `;
// 何これ // 何これ
const bootData = const bootData = `
topMenu +
`
const setReload = () =>{ const setReload = () =>{
try{ try{
document.getElementById('refreshIcon').click(); document.getElementById('refreshIcon').click();
@ -579,8 +577,7 @@ const setStrings = () =>{
try { try {
const elements =[]; const elements =[];
document.querySelectorAll('#disp div div div').forEach(d=>{ document.querySelectorAll('#disp div div div').forEach(d=>{
if(d.onclick)if(d.onclick.toString().match("ShowTrainTimeInfo")) if(d.onclick)elements.push(d)
elements.push(d)
}); });
for (let element of elements) { for (let element of elements) {
var 行き先情報 = element.getElementsByTagName("p")[0]; var 行き先情報 = element.getElementsByTagName("p")[0];
@ -672,16 +669,12 @@ const setStrings = () =>{
alert("にゃーん"); alert("にゃーん");
} }
} catch (e) {} } catch (e) {}
//setTimeout(setStrings,500);
} }
const target = document.getElementById('disp'); // body要素を監視
const observer = new MutationObserver( (mutations) => { const textInsert = new MutationObserver( (mutations) => setStrings());
// observer.disconnect(); // 監視を終了
setStrings();
});
// 監視を開始 // 監視を開始
observer.observe(target, { textInsert.observe(document.getElementById('disp'), {
attributes: true, // 属性変化の監視 attributes: true, // 属性変化の監視
//attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する //attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する
//characterData: true, // テキストノードの変化を監視 //characterData: true, // テキストノードの変化を監視
@ -693,9 +686,8 @@ observer.observe(target, {
const makeTrainView = ` const makeTrainView = `
const modal_content = document.getElementById('modal_content'); // body要素を監視 const makeTrainView = new MutationObserver( (mutations) => {
const modal_observer = new MutationObserver( (mutations) => {
// observer.disconnect(); // 監視を終了
for(let d of modal_content.getElementsByTagName("button") ){ for(let d of modal_content.getElementsByTagName("button") ){
const data = d.onclick.toString().split("\\"")[1]; const data = d.onclick.toString().split("\\"")[1];
d.onclick = () => window.ReactNativeWebView.postMessage(data) d.onclick = () => window.ReactNativeWebView.postMessage(data)
@ -703,7 +695,7 @@ const modal_observer = new MutationObserver( (mutations) => {
}); });
// 監視を開始 // 監視を開始
modal_observer.observe(modal_content, { makeTrainView.observe(document.getElementById('modal_content'), {
//attributes: true, // 属性変化の監視 //attributes: true, // 属性変化の監視
//attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する //attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する
//characterData: true, // テキストノードの変化を監視 //characterData: true, // テキストノードの変化を監視
@ -712,17 +704,22 @@ modal_observer.observe(modal_content, {
//subtree: true // 子孫ノードも監視対象に含める //subtree: true // 子孫ノードも監視対象に含める
}); });
`; `;
const makeStationMenu =
stationMenu == "true"
? 'function PopUpMenu(event,id,name,pdf,map,url,chk){window.ReactNativeWebView.postMessage(JSON.stringify({type:"PopUpMenu",event,id,name,pdf,map,url,chk}));}'
: ``;
const makeTrainMenu = const makeTrainMenu =
//trainMenu == "true" //trainMenu == "true"
true true
? `
function ShowTrainTimeInfo(trainNum,limited){
window.ReactNativeWebView.postMessage(JSON.stringify({type:"ShowTrainTimeInfo",trainNum,limited}));
};
`
: ``;
const makeStationMenu =
stationMenu == "true"
? ` ? `
//駅メニューダイアログの配置 //駅メニューダイアログの配置
const setStationMenuDialog = () =>{
const setStationMenuDialog = new MutationObserver( (mutations) => {
const data =[]; const data =[];
document.querySelectorAll('#disp div div').forEach(d=>d.id.indexOf("st")!= -1 && data.push(d)); document.querySelectorAll('#disp div div').forEach(d=>d.id.indexOf("st")!= -1 && data.push(d));
@ -738,15 +735,10 @@ const setStationMenuDialog = () =>{
window.ReactNativeWebView.postMessage(JSON.stringify({type:"PopUpMenu",event:s[0],id:s[1],name:s[2],pdf:s[3],map:s[4],url:s[5],chk:s[6]})); window.ReactNativeWebView.postMessage(JSON.stringify({type:"PopUpMenu",event:s[0],id:s[1],name:s[2],pdf:s[3],map:s[4],url:s[5],chk:s[6]}));
} }
} }
}
const observer3 = new MutationObserver( (mutations) => {
// observer3.disconnect(); // 監視を終了
setStationMenuDialog();
}); });
// 監視を開始 // 監視を開始
observer3.observe(target, { setStationMenuDialog.observe(document.querySelector('#disp'), {
attributes: true, // 属性変化の監視 attributes: true, // 属性変化の監視
//attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する //attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する
//characterData: true, // テキストノードの変化を監視 //characterData: true, // テキストノードの変化を監視
@ -755,14 +747,10 @@ observer3.observe(target, {
//subtree: true // 子孫ノードも監視対象に含める //subtree: true // 子孫ノードも監視対象に含める
}); });
` `
: // ` : ``;
// function ShowTrainTimeInfo(trainNum,limited){
// window.ReactNativeWebView.postMessage(JSON.stringify({type:"ShowTrainTimeInfo",trainNum,limited}));
// };
// `
``;
return ( return (
bootData + bootData +
topMenu +
makeTrainView + makeTrainView +
trainIconMaker + trainIconMaker +
textInsert + textInsert +