type InjectJavascriptData = (
  a: string,
  b: string,
  c: string,
  d: string
) => string;
export const injectJavascriptData: InjectJavascriptData = (
  mapSwitch,
  iconSetting,
  stationMenu,
  trainMenu
) => {
  // 一番上のメニュー非表示　地図スイッチによって切り替え
  const topMenu =
    mapSwitch != "true"
      ? `
      document.querySelector('#header a').style.display = 'none';
      document.querySelector('#header').style.height = '50px';
      document.querySelector('#main').style.paddingTop = '54px';
      document.querySelector('#headerStr').style.display = 'none';
      `
      : `
      document.querySelector('.accordionClass').style.display = 'none';
      document.querySelector('#header').style.display = 'none';
      document.querySelector('#main').style.paddingTop = '0px';
      document.querySelector('#headerStr').style.display = 'none';
      `;

  // 何これ
  const bootData = `
    const setReload = () =>{
      try{
        document.getElementById('refreshIcon').click();
        setStrings();
      }catch{

      }
      setTimeout(setReload, 10000);
    }
    setReload();
  `;
  // 左か右かを判定してアイコンを設置する
  const trainIconMaker = `
    const setStationIcon = (setIconElem,img) =>{
      if(setIconElem.getAttribute("style").includes("left")){
        setIconElem.insertAdjacentHTML('beforebegin', "<img src="+img+" style='float:left;height:20px;'>");
      }
      else{
        setIconElem.insertAdjacentHTML('beforebegin', "<img src="+img+" style='float:right;height:20px;'>");
      }
      setIconElem.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.querySelector("img"),'https://storage.haruk.in/s8000nr.png');
      break;
    //8000 アンパン
    case "10M":
    case "22M":
    case "9M":
    case "21M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s8000ap.png');
      break;


    //8600
    case "8M":
    case "12M":
    case "20M":
    case "24M":
    case "7M":
    case "11M":
    case "19M":
    case "23M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/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.querySelector("img"),'https://storage.haruk.in/s8000no.png');
      break;

    //8000 アンパン
    case "1010M":
    case "1022M":
    case "1009M":
    case "1021M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s8000ap.png');
      break;

    //8600
    case "1008M":
    case "1012M":
    case "1020M":
    case "1024M":
    case "1007M":
    case "1011M":
    case "1019M":
    case "1023M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s8600_isz.png');
      break;

    //MEXP
    //8000
    case "1092M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s8000nr.png');
      break;
    //8600
    case "1091M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s8600_isz.png');
      break;
    //三桁いしづち
    //8000 アンパン
    case "1041M":
    case "1044M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s8000ap.png');
      break;
    //8600
    case "1043M":
    case "1042M":
    case "1046M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/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.querySelector("img"),'https://storage.haruk.in/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.querySelector("img"),'https://n8n.haruk.in/webhook/dosan-anpanman-pictures.png?trainNum='+列番データ);
      break;



    //うずしお
    //2700
    case "5006D":
    case "5022D":
    case "5013D":
    case "5029D":
    case "3004D":
    case "3010D":
    case "3014D":
    case "3016D":
    case "3028D":
    case "3003D":
    case "3007D":
    case "3025D":
    case "3031D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s2700_uzu.png');
      break;

    //2700 二両編成
    
    case "3020D":
    case "3026D":
    case "3032D":
    case "3005D":
    case "3011D":
    case "3017D":
    case "3019D":
    case "3023D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s2700_uzu.png');
      break;

    //2600
    case "3002D":
    case "3012D":
    case "3018D":
    case "3024D":
    case "3030D":
    case "3009D":
    case "3015D":
    case "3021D":
    case "3027D":
    case "3033D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s2600.png');
      break;

    //キハ185
    case "3001D":
    case "3008D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/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.querySelector("img"),'https://storage.haruk.in/s5001.png');
      break;
    case "3102M":
    case "3101M":
    case "3103M":
    case "3171M":
    case "3173M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s5001k.png');
      break;

    //サンライズ瀬戸
    case "5032M":
    case "5031M":
    case "8041M": //琴平延長高松迄
    case "8031M": //琴平延長高松以降
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/w285.png');
      break;

    //宇和海
    //2000 ノーマル
    case "1052D":
    case "1056D":
    case "1058D":
    case "1062D":
    case "1064D":
    case "1068D":
    case "1070D":
    case "1074D":
    case "1076D":
    case "1078D":
    case "1080D":
    case "1082D":
    case "1051D":
    case "1053D":
    case "1057D":
    case "1059D":
    case "1063D":
    case "1065D":
    case "1069D":
    case "1071D":
    case "1073D":
    case "1075D":
    case "1077D":
    case "1079D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s2000_uwa.png');
    break;
    //2000 アンパン込み
    case "1054D":
    case "1060D":
    case "1066D":
    case "1072D":
    case "1055D":
    case "1061D":
    case "1067D":
    case "1081D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s2002a.png');
    break;
    //しまんと
    case "2002D":
    case "2004D":
    case "2006D":
    case "2008D":
    case "2001D":
    case "2003D":
    case "2005D":
    case "2007D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s2700_smn.png');
    break;

    //あしずり 2000
    case "2074D":
    case "2076D":
    case "2080D":
    case "2082D":
    case "2071D":
    case "2073D":
    case "2079D":
    case "2081D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s2000_asi.png');
    break;

    //あしずり 2700
    case "2078D":
    case "2084D":
    case "2088D":
    case "2075D":
    case "2077D":
    case "2072D":
    case "2083D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/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.querySelector("img"),'https://storage.haruk.in/s185tu.png');
    break;
    //むろと
    case "8051D":
    case "8052D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s185_mrt.png');
    break;


    //よしのがわトロッコ
    case "8452D":
    case "8451D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s185to_ai.png');
    break;

    //岡山高松アントロ
    case "8176D":
    case "8179D":
    //岡山琴平アントロ
    case "8277D":
    case "8278D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s32to4.png');
    break;


    //千年ものがたり
    case "8021D":
    case "8022D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s185mm1.png');
    break;

    //夜明けものがたり
    case "8082D":
    case "8083D":
    case "8073D":
    case "8074D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s185ym1.png');
    break;
    //ラマルドボア
    case "9253M":
    case "9256M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/w213w.png');
      break;

    // 貨物
    case "74":
    case "75":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/ef65_rp0.png');
      break;
    case "70":
    case "71":
    case "73":
    case "76":
    case "3070":
    case "3071":
    case "3072":
    case "3073":
    case "3076":
    case "3077":
    case "3078":
    case "3079":
    case "8070":
    case "8071":
    case "8072":
    case "8077":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/ef210a.png');
      break;

    // 普通列車系統、6000系運用
    //61運用
    case "1213M":
    case "1214M":
    case "143M":
    case "147M":
    //62運用
    case "114M":
    //961運用
    case "143M":
    case "147M":
    //962運用
    case "114M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s6000p.png');
      break;


    // 土讃線普通列車系統(include ごな線)
    // ごな線
    case "5851D": //219D併結 [ToDo: 219Dとの分割対策]
    case "5854D": 
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/tosa9640jgr.png');
      break;
    
      //JR車両乗り入れ運用
    case "5858D": 
    case "5869D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1000.png');
      break;
    //併結運用の併結される側  [ToDo: 分割対策]
    case "5845D":
    case "5851D":
    case "5818D":
    case "5820D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/tosa9640.png');
      break;
    // 土讃線単体列車のキハ32運用
    case "715D":
    case "718D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s32ns.png');
      break;
    
    // サンライズに伴う気動車代走
    case "6219D":
    case "6222D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1000.png');
      break;
    // それ以外の土讃線ごな線直通列車
    case "5811D":
    case "5813D":
    case "5815D":
    case "5817D":
    case "5843D":
    case "5853D":
    case "5855D":
    case "5859D":
    case "5861D":
    case "5865D":
    case "5881D":
    case "5885D":
    case "5889D":
    
    case "5812D":
    case "5814D":
    case "5816D":
    case "5852D":
    case "5856D":
    case "5860D":
    case "5862D":
    case "5872D":
    case "5874D":
    case "5876D":
    case "5880D":
    case "5882D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/tosa9640.png');
      break;
    // それ以外の土讃線普通列車(1000)
    case "4210D":
    case "4212D":
    case "4214D":
    case "4218D":
    case "4220D":
    case "4222D":
    case "4224D":
    case "4226D":
    case "4228D":
    case "4230D":
    case "4232D":
    case "4234D":
    case "4236D":
    case "4238D":
    case "4240D":
    case "4242D":
    case "4244D":
    case "4250D":
    case "4252D":
    case "4254D":
    case "4256D":

    case "4211D":
    case "4221D":
    case "4223D":
    case "4225D":
    case "4227D":
    case "4229D":
    case "4231D":
    case "4235D":
    case "4237D":
    case "4239D":
    case "4241D":
    case "4245D":
    case "4247D":
    case "4249D":
    case "4251D":
    case "4253D":
    case "4255D":
    case "4257D":
    case "4259D":
    case "4261D":

    case "4710D":
    case "4726D":
    case "4730D":
    case "4732D":
    case "4734D":
    case "4738D":
    case "4740D":
    case "4742D":
    case "4744D":
    case "4746D":
    case "4752D":
    case "4756D":
    case "4762D":
    case "4764D":
    case "4766D":

    case "4711D":
    case "4713D":
    case "4723D":
    case "4725D":
    case "4727D":
    case "4729D":
    case "4731D":
    case "4737D":
    case "4739D":
    case "4745D":
    case "4753D":
    case "4755D":
    case "4759D":
    case "4761D":
    case "4763D":

    case "216D":
    case "238D":
    case "246D":
    case "248D":

    case "213D":
    case "215D":
    case "217D":
    case "219D":
    case "233D":
    case "243D":
      
    case "710D":
    case "712D":
    case "714D":
    case "716D":
    case "720D":
    case "722D":
    case "724D":
    case "728D":
    case "736D":
    case "748D":
    case "750D":
    case "754D":
    case "758D":
    case "760D":
    case "768D":

    case "717D":
    case "719D":
    case "721D":
    case "733D":
    case "735D":
    case "737D":
    case "741D":
    case "743D":
    case "747D":
    case "749D":
    case "751D":
    case "755D":
    case "757D":
    case "761D":
      
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1000.png');
      break;
    // 予讃線/土讃線普通列車運用(7000,7200)
    // 下り列車(伊予西条-松山は全て7000系)

    case "5519M":
    case "5525M":
    case "5215M":
    case "5103M":
    case "107M":
    case "1219M":
    case "5109M":
    case "6109M":
    case "5531M":
    case "1221M":
    case "5225M":
    case "5111M":
    case "1227M":
    case "115M":
    case "5229M":
    case "5117M":
    case "5119M":
    case "119M":
    case "5231M":
    case "4537M":
    case "5233M":
    case "123M":
    case "125M":
    case "5235M":
    case "5239M":
    case "5547M":
    case "129M":
    case "5241M":
    case "5133M":
    case "135M":
    case "1243M":
    case "137M":
    case "5139M":
    case "4559M":
    case "1245M":
    case "141M":
    case "1247M":
    case "5249M":
    case "145M":
    case "5253M":
    case "5149M":
    case "5255M":
    case "151M":
    case "5257M":
    case "153M":
    case "5259M":
    case "155M":
    case "1263M":
    case "157M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s7200.png');
      break;
      // 下り7000系
    case "101M":
    case "4601M":
    case "4113M":
    case "121M":
    case "127M":
    case "131M":
    case "555M":
    case "4565M":
    case "159M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s7000.png');
      break;
      // 上り列車 7200系
    case "5102M":
    case "104M":
    case "5210M":
    case "5108M":
    case "4108M":
    case "110M":
    case "112M":
    case "118M":
    case "5218M":
    case "5120M":
    case "5220M":
    case "5512M":
    case "1602M":
    case "1224M":
    case "5124M":
    case "5226M":
    case "5126M":
    case "5128M":
    case "1230M":
    case "4128M":
    case "130M":
    case "4522M":
    case "5232M":
    case "132M":
    case "5234M":
    case "136M":
    case "5236M":
    case "5140M":
    case "5238M":
    case "5240M":
    case "142M":
    case "4530M":
    case "144M":
    case "5242M":
    case "146M":
    case "5244M":
    case "4148M":
    case "1246M":
    case "150M":
    case "5538M":
    case "5152M":
    case "154M":
    case "156M":
    case "1252M":
    case "158M":
    case "4604M":
    case "548M":
    case "5254M":
    case "1606M":
    case "5160M":
    case "5256M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s7200.png');
      break;
    // 上り7000系
    case "114M":
    case "122M":
    case "134M":
    case "4138M":
    case "138M":
    case "4542M":
    case "162M":
    case "4166M":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s7000.png');
      break;
    // 松山界隈気動車運用
    // 上り下りの概念アリ
    // キハ32 通常運用
    case "4625D":
    case "4916D":
    case "925D":
    case "4618D":
    case "4913D":
    case "4918D":
    case "4643D":
    case "4654D":
    case "4657D":
    case "4928D":
    case "4667D":
    case "653D":
    case "3621D":
    case "4818D":
    case "4821D":
    case "4824D":
    case "4813D":
    case "4664D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s32s.png');
      break;
    // 河童うようよ号偶数
    case "4816D":
    case "4830D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s32kpuy2.png');
      break;
    // 河童うようよ号奇数
    case "4827D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s32kpuy1.png');
      break;
    // 新幹線偶数
    case "4810D":
    case "4822D":
    case "4826D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s32tht.png');
      break;
    // 新幹線奇数
    case "4817D":
    case "4823D":
    case "4829D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s32thtk.png');
      break;
    // キハ54 通常運用
    case "4632D":
    case "4634D":
    case "4921D":
    case "4926D": 
    case "4927D":
    case "912D":
    case "4917D":
    case "4641D":
    case "4652D":
    case "4651D":
    case "4666D":
    case "4820D":
    case "4825D":
    case "4828D":
    case "4811D":
    case "4640D":
    case "622D":
    case "4633D":
    case "4920D":
    case "4637D":
    case "4648D":
    case "620D":
    case "4627D":
    case "4624D":
    case "4915D":
    case "4924D":
    case "4649D":
    case "4812D":
    case "4815D":
    case "4659D":
    case "4658D":
    case "4665D":
    case "4914D":
    case "4626D":
    case "4631D":
    case "4636D":
    case "4919D":
    case "4922D":
    case "4923D":
    case "4663D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s54s.png');
      break;
    // 54しまんとろっこ
    case "4623D":
    case "8814D":
    case "8819D":
    case "4662D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s54to0ys.png');
      break;
    // キハ185 通常運用
    case "911D":
    case "628D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s185cm.png');
      break;
    // 伊予灘ものがたり 赤
    case "8091D":
    case "8093D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s185iyor.png');
      break;
    // 伊予灘ものがたり 黄
    case "8092D":
    case "8094D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s185iyoy.png');
      break;
    // 高徳線、徳島線、牟岐線、鳴門線普通列車系統
    // キハ40・47
    case "4303D":
    case "363D":
    case "369D":
    case "314D":
    case "316D":
    case "368D":
    case "4382D":
    case "951D":
    case "953D":
    case "955D":
    case "973D":
    case "975D":
    case "977D":
    case "979D":
    case "981D":
    case "950D":
    case "968D":
    case "970D":
    case "972D":
    case "974D":
    case "976D":
    case "980D":
    case "982D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s40.png');
      break;
    // 1000形
    case "4309D":
    case "4311D":
    case "371D":
    case "4318D":
    case "358D":
    case "4380D":
    case "433D":
    case "473D":
    case "450D":
    case "480D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1000.png');
      break;
    // 1200形
    case "4301D":
    case "4327D":
    case "4329D":
    case "4343D":
    case "351D":
    case "353D":
    case "355D":
    case "4355D":
    case "4361D":
    case "367D":
    case "4330D":
    case "4336D":
    case "4346D":
    case "360D":
    case "362D":
    case "4370D":
    case "374D":
    case "4378D":
    case "451D":
    case "4453D":
    case "4455D":
    case "4459D":
    case "471D":
    case "475D":
    case "485D":
    case "4430D":
    case "434D":
    case "438D":
    case "4460D":
    case "4466D":
    case "4470D":
    case "474D":
    case "484D":
    case "957D":
    case "4959D":
    case "4963D":
    case "4967D":
    case "4971D":
    case "4983D":
    case "952D":
    case "4954D":
    case "4958D":
    case "4962D":
    case "4966D":
    case "4978D":
      setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1200n.png');
      break;

      
    default: //指定車両でなく、Regexでの指定に移動
        // 琴平直通系普通電車  
      if(new RegExp(/^(1|4|5)2\\d\\dM$/).test(列番データ)){
        setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s7200.png');
        break;
      }
      else if(new RegExp(/^(1|4|5)(1|5|6)\\d\\dM$/).test(列番データ)){
        setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s7000.png');
        break;
      }
      else if(new RegExp(/^(1|5|6)\\d\\dM$/).test(列番データ)){
        setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s7000.png');
        break;
      }// 高徳線 普通列車系統
      else if(new RegExp(/^(4|5)3\\d\\dD$/).test(列番データ)){
        setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1500.png');
        break;
      }
      else if(new RegExp(/^3\\d\\dD$/).test(列番データ)){
        setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1500.png');
        break;
      }// 徳島線 普通列車系統
      else if(new RegExp(/^(4|5)4\\d\\dD$/).test(列番データ)){
        setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1500.png');
        break;
      }
      else if(new RegExp(/^4\\d\\dD$/).test(列番データ)){
        setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1500.png');
        break;
      }// 鳴門線普通列車系統
      else if(new RegExp(/^(4|5)9(5|6|7|8)\\dD$/).test(列番データ)){
        setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1500.png');
        break;
      }
      else if(new RegExp(/^9(5|6|7|8)\\dD$/).test(列番データ)){
        setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s1500.png');
        break;
      }
      // 牟岐線普通列車系統 一旦閉鎖
      // else if(new RegExp(/^(4|5)5\\d\\dD$/).test(列番データ)){
      //   setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s7200.png');
      //   break;
      // }
      // else if(new RegExp(/^5\\d\\dD$/).test(列番データ)){
      //   setStationIcon(element.querySelector("img"),'https://storage.haruk.in/s7000.png');
      //   break;
      // }
      break;
    }
    `
      : ``;

  const normal_train_name = `
    if(列車名データ.match("サンポート")){
      const textBase = 列車名データ.split(":")[1];
      行き先情報.innerText = textBase+行き先情報.innerText;
    }
    if(new RegExp(/^4[1-9]\\d\\d[DM]$/).test(列番データ) || new RegExp(/^5[1-7]\\d\\d[DM]$/).test(列番データ) || 列番データ ==="3621D"){
      行き先情報.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;
const getJRF = num =>{
  switch(num){
    case "71":
      return "東京(タ)→高松(タ)"+"\\n";
    case "73":
    case "75":
      return "大阪(タ)→高松(タ)"+"\\n";
    case "3079":
      return "高松(タ)→伊予三島"+"\\n";
    case "3071":
    case "3077":
      return "高松(タ)→新居浜"+"\\n";
    case "3073":
      return "高松(タ)→松山貨物"+"\\n";
    case "70":
      return "高松(タ)→東京(タ)"+"\\n";
    case "74":
    case "76":
      return "高松(タ)→大阪(タ)"+"\\n";
    case "3078":
      return "伊予三島→高松(タ)"+"\\n";
    case "3070":
      return "新居浜→高松(タ)"+"\\n";
    case "3076":
      return "新居浜→高松(タ)"+"\\n";
    case "3072":
      return "松山貨物→高松(タ)"+"\\n";
    case "9070":
      return "臨時貨物"+"\\n";
    default:
      JRF = true;
      return null;
  }
}
const data = getJRF(列番データ);
行き先情報.innerText = data != null ?  data+行き先情報.innerText : 行き先情報.innerText;

`;

  const Other_Name = `
  const getThrew = num =>{
  
    switch(num){
    //牟岐線直通列車情報
    case "351D":
    case "468D":
    case "484D":
      return "牟岐線直通\\n牟岐行";
    case "951D":
      return "牟岐線直通\\n桑野行";
    case "4430D":
    case "4472D":
      return "牟岐線直通\\nワンマン 牟岐行";
    case "434D":
    case "474D":
    case "478D":
    case "480D":
      return "牟岐線直通\\n阿南行";
    case "5444D":
    case "4452D":
    case "4458D":
    case "4460D":
    case "4466D":
      return "牟岐線直通\\nワンマン 阿南行";
    case "4464D":
      return "牟岐線直通\\nワンマン 阿波海南行";
    
    //安芸行と併結列車を個別に表示、それ以外をdefaultで下りなら既定の行き先を、上りなら奈半利行を設定
      case "5814D":
      case "5816D":
        return "ごめん・なはり線直通\\n快速 奈半利行";
      case "5812D":
        return "ごめん・なはり線直通\\n快速 安芸行";
      case "5874D":
      case "5882D":
      case "5878D":
        return "ごめん・なはり線直通\\n各停 安芸行";
      case "246D":
      case "750D":
        return "土佐山田/奈半利行\\n(後免にて解結)\\nごめん・なはり線快速";
      default:
        if(new RegExp(/^58[1-3][1,3,5,7,9][DM]$/).test(列番データ)){
          return "ごめん・なはり線直通\\n快速 "+行き先情報.innerText;
        }
        else if(new RegExp(/^58[4-9][1,3,5,7,9][DM]$/).test(列番データ)){
          return "ごめん・なはり線直通\\n各停 "+行き先情報.innerText;
        }
        else if(new RegExp(/^58[3-4][0,2,4,6,8][DM]$/).test(列番データ)){
          return "ごめん・なはり線直通\\n快速 奈半利行";
        }
        else if(new RegExp(/^58[5-9][0,2,4,6,8][DM]$/).test(列番データ)){
          return "ごめん・なはり線直通\\n各停 奈半利行";
        }
      }
    }
  行き先情報.innerText = getThrew(列番データ) || 行き先情報.innerText;

`;

  const textInsert =
    `
    //列番付与
const setStrings = () =>{
  try {
    const elements = document.querySelectorAll('#disp > div > div > div[onclick]');
    for (let element of elements) {
      if(!element.getAttribute('offclick')){
        element.setAttribute('offclick',element.getAttribute('onclick'))
      }
      var 行き先情報 = element.getElementsByTagName("p")[0];
      var 列番データ = element.getAttribute('offclick').split('"')[1];
      var 列車名データ = element.getAttribute('offclick').split('"')[3];
      var flag=false;
      var TrainType = undefined;
      setTrainMenuDialog(element)
      if(行き先情報.innerText.includes(列番データ))continue; //回避
      ` +
    trainIcon +
    normal_train_name +
    JRF_name +
    Other_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("本家サーバーからのデータ取得に失敗しました。");
      window.ReactNativeWebView.postMessage(JSON.stringify({type:"LoadError"}));
    }
  } catch (e) {}
}

