Cathay Award Search Fixer 2022

Un-Elevate Your Cathay Award Search 2022

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

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