Cathay Award Search Fixer 2022

Un-Elevate Your Cathay Award Search 2022

目前为 2022-09-01 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Cathay Award Search Fixer 2022
  3. // @name:zh-TW 國泰獎勵機票搜尋引擎修復神器 2022
  4. // @namespace jayliutw
  5. // @version 2.3.1
  6. // @description Un-Elevate Your Cathay Award Search 2022
  7. // @description:zh-TW 國泰航空 2022 里程獎勵機票搜尋引擎「反升級」套件
  8. // @author jayliutw
  9. // @require https://greasyfork.org/scripts/431490-greasyforkscriptupdate/code/GreasyForkScriptUpdate.js?version=1080054
  10. // @connect greasyfork.org
  11. // @match https://*.cathaypacific.com/cx/*/book-a-trip/redeem-flights/redeem-flight-awards.html*
  12. // @match https://book.cathaypacific.com/*
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @grant GM_xmlhttpRequest
  16. // @grant unsafeWindow
  17. // @license GPL
  18. // ==/UserScript==
  19.  
  20. (function() {
  21. 'use strict';
  22.  
  23. function addCss(cssString) {
  24. var head = document.getElementsByTagName('head')[0];
  25. var newCss = document.createElement('style');
  26. newCss.type = "text/css";
  27. newCss.innerHTML = cssString;
  28. head.appendChild(newCss);
  29. }
  30. //GM_setValue("last_update", "2022/08/08");
  31. function show_update(version) {
  32. document.querySelector(".unelevated_update").classList.add("update_show");
  33. document.querySelector("#upd_version").innerText = version;
  34. console.log(version)
  35. }
  36.  
  37. var uef_from = GM_getValue("uef_from", "HKG") || localStorage.getItem("uef_from") || "HKG";
  38. var uef_to = GM_getValue("uef_to", "TYO") || localStorage.getItem("uef_to") || "TYO";
  39. var uef_date = GM_getValue("uef_date", "20230801") || localStorage.getItem("uef_date") || "20230801";
  40. var uef_adult = GM_getValue("uef_adult", "1") || localStorage.getItem("uef_adult") || "1";
  41. var uef_child = GM_getValue("uef_child", "0") || localStorage.getItem("uef_child") || "0";
  42.  
  43. var route_changed = false;
  44.  
  45. addCss (
  46. '.unelevated_form { position:relative;transition: margin-left 0.7s ease-out;z-index: 10; font-family: "GT Walsheim","Cathay Sans EN", CathaySans_Rg, sans-serif; border: 1px solid #bcbec0; margin:10px 0; background: #f7f6f0; padding: 8px 0px 8px 8px; border-top: 5px solid #367778; box-shadow: 0px 0px 7px rgb(0 0 0 / 20%);} ' +
  47. '.unelevated_form.uef_collapsed { margin-left:-90%;} ' +
  48. '.unelevated_title {font-weight: 400; font-size: 17px; font-family: "GT Walsheim","Cathay Sans EN", CathaySans_Lt, sans-serif; color: #2d2d2d; margin: 5px;} '+
  49. '.unelevated_form label { display: inline-block; position: relative; width:50%; padding: 0px 8px 0px 0px; } ' +
  50. '.unelevated_form label span { position: absolute; top: 0px; left: 5px; color: #66686a; font-family: Cathay Sans EN, CathaySans_Rg, sans-serif; line-height: 25px; font-size: 10px;} ' +
  51. '.unelevated_form input { font-family: Cathay Sans EN, CathaySans_Lt, sans-serif; padding: 19px 5px 5px 5px; border-radius: 0px; border: 1px solid #bcbec0; display: inline-block; margin: 0px 8px 8px 0px; height: 45px; width: 100%; font-size:16px} ' +
  52. '.unelevated_form button.uef_search { background-color: #367778; border: none; color: white; display: inline-block;vertical-align: top; margin: 0px; height: 45px; width: calc(50% - 8px);} ' +
  53. '.unelevated_sub { line-height:25px; vertical-align:top;} .coffee_emoji {display:inline-block; line-height:25px; font-size: 25px; margin-left: 6px; vertical-align: top;}' +
  54. '.unelevated_sub a { line-height:25px; vertical-align:top; font-family: Cathay Sans EN, CathaySans_Bd, sans-serif; font-size: 15px !important; text-decoration:underline dotted !important; margin: 0px; color: #ae4b4b !important; font-weight: bold;}' +
  55. '.unelevated_sub a:after { content:none !important; }' +
  56. 'a.uef_toggle, a.uef_toggle:hover { background: #367778; display: block; position: absolute; right: -1px; top: -5px; padding-top:5px; width: 30px; text-align: center; text-decoration: none; color: white !important; padding-bottom: 5px; }' +
  57. 'a.uef_toggle:after {content:\'«\'} .uef_collapsed a.uef_toggle:after {content : \'»\'} ' +
  58. '.bulk_hidden {display:none;}' +
  59. '.bulk_box {min-height: 60px; transition: margin-top 0.7s ease-out;background: #f7f6f0; padding: 8px; border: 1px solid #bcbec0; box-shadow: 0px 0px 7px rgb(0 0 0 / 20%); margin-top: -11px; margin-bottom: 20px; z-index: 9; position: relative;}' +
  60. '.bulk_box_hidden {position:relative; margin-top:-80px;}' +
  61. '.bulk_table { width:100%; border: 1px solid #c6c2c1; margin: 10px 0; font-size: 12px;}' +
  62. '.bulk_table th { text-align:center; font-weight:bold; background: #ebedec; line-height:17px; }' +
  63. '.bulk_table td { background:white; }' +
  64. '.bulk_table tr:nth-child(even) td { background:#f9f9f9; }' +
  65. '.bulk_table th, .bulk_table td { border: 1px solid #c6c2c1; padding: 5px; }' +
  66. '.bulk_table .bulk_date { width:80px; text-align:center; }' +
  67. '.bulk_table .bulk_date a { text-decoration:underline !important; }' +
  68. '.bulk_table td.bulk_flights { padding:5px 5px 0 5px }' +
  69. '.bulk_table .bulk_flights .bulk_no_flights { display:block;padding-bottom:5px; }' +
  70. '.bulk_table .flight_item { display: inline-block; background: #e0e0e0; line-height:15px; padding: 6px; border-radius: 5px; margin-right: 6px; margin-bottom: 5px; white-space: nowrap; }' +
  71. '.bulk_table .flight_item img { line-height: 15px; max-height: 15px; vertical-align: middle; margin-right: 5px; max-width: 20px;}' +
  72. '.bulk_table .flight_item.direct { background: #cbe0cf; }' +
  73. '.bulk_table .flight_item span { padding: 2px 5px; color: white; border-radius: 5px; margin-left: 5px; }' +
  74. 'span.bulk_j { background: #002e6c;}' +
  75. 'span.bulk_f { background: #832c40;}' +
  76. 'span.bulk_p { background: #487c93;}' +
  77. 'span.bulk_y { background: #016564;}' +
  78. '.flight_item span.stopover { color: #909090 !important; display: inline-block; background: white; font-size: 11px; margin: 0px 6px !important; }' +
  79. '.bulk_submit {background-color: #367778; border: none; color: white; vertical-align: middle; margin: 0px auto; height: 45px; line-height: 35px; padding: 5px 0; width: 100%; display: block;}' +
  80. '.bulk_submit img, button.uef_search img {line-height: 35px; height: 25px; display: inline-block; margin-right: 10px; vertical-align: -7px;}' +
  81. '.bulk_searching, .uef_search.searching {background-color: #b9cdc9 !important;}' +
  82. '.col-select-departure-flight > .row:last-of-type { padding-bottom: 140px; }' +
  83. 'span.info-x { border-radius: 5px; padding: 2px 5px; margin-left: 5px; color:white; font-size:10px; font-family: CathaySans_Md; }' +
  84. 'span.info-f { background: #832c40;}' +
  85. 'span.info-j { background: #002e6c;}' +
  86. 'span.info-p { background: #487c93;}' +
  87. 'span.info-y { background: #016564;}' +
  88. '.unelevated_update { border-radius: 5px; background: #f27878; padding: 5px 10px; margin: 10px 8px 0 0; text-align: center; display:none; }'+
  89. '.unelevated_update a { color:white !important; } .unelevated_update a:after { content:none !important; }' +
  90. '.unelevated_update a span { font-weight:bold; font-family: "GT Walsheim","Cathay Sans EN", CathaySans_Md, sans-serif; }'+
  91. '.unelevated_update.update_show { display:block; }'
  92. );
  93.  
  94. var lang = (navigator.language != "zh-TW") ? {
  95. "ec" : "HK",
  96. "el": "en",
  97. "search" : "Search",
  98. "coffee" : "Did this tool help you? Buy me a coffee! ",
  99. "searching" : "<img src='https://book.cathaypacific.com/CathayPacificAwardV3/AML_S65.12/common/skin/img/icons/cx/icon-loading.gif'> Searching...",
  100. "searching_w_cancel" : "<img src='https://book.cathaypacific.com/CathayPacificAwardV3/AML_S65.12/common/skin/img/icons/cx/icon-loading.gif'> Searching... (Click to Stop)",
  101. "next_batch" : "Load More...",
  102. "search_10" : "Batch Availability for 20 Days",
  103. "flights" : "Available Flights",
  104. "first" : "First",
  105. "business" : "Bus",
  106. "premium" : "Prem",
  107. "economy" : "Econ",
  108. "date" : "Date",
  109. "no_flights" : "No Flights",
  110. "expired" : "Search Next 20 (Requires Refresh)",
  111. "searching_cont" : "<img src='https://book.cathaypacific.com/CathayPacificAwardV3/AML_S65.12/common/skin/img/icons/cx/icon-loading.gif'> Please wait... (Page will refresh)",
  112. "super" : "SuperCharged Award Search",
  113. "error" : "Unknown Error... Try Again",
  114. "bulk_batch" : "Batch Search",
  115. "bulk_flights" : "Flights",
  116. "new_version" : "有新版本可更新:"
  117. } : {
  118. "ec" : "TW",
  119. "el": "zh",
  120. "search" : "搜尋",
  121. "coffee" : "這工具有幫到你嗎?歡迎請我喝杯咖啡呀!",
  122. "searching" : "<img src='https://book.cathaypacific.com/CathayPacificAwardV3/AML_S65.12/common/skin/img/icons/cx/icon-loading.gif'> 請稍後...",
  123. "searching_w_cancel" : "<img src='https://book.cathaypacific.com/CathayPacificAwardV3/AML_S65.12/common/skin/img/icons/cx/icon-loading.gif'> 請稍後... (點我暫停)",
  124. "next_batch" : "載人更多...",
  125. "search_10" : "批次搜尋 20 天可兌換航班",
  126. "flights" : "可兌換航班",
  127. "first" : "頭等",
  128. "business" : "商務",
  129. "premium" : "豪經",
  130. "economy" : "經濟",
  131. "date" : "日期",
  132. "no_flights" : "無航班",
  133. "expired" : "再搜尋 20 天 (畫面需重整)",
  134. "searching_cont" : "<img src='https://book.cathaypacific.com/CathayPacificAwardV3/AML_S65.12/common/skin/img/icons/cx/icon-loading.gif'> 請稍後... (視窗將會刷新)",
  135. "super" : "SUPERCharged Award Search",
  136. "error" : "不明錯誤... 再試一次",
  137. "bulk_batch" : "批次查詢",
  138. "bulk_flights" : "航班",
  139. "new_version" : "New Version Available:"
  140. };
  141.  
  142. var cx_json = {
  143. "awardType": "Standard",
  144. "brand": "CX",
  145. "cabinClass": "Y",
  146. "entryCountry": lang.ec,
  147. "entryLanguage": lang.el,
  148. "entryPoint": "https://www.cathaypacific.com/cx/" + lang.el + "_" + lang.ec + "/book-a-trip/redeem-flights/redeem-flight-awards.html",
  149. "errorUrl": "https://www.cathaypacific.com/cx/" + lang.el + "_" + lang.ec + "/book-a-trip/redeem-flights/redeem-flight-awards.html?recent_search=ow",
  150. "isFlexibleDate": false,
  151. "numAdult": 1,
  152. "numChild": 0,
  153. "promotionCode": "",
  154. "returnUrl": "https://www.cathaypacific.com/cx/" + lang.el + "_" + lang.ec + "/book-a-trip/redeem-flights/redeem-flight-awards.html?recent_search=ow",
  155. "segments": [
  156. {
  157. "departureDate": "20230801",
  158. "origin": "TPE",
  159. "destination": "TYO"
  160. }
  161. ]
  162. };
  163.  
  164. var bulk_continue = false;
  165. var limit_reached = false;
  166.  
  167. function isValidDate(dateString)
  168. {
  169. // First check for the pattern
  170. if(!/^\d{8}$/.test(dateString)) return false;
  171.  
  172. // Parse the date parts to integers
  173. var day = dateString.substring(6, 8);
  174. var month = dateString.substring(4, 6);
  175. var year = dateString.substring(0, 4);
  176.  
  177. // Check the ranges of month and year
  178. if(year < 1000 || year > 3000 || month == 0 || month > 12) return false;
  179.  
  180. var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
  181.  
  182. // Adjust for leap years
  183. if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) monthLength[1] = 29;
  184.  
  185. // Check the range of the day
  186. return day > 0 && day <= monthLength[month - 1];
  187. };
  188.  
  189. function waitForElm(selector) {
  190. return new Promise(resolve => {
  191. if (document.querySelector(selector)) {
  192. return resolve(document.querySelector(selector));
  193. }
  194.  
  195. const observer = new MutationObserver(mutations => {
  196. if (document.querySelector(selector)) {
  197. resolve(document.querySelector(selector));
  198. observer.disconnect();
  199. }
  200. });
  201.  
  202. observer.observe(document.body, {
  203. childList: true,
  204. subtree: true
  205. });
  206. });
  207. }
  208.  
  209.  
  210. var cxhttp = new XMLHttpRequest();
  211. cxhttp.onload = function() {
  212. var response = JSON.parse(this.responseText);
  213. cxform(response.parameters);
  214. }
  215.  
  216. function cxsearch(string){
  217. cxhttp.withCredentials = true;
  218. cxhttp.open("POST", "https://api.cathaypacific.com/redibe/standardAward/create");
  219. cxhttp.setRequestHeader("Content-type", "application/json");
  220. cxhttp.send(string);
  221. }
  222.  
  223. function cxform(parameters) {
  224.  
  225. // Create a form dynamically
  226. var form = document.createElement("form");
  227. var action = "https://book.cathaypacific.com/CathayPacificAwardV3/dyn/air/booking/availability";
  228. if (bulk_continue) action += "?bulk_continue=1"
  229. form.setAttribute("name", "cxform");
  230. form.setAttribute("method", "post");
  231. form.setAttribute("action", action);
  232.  
  233. for(var item in parameters) {
  234. var input = document.createElement("input");
  235. input.setAttribute("type", "hidden");
  236. input.setAttribute("name", item);
  237. input.setAttribute("value", parameters[item]);
  238. form.appendChild(input);
  239. }
  240.  
  241. document.getElementsByTagName("body")[0].appendChild(form);
  242. document.forms.cxform.submit();
  243. }
  244.  
  245. function addtoBulk(html){
  246. document.querySelector(".bulk_table tbody").insertAdjacentHTML("beforeend", html);
  247. }
  248.  
  249. var bulk_http = new XMLHttpRequest();
  250. var bulk_url = (typeof formSubmitUrl !== 'undefined') ? formSubmitUrl : "";
  251. var bulk_date = "";
  252. var bulk_limit = 21;
  253. bulk_http.onreadystatechange = function() {//Call a function when the state changes.
  254. if(bulk_http.readyState == 4 && bulk_http.status == 200) {
  255. console.log(bulk_http);
  256. bulk_date = bulk_date ? bulk_date : document.querySelector("input[name=uef_date]").value;
  257. var search_year = +bulk_date.substring(0, 4);
  258. var search_month = +bulk_date.substring(4, 6);
  259. var search_day = +bulk_date.substring(6, 8);
  260. var search_date = new Date(search_year, search_month - 1, search_day);
  261. var responseText = JSON.parse(bulk_http.responseText);
  262. var response = JSON.parse(responseText.pageBom);
  263. var flights = response.modelObject?.availabilities?.upsell?.bounds[0].flights || [];
  264. var flightHTML = "";
  265. var formatted_date = search_date.getFullYear() +"-"+ (search_date.getMonth() +1).toString().padStart(2, '0') +"-"+ search_date.getDate().toString().padStart(2, '0');
  266. flightHTML += "<tr><td class='bulk_date'>";
  267. flightHTML += "<a href='javascript:void();' data-date='" + formatted_date.replaceAll("-","") + "'>" + formatted_date + "</a>";
  268. flightHTML += "</td><td class='bulk_flights'>";
  269. var noflights = true;
  270. flights.forEach((flight) => {
  271. var available = "";
  272. var f1 = flight.segments[0].cabins?.F?.status || 0;
  273. var j1 = flight.segments[0].cabins?.B?.status || 0;
  274. var p1 = flight.segments[0].cabins?.N?.status || 0;
  275. var y1 = (+flight.segments[0].cabins?.E?.status || 0) + (+flight.segments[0].cabins?.R?.status || 0);
  276. if(flight.segments.length == 1) {
  277. if (f1 >= 1) available = available + " <span class='bulk_f'>F <b>" + f1 + "</b></span>";
  278. if (j1 >= 1) available = available + " <span class='bulk_j'>J <b>" + j1 + "</b></span>";
  279. if (p1 >= 1) available = available + " <span class='bulk_p'>PY <b>" + p1 + "</b></span>";
  280. if (y1 >= 1) available = available + " <span class='bulk_y'>Y <b>" + y1 + "</b></span>";
  281. if (available != "") {
  282. flightHTML += "<span class='flight_item direct'><img src='https://book.cathaypacific.com/CathayPacificAwardV3/AML_S65.15/common/skin/img/airlines/logo-" + flight.segments[0].flightIdentifier.marketingAirline.toLowerCase() + ".png'>" + flight.segments[0].flightIdentifier.marketingAirline + flight.segments[0].flightIdentifier.flightNumber + available + "</span>";
  283. noflights = false;
  284. }
  285. } else {
  286. var f2 = flight.segments[1].cabins?.F?.status || 0;
  287. var j2 = flight.segments[1].cabins?.B?.status || 0;
  288. var p2 = flight.segments[1].cabins?.N?.status || 0;
  289. var y2 = (+flight.segments[1].cabins?.E?.status || 0) + (+flight.segments[1].cabins?.R?.status || 0);
  290. if (f1 >= 1 && f2 >= 1) available = available + " <span class='bulk_f'>F <b>" + Math.max(f1, f2) + "</b></span>";
  291. if (j1 >= 1 && j2 >= 1) available = available + " <span class='bulk_j'>J <b>" + Math.max(j1, j2) + "</b></span>";
  292. if (p1 >= 1 && p2 >= 1) available = available + " <span class='bulk_p'>PY <b>" + Math.max(p1, p2) + "</b></span>";
  293. if (y1 >= 1 && y2 >= 1) available = available + " <span class='bulk_y'>Y <b>" + Math.max(y1, y2) + "</b></span>";
  294. if (available != "") {
  295. flightHTML += "<span class='flight_item'><img src='https://book.cathaypacific.com/CathayPacificAwardV3/AML_S65.15/common/skin/img/airlines/logo-" + flight.segments[0].flightIdentifier.marketingAirline.toLowerCase() + ".png'>" + flight.segments[0].flightIdentifier.marketingAirline + flight.segments[0].flightIdentifier.flightNumber + "<span class='stopover'>" + /^[A-Z]{3}:([A-Z:]{3,7}):[A-Z]{3}_/g.exec(flight.flightIdString)[1].replace(":"," / ") + "</span>" + flight.segments[1].flightIdentifier.marketingAirline + flight.segments[1].flightIdentifier.flightNumber + available + "</span>";
  296. noflights = false;
  297. }
  298. }
  299. });
  300. if (noflights) flightHTML += "<span class='bulk_no_flights'>"+lang.no_flights+"</span>";
  301. flightHTML += "</td></tr>";
  302. addtoBulk(flightHTML);
  303. var next_date = new Date(search_year, search_month - 1, search_day + 1);
  304. bulk_date = next_date.getFullYear() +""+ (next_date.getMonth() +1).toString().padStart(2, '0') +""+ next_date.getDate().toString().padStart(2, '0');
  305. bulk_search();
  306. } else if (bulk_http.readyState == 4 && bulk_http.status >= 400) {
  307. console.log(bulk_http);
  308. document.querySelector(".bulk_submit").innerHTML = lang.expired;
  309. limit_reached = true;
  310. bulk_limit = 21;
  311. document.querySelector(".bulk_submit").classList.remove("bulk_searching");
  312. } else if (bulk_http.readyState == 4 && bulk_http.status >= 300) {
  313. document.querySelector(".bulk_submit").classList.remove("bulk_searching");
  314. document.querySelector(".bulk_submit").innerHTML = lang.error;
  315. }
  316.  
  317. console.log(bulk_http);
  318. }
  319.  
  320. function single_date(date){
  321. document.querySelector("#uef_date").value = date;
  322. document.querySelector(".bulk_submit").innerHTML = lang.searching_w_cancel;
  323. document.querySelector(".uef_search").click();
  324. }
  325.  
  326.  
  327. function bulk_search() {
  328. if(limit_reached || route_changed) {
  329. bulk_continue = true;
  330. document.querySelector("#uef_date").value = bulk_date;
  331. document.querySelector(".bulk_submit").innerHTML = lang.searching_w_cancel;
  332. document.querySelector(".uef_search").click();
  333. return;
  334. } else if (--bulk_limit <= 0) {
  335. document.querySelector(".bulk_submit").innerText = lang.next_batch;
  336. document.querySelector(".bulk_submit").classList.remove("bulk_searching");
  337. return;
  338. }
  339. bulk_date = bulk_date ? bulk_date : document.querySelector("input[name=uef_date]").value;
  340. var search_year = +bulk_date.substring(0, 4);
  341. var search_month = +bulk_date.substring(4, 6);
  342. var search_day = +bulk_date.substring(6, 8);
  343. var search_date = new Date(search_year, search_month - 1, search_day);
  344. var new_date = search_date.getFullYear() +""+ (search_date.getMonth() + 1).toString().padStart(2, '0') +""+ search_date.getDate().toString().padStart(2, '0') + "0000";
  345. var params = document.querySelector("form[name=MNMB_FACADE_FORM] input[name=ENTRY_REQUEST]").value;
  346. params = params.replace('&ENCT=2', '').replace('&SERVICE_ID=1', '').replace('&DIRECT_LOGIN=YES', '').replace('&B_DATE_1', '&OLD_DATE').replace(/(&ENC=[^&]+)/g,"");
  347. params = params + "WDS_PRE_STEP=SCHEDULE_DRIVEN&WDS_CURRENT_STEP=SCHEDULE_DRIVEN&WDS_TIER_SELECTED=STD&WDS_SELECTED_TIER=STD&PAGE_TICKET=0&&WDS_DATE=" + new_date + "&DDS_PROMO_SELECTED=FALSE&B_DATE_1=" + new_date ;
  348. bulk_http.open('POST', bulk_url, true);
  349.  
  350. //Send the proper header information along with the request
  351. bulk_http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  352. bulk_http.setRequestHeader('Accept', 'application/json, text/plain, */*');
  353.  
  354. bulk_http.send(params);
  355. }
  356.  
  357. function insertBulk(elm){
  358. elm.insertAdjacentHTML("beforeend", "<div class='bulk_box'><div>" +
  359. "<table class='bulk_table bulk_hidden'><thead><th class='bulk_date'>" + lang.date + "</th><th class='bulk_flights'>" + lang.flights + " <span class='info-x info-f'>" + lang.first + "</span><span class='info-x info-j'>" + lang.business + "</span><span class='info-x info-p'>" + lang.premium + "</span><span class='info-x info-y'>" + lang.economy + "</span></th></thead><tbody></tbody></table>" +
  360. "</div>" +
  361. "<button class='bulk_submit'>" + lang.search_10 + "</button>" +
  362. "</div>");
  363.  
  364. document.querySelector(".bulk_submit").addEventListener("click",function(e){
  365. if (route_changed) {
  366. bulk_continue = true;
  367. document.querySelector(".bulk_submit").innerHTML = lang.searching_w_cancel;
  368. document.querySelector(".uef_search").click();
  369. } else {
  370. document.querySelector(".bulk_table").classList.remove("bulk_hidden");
  371. console.log(bulk_limit);
  372. if (bulk_limit != 21 && bulk_limit != 0 && bulk_limit != -1){
  373. bulk_limit = 0;
  374. document.querySelector(".bulk_submit").innerText = lang.next_batch;
  375. document.querySelector(".bulk_submit").classList.remove("bulk_searching");
  376. } else {
  377. bulk_limit = 21;
  378. document.querySelector(".bulk_submit").innerHTML = lang.searching_w_cancel;
  379. document.querySelector(".bulk_submit").classList.add("bulk_searching");
  380. bulk_search();
  381. }
  382. }
  383. });
  384.  
  385. document.querySelector(".bulk_table").addEventListener("click",function(e){
  386. if(e.target.dataset.date) {
  387. bulk_limit = 0;
  388. single_date(e.target.dataset.date)
  389. }
  390. });
  391. /*
  392. if(GM_getValue("bulk_show") == true || localStorage.getItem("bulk_show") == true) {
  393. document.querySelector(".unelevated_title").innerText = lang.super;
  394. document.querySelector(".bulk_box").classList.remove("bulk_box_hidden");
  395. }
  396. */
  397. const queryString = window.location.search;
  398. const urlParams = new URLSearchParams(queryString);
  399. const bcont_query = urlParams.get('bulk_continue');
  400. if (bcont_query) {
  401. document.querySelector(".bulk_submit").innerHTML = lang.searching_w_cancel;
  402. document.querySelector(".bulk_submit").classList.add("bulk_searching");
  403. waitForElm('form[name=MNMB_FACADE_FORM] input[name=ENTRY_REQUEST]').then((elm) => {
  404. setTimeout(() => {
  405. document.querySelector(".bulk_submit").click();
  406. }, "1000")
  407. });
  408. }
  409. }
  410.  
  411. function insertForm(elm){
  412. elm.insertAdjacentHTML("beforeend", "<div class='unelevated_form'>" +
  413. "<div class='unelevated_title'>Unelevated Award Search</div>" +
  414. "<label><span>From</span><input type='text' onClick='this.select();' id='uef_from' name='uef_from' placeholder='TPE' value='" + uef_from + "'></label>" +
  415. "<label><span>To</span><input type='text' onClick='this.select();' id='uef_to' name='uef_to' placeholder='TYO' value='" + uef_to + "'></label>" +
  416. "<label><span>Adults</span><input type='number' inputmode='decimal' onClick='this.select();' id='uef_adult' name='uef_adult' placeholder='Adults' value='" + uef_adult + "'></label>" +
  417. "<label><span>Children</span><input type='number' inputmode='decimal' onClick='this.select();' id='uef_child' name='uef_child' placeholder='Children' value='" + uef_child + "'></label>" +
  418. "<label><span>Date</span><input class='uef_date' onClick='this.setSelectionRange(6, 8);' id='uef_date' type='number' inputmode='decimal' name='uef_date' placeholder='20221001' value='" + uef_date + "'></label>" +
  419. "<button class='uef_search'>" + lang.search + "</button>" +
  420. "<div class='unelevated_sub'><a href='https://jayliu.net/buymeacoffee' target='_blank'>" + lang.coffee + "</a><span class='coffee_emoji'>☕</span></div>" +
  421. "<div class='unelevated_update'><a href='https://greasyfork.org/en/scripts/449998-cathay-award-search-fixer-2022' target='_blank'>"+ lang.new_version +" <span id='upd_version'>2.1.3</span> &raquo;</a></div>" +
  422. //"<a href='javascript:void();' class='uef_toggle'></a>" +
  423. "</div>");
  424.  
  425. /*document.querySelector(".uef_toggle").addEventListener("click",function(e){
  426. document.querySelector(".unelevated_form").classList.toggle("uef_collapsed")
  427. });*/
  428.  
  429. document.querySelector(".unelevated_form input[name=uef_from]").addEventListener("change",function(e){
  430. this.value = this.value.toUpperCase().split(' ').join('').substring(0, 3);
  431. route_changed = true;
  432. if(document.querySelector(".bulk_submit")) {
  433. document.querySelector(".bulk_submit").innerHTML = lang.bulk_batch + " " + document.querySelector(".unelevated_form input[name=uef_from]").value + " - " + document.querySelector(".unelevated_form input[name=uef_to]").value + " " + lang.bulk_flights;
  434. }
  435. });
  436. document.querySelector(".unelevated_form input[name=uef_to]").addEventListener("change",function(e){
  437. this.value = this.value.toUpperCase().split(' ').join('').substring(0, 3);
  438. route_changed = true;
  439. if(document.querySelector(".bulk_submit")) {
  440. document.querySelector(".bulk_submit").innerHTML = lang.bulk_batch + " " + document.querySelector(".unelevated_form input[name=uef_from]").value + " - " + document.querySelector(".unelevated_form input[name=uef_to]").value + " " + lang.bulk_flights;
  441. }
  442. });
  443. document.querySelector(".unelevated_form input[name=uef_date]").addEventListener("change",function(e){
  444. if (!isValidDate(this.value)) {
  445. var default_date = new Date(new Date().getTime()+(5*24*60*60*1000));
  446. alert("Invalid Date");
  447. this.value = default_date.getFullYear() + (default_date.getMonth() +1).toString().padStart(2, '0') + default_date.getDate().toString().padStart(2, '0');
  448. }
  449. });
  450. /*
  451. var secret_mode = 0;
  452. document.querySelector(".unelevated_title").addEventListener("click",function(e){
  453. if(++secret_mode == 9) {
  454. document.querySelector(".unelevated_title").innerText = lang.super;
  455. document.querySelector(".bulk_box").classList.remove("bulk_box_hidden");
  456. localStorage.setItem("bulk_show",true);
  457. GM_setValue("bulk_show",true);
  458. }
  459. });*/
  460. /*
  461.  
  462. var last_update = new Date(GM_getValue("last_update")) || false;
  463. var current_update = new Date();
  464. current_update = new Date(current_update.getFullYear(),current_update.getMonth() +1,current_update.getDate() );
  465.  
  466. if (!last_update || current_update.getTime() - last_update.getTime() >= 86400000) {
  467. var GFU = new GreasyForkUpdater();
  468. GFU.checkUpdate(449998, GM_info.script.version, function(update, updateurl, metaData) {
  469. if (update != false) {
  470. show_update(metaData.version);
  471. console.log(updateurl);
  472. console.log(metaData.version);
  473. //https://greasyfork.org/en/scripts/449998-cathay-award-search-fixer-2022
  474. GM_setValue("latest_version",metaData.version);
  475. } else {
  476. GM_setValue("latest_version",GM_info.script.version);
  477. }
  478. GM_setValue("last_update", current_update.getFullYear() +"/"+ (current_update.getMonth() +1).toString().padStart(2, '0') +"/"+ current_update.getDate().toString().padStart(2, '0'));
  479. });
  480. } else if (GM_getValue("latest_version") != GM_info.script.version) {
  481. show_update(GM_getValue("latest_version"));
  482. }
  483. */
  484.  
  485. document.querySelector(".uef_search").addEventListener("click",function(e){
  486. uef_from = document.querySelector("#uef_from").value;
  487. uef_to = document.querySelector("#uef_to").value;
  488. uef_date = document.querySelector("#uef_date").value;
  489. uef_adult = document.querySelector("#uef_adult").value;
  490. uef_child = document.querySelector("#uef_child").value;
  491. localStorage.setItem("uef_from",uef_from);
  492. localStorage.setItem("uef_to",uef_to);
  493. localStorage.setItem("uef_date",uef_date);
  494. localStorage.setItem("uef_adult",uef_adult);
  495. localStorage.setItem("uef_child",uef_child);
  496. GM_setValue("uef_from",uef_from);
  497. GM_setValue("uef_to",uef_to);
  498. GM_setValue("uef_date",uef_date);
  499. GM_setValue("uef_adult",uef_adult);
  500. GM_setValue("uef_child",uef_child);
  501. cx_json.numAdult = uef_adult;
  502. cx_json.numChild = uef_child;
  503. cx_json.segments[0].departureDate = uef_date;
  504. cx_json.segments[0].origin = uef_from.toUpperCase();
  505. cx_json.segments[0].destination = uef_to.toUpperCase();
  506. var cx_string = JSON.stringify(cx_json);
  507. document.querySelector(".uef_search").innerHTML = lang.searching;
  508. document.querySelector(".uef_search").classList.add("searching");
  509. cxsearch(cx_string);
  510. });
  511. }
  512.  
  513.  
  514.  
  515. window.addEventListener('load', function() {
  516. if(document.querySelector('.redibe-v3-flightsearch-description')) {
  517. insertForm(document.querySelector('.redibe-v3-flightsearch-description'));
  518. } else {
  519. waitForElm('.redibe-v3-flightsearch-description').then((elm) => {
  520. insertForm(elm);
  521. });
  522. }
  523. if(document.querySelector('.bound-route')) {
  524. insertForm(document.querySelector('.bound-route'));
  525. insertBulk(document.querySelector('.bound-route'));
  526. } else {
  527. waitForElm('.bound-route').then((elm) => {
  528. insertForm(elm);
  529. insertBulk(elm);
  530. });
  531. }
  532. });
  533.  
  534.  
  535. })();