const textInsert = new MutationObserver( (mutations) =>{
  setStrings();
  const currentLines = document.querySelector('#topHeader div').innerText;
  window.ReactNativeWebView.postMessage(JSON.stringify({type:"currentLines",currentLines}));
});

// 監視を開始
textInsert.observe(document.getElementById('disp'), {
  attributes: true, // 属性変化の監視
  //attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する
  //characterData: true, // テキストノードの変化を監視
  //characterDataOldValue: true, // 変化前のテキストを matation.oldValue に格納する
  childList: true, // 子ノードの変化を監視
  //subtree: true // 子孫ノードも監視対象に含める
});
`;

  const makeTrainView = `

const makeTrainView = new MutationObserver( (mutations) => {

  for(let d of modal_content.getElementsByTagName("button") ){
    const data = d.onclick.toString().split("\\"")[1];
    d.onclick = () => window.ReactNativeWebView.postMessage(data)
  }
});

// 監視を開始
makeTrainView.observe(document.getElementById('modal_content'), {
  //attributes: true, // 属性変化の監視
  //attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する
  //characterData: true, // テキストノードの変化を監視
  //characterDataOldValue: true, // 変化前のテキストを matation.oldValue に格納する
  childList: true, // 子ノードの変化を監視
  //subtree: true // 子孫ノードも監視対象に含める
});
`;
  const makeTrainMenu =
    trainMenu == "true"
      ? `
      // これの中身抽出ShowTrainTimeInfo("1228M","normal")
      // ShowTrainTimeInfo("142M","rapid:サンポート南風リレー")
      function setTrainMenuDialog(d){
        try{
          const offclick = d.getAttribute('offclick');
          if(!offclick) return;
          const s =  offclick.replace('ShowTrainTimeInfo(','').replaceAll('"','').replace(')','').split(',') ;
          const returnData = {type:"ShowTrainTimeInfo",trainNum:s[0],limited:s[1]};
          d.onclick = ()=>window.ReactNativeWebView.postMessage(JSON.stringify(returnData));
        }catch(e){
        }
        
      }
        function ShowTrainTimeInfo(trainNum,limited){
          window.ReactNativeWebView.postMessage(JSON.stringify({type:"ShowTrainTimeInfo",trainNum,limited}));
        };
      `
      : `function setTrainMenuDialog(d){}`;

  const makeStationMenu =
    stationMenu == "true"
      ? `
      //駅メニューダイアログの配置

const setStationMenuDialog = new MutationObserver( (mutations) => {
  const data =[];
  document.querySelectorAll('#disp div div').forEach(d=>d.id.indexOf("st")!= -1 && data.push(d));

  for(let d of data ){
    if(!d.offclick){
      d.offclick = d.onclick.toString();
    }
    d.onclick = () =>{ 
      const s = d.offclick.replace('(event)','').replaceAll("'", "").split('(')[1].split(')')[0].split(',');
      // これの中身抽出 PopUpMenu(event,'2','端岡','http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/hashioka.pdf','https://www.google.co.jp/maps/place/34.305027,133.967643','','1')
      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 data2 =[];
  document.querySelectorAll('#disp > div > div > div > div > font > div').forEach(d=>{
    if(!!d.onclick) data2.push(d);
  })

  for(let d of data2 ){
    if(!d.offclick){
      d.offclick = d.onclick.toString();
    }
    const stationID = d.childNodes[0].innerText;
    const PDFAddress = d.offclick.split("'")[1];
    const Name = d.childNodes[2].innerText;
    //alert(PDFAddress);
    d.onclick = () =>{ 
      //const s = d.offclick.replace('(event)','').replaceAll("'", "").split('(')[1].split(')')[0].split(',');
      // これの中身抽出 PopUpMenu(event,'2','端岡','http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/hashioka.pdf','https://www.google.co.jp/maps/place/34.305027,133.967643','','1')
      window.ReactNativeWebView.postMessage(JSON.stringify({type:"PopUpMenu",id:stationID,name:Name,pdf:PDFAddress}));
    }
  }
});

// 監視を開始
setStationMenuDialog.observe(document.querySelector('#disp'), {
  attributes: true, // 属性変化の監視
  //attributeOldValue: true, // 変化前の属性値を matation.oldValue に格納する
  //characterData: true, // テキストノードの変化を監視
  //characterDataOldValue: true, // 変化前のテキストを matation.oldValue に格納する
  childList: true, // 子ノードの変化を監視
  //subtree: true // 子孫ノードも監視対象に含める
});
`
      : ``;
  return (
    bootData +
    topMenu +
    makeTrainView +
    trainIconMaker +
    makeTrainMenu +
    textInsert +
    makeStationMenu
  );
};
