From 5fcaa30be53385038c9f5c80ad7f4d16e4d22754 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 17 Jan 2024 12:21:33 +0800 Subject: [PATCH] add extension to handle hkticketing --- webdriver/Maxbotplus_1.0.0/background.js | 7 ++++ .../Maxbotplus_1.0.0/js/cityline_msg_front.js | 7 +++- .../js/hkticketing_queue_background.js | 32 +++++++++++++++ .../js/hkticketing_queue_front.js | 41 +++++++++++++++++++ webdriver/Maxbotplus_1.0.0/manifest.json | 22 ++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 webdriver/Maxbotplus_1.0.0/js/hkticketing_queue_background.js create mode 100644 webdriver/Maxbotplus_1.0.0/js/hkticketing_queue_front.js diff --git a/webdriver/Maxbotplus_1.0.0/background.js b/webdriver/Maxbotplus_1.0.0/background.js index 8f29bc9..5d35761 100644 --- a/webdriver/Maxbotplus_1.0.0/background.js +++ b/webdriver/Maxbotplus_1.0.0/background.js @@ -162,6 +162,13 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { const tabId = sender.tab.id; ocr(request_json.data.url, request_json.data.image_data, tabId); } + + if(request_json.action=="status") { + result_json={"status": answer}; + const tabId = sender.tab.id; + chrome.tabs.sendMessage(tabId, result_json); + } + }); diff --git a/webdriver/Maxbotplus_1.0.0/js/cityline_msg_front.js b/webdriver/Maxbotplus_1.0.0/js/cityline_msg_front.js index cd23ae6..3d75b14 100644 --- a/webdriver/Maxbotplus_1.0.0/js/cityline_msg_front.js +++ b/webdriver/Maxbotplus_1.0.0/js/cityline_msg_front.js @@ -14,6 +14,11 @@ function begin() auto_reload_page_interval = settings.advanced.auto_reload_page_interval; } + // too short to cause error. + if(auto_reload_page_interval < 0.5) { + auto_reload_page_interval = 0.5; + } + if(status=='ON') { setInterval(() => { retry(); @@ -23,7 +28,7 @@ function begin() function dom_ready() { - console.log("checking..."); + //console.log("checking..."); if($("#settings").length>0) { clearInterval(myInterval); begin(); diff --git a/webdriver/Maxbotplus_1.0.0/js/hkticketing_queue_background.js b/webdriver/Maxbotplus_1.0.0/js/hkticketing_queue_background.js new file mode 100644 index 0000000..2e0a644 --- /dev/null +++ b/webdriver/Maxbotplus_1.0.0/js/hkticketing_queue_background.js @@ -0,0 +1,32 @@ +const storage = chrome.storage.local; +var settings = null; + +function hkticketing_msg_start(status) +{ + if(settings) { + let settings_div=""; + $("body").append(settings_div); + let status_div=""; + $("body").append(status_div); + console.log("dom append"); + } +} + +storage.get('settings', function (items) +{ + if (items.settings) + { + settings = items.settings; + } +}); + +storage.get('status', function (items) +{ + if (items.status && items.status=='ON') + { + hkticketing_msg_start(items.status); + } else { + console.log('no status found'); + } +}); + diff --git a/webdriver/Maxbotplus_1.0.0/js/hkticketing_queue_front.js b/webdriver/Maxbotplus_1.0.0/js/hkticketing_queue_front.js new file mode 100644 index 0000000..5cb41cf --- /dev/null +++ b/webdriver/Maxbotplus_1.0.0/js/hkticketing_queue_front.js @@ -0,0 +1,41 @@ +function begin() +{ + const settings_div = document.querySelector('#settings'); + const status_div = document.querySelector('#status'); + let settings = JSON.parse(settings_div.innerHTML); + let status = status_div.innerHTML; + console.log("msg"); + console.log(settings); + console.log(status); + + let auto_reload_page_interval = 0.0; + if(settings) { + auto_reload_page_interval = settings.advanced.auto_reload_page_interval; + } + + // too short to cause error. + if(auto_reload_page_interval < 0.8) { + auto_reload_page_interval = 0.8; + } + + if(status=='ON') { + setInterval(() => { + busyFor = 0; + reload(); + }, auto_reload_page_interval * 1000); + } +} + +function dom_ready() +{ + //console.log("checking..."); + const settings_div = document.querySelector('#settings'); + if(settings_div) { + clearInterval(myInterval); + begin(); + } +} + +myInterval = setInterval(() => { + dom_ready(); +}, 100); diff --git a/webdriver/Maxbotplus_1.0.0/manifest.json b/webdriver/Maxbotplus_1.0.0/manifest.json index ebc8b76..1b518bc 100644 --- a/webdriver/Maxbotplus_1.0.0/manifest.json +++ b/webdriver/Maxbotplus_1.0.0/manifest.json @@ -245,6 +245,28 @@ "js/ibon_ticket_next.js" ] }, + { + "matches": [ + "https://queue.hkticketing.com/hotshow.html", + "https://busy.hkticketing.com/" + ], + "run_at": "document_end", + "js": [ + "jquery.min.js", + "js/hkticketing_queue_background.js" + ] + }, + { + "matches": [ + "https://queue.hkticketing.com/hotshow.html", + "https://busy.hkticketing.com/" + ], + "run_at": "document_end", + "world": "MAIN", + "js": [ + "js/hkticketing_queue_front.js" + ] + }, { "matches": [ "https://msg.cityline.com/*.html*"