From d5e942da744ba5a84aba544b77383b30cbaacff7 Mon Sep 17 00:00:00 2001 From: unknown <2303063@ad.nchc.org.tw> Date: Fri, 5 Jan 2024 16:10:13 +0800 Subject: [PATCH] 2023-12-25 MaxBot settings able to stop extension. --- chrome_tixcraft.py | 30 +++++++++++-- config_launcher.py | 2 +- settings.py | 2 +- text_server.py | 2 +- webdriver/Maxbot_1.0.0/background.js | 11 +---- webdriver/Maxbot_1.0.0/data/settings.json | 2 +- ...s_new.js => kktix_registrations_reload.js} | 0 webdriver/Maxbot_1.0.0/manifest.json | 6 +-- .../Maxbot_1.0.0/modules/heartbeatconnect.js | 45 +++++++++++++++++++ 9 files changed, 80 insertions(+), 20 deletions(-) rename webdriver/Maxbot_1.0.0/js/{kktix_registrations_new.js => kktix_registrations_reload.js} (100%) diff --git a/chrome_tixcraft.py b/chrome_tixcraft.py index b1a9ec3..0fc6124 100644 --- a/chrome_tixcraft.py +++ b/chrome_tixcraft.py @@ -54,13 +54,15 @@ import webbrowser import chromedriver_autoinstaller -CONST_APP_VERSION = "MaxBot (2023.12.24)" +CONST_APP_VERSION = "MaxBot (2023.12.25)" CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt" CONST_MAXBOT_INT28_FILE = "MAXBOT_INT28_IDLE.txt" CONST_MAXBOT_ANSWER_ONLINE_FILE = "MAXBOT_ONLINE_ANSWER.txt" CONST_MAXBOT_QUESTION_FILE = "MAXBOT_QUESTION.txt" +MAXBOT_EXTENSION_NAME = "Maxbot_1.0.0" +MAXBOT_EXTENSION_STATUS_JSON = "status.json" CONST_HOMEPAGE_DEFAULT = "https://tixcraft.com" URL_CHROME_DRIVER = 'https://chromedriver.chromium.org/' @@ -380,7 +382,7 @@ def get_favoriate_extension_path(webdriver_path, config_dict): extension_list = [] if config_dict["advanced"]["adblock_plus_enable"]: extension_list.append(os.path.join(webdriver_path,"Adblock_3.21.1.0.crx")) - extension_list.append(os.path.join(webdriver_path,"Maxbot_1.0.0.crx")) + extension_list.append(os.path.join(webdriver_path, MAXBOT_EXTENSION_NAME + ".crx")) return extension_list def get_chromedriver_path(webdriver_path): @@ -593,7 +595,7 @@ def get_uc_options(uc, config_dict, webdriver_path): ext = ext.replace('.crx','') if os.path.exists(ext): # sync config. - if "Maxbot_" in ext: + if MAXBOT_EXTENSION_NAME in ext: target_path = ext target_path = os.path.join(target_path, "data") target_path = os.path.join(target_path, "settings.json") @@ -12229,6 +12231,27 @@ def get_current_url(driver): return url, is_quit_bot +def sync_status_to_extension(status): + Root_Dir = get_app_root() + webdriver_path = os.path.join(Root_Dir, "webdriver") + target_path = os.path.join(webdriver_path, MAXBOT_EXTENSION_NAME) + target_path = os.path.join(target_path, "data") + target_path = os.path.join(target_path, MAXBOT_EXTENSION_STATUS_JSON) + #print("save as to:", target_path) + status_json={} + status_json["status"]=status + #print("dump json to path:", target_path) + if not status: + with open(target_path, 'w') as outfile: + json.dump(status_json, outfile) + else: + if os.path.exists(target_path): + try: + os.unlink(target_path) + except Exception as exc: + print(exc) + pass + def main(args): config_dict = get_config_dict(args) @@ -12315,6 +12338,7 @@ def main(args): is_maxbot_paused = False if os.path.exists(CONST_MAXBOT_INT28_FILE): is_maxbot_paused = True + sync_status_to_extension(not is_maxbot_paused) if len(url) > 0 : if url != last_url: diff --git a/config_launcher.py b/config_launcher.py index 6b1a4a7..03a1b24 100644 --- a/config_launcher.py +++ b/config_launcher.py @@ -22,7 +22,7 @@ import sys import threading import webbrowser -CONST_APP_VERSION = "MaxBot (2023.12.24)" +CONST_APP_VERSION = "MaxBot (2023.12.25)" CONST_MAXBOT_LAUNCHER_FILE = "config_launcher.json" CONST_MAXBOT_CONFIG_FILE = "settings.json" diff --git a/settings.py b/settings.py index 8ad2f26..7937e9c 100644 --- a/settings.py +++ b/settings.py @@ -34,7 +34,7 @@ import ssl ssl._create_default_https_context = ssl._create_unverified_context -CONST_APP_VERSION = "MaxBot (2023.12.24)" +CONST_APP_VERSION = "MaxBot (2023.12.25)" CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt" diff --git a/text_server.py b/text_server.py index c43dcff..eed9a33 100644 --- a/text_server.py +++ b/text_server.py @@ -27,7 +27,7 @@ import pyperclip import tornado from tornado.web import Application -CONST_APP_VERSION = "MaxBot (2023.12.24)" +CONST_APP_VERSION = "MaxBot (2023.12.25)" CONST_MAXBOT_QUESTION_FILE = "MAXBOT_QUESTION.txt" diff --git a/webdriver/Maxbot_1.0.0/background.js b/webdriver/Maxbot_1.0.0/background.js index 1199d67..526d9d0 100644 --- a/webdriver/Maxbot_1.0.0/background.js +++ b/webdriver/Maxbot_1.0.0/background.js @@ -56,16 +56,7 @@ let heartbeatInterval; async function runHeartbeat() { //console.log("runHeartbeat"); - chrome.storage.local.get('status', function (items) - { - console.log(items); - if (items.status && items.status=='ON') - { - heartbeatconnect.start(); - } else { - console.log('no status found'); - } - }); + heartbeatconnect.start(); } async function startHeartbeat() diff --git a/webdriver/Maxbot_1.0.0/data/settings.json b/webdriver/Maxbot_1.0.0/data/settings.json index 4add0fc..ad94138 100644 --- a/webdriver/Maxbot_1.0.0/data/settings.json +++ b/webdriver/Maxbot_1.0.0/data/settings.json @@ -1 +1 @@ -{"homepage": "https://kktix.com", "browser": "chrome", "language": "\u7e41\u9ad4\u4e2d\u6587", "ticket_number": 2, "ocr_captcha": {"enable": true, "beta": true, "force_submit": true, "image_source": "canvas"}, "webdriver_type": "undetected_chromedriver", "kktix": {"auto_press_next_step_button": true, "auto_fill_ticket_number": true}, "tixcraft": {"date_auto_select": {"enable": true, "date_keyword": "", "mode": "random"}, "pass_date_is_sold_out": true, "auto_reload_coming_soon_page": true}, "area_auto_select": {"enable": true, "mode": "random", "area_keyword": ""}, "keyword_exclude": "\"\u8f2a\u6905\",\"\u8eab\u969c\",\"\u8eab\u5fc3 \u969c\u7919\",\"Restricted View\",\"\u71c8\u67f1\u906e\u853d\",\"\u8996\u7dda\u4e0d\u5b8c\u6574\"", "advanced": {"play_captcha_sound": {"enable": true, "filename": "ding-dong.wav"}, "tixcraft_sid": "", "ibonqware": "", "facebook_account": "", "kktix_account": "", "fami_account": "", "cityline_account": "", "urbtix_account": "", "hkticketing_account": "", "kham_account": "", "ticket_account": "", "udn_account": "", "ticketplus_account": "", "facebook_password": "", "kktix_password": "", "fami_password": "", "urbtix_password": "", "cityline_password": "", "hkticketing_password": "", "kham_password": "", "ticket_password": "", "udn_password": "", "ticketplus_password": "", "adblock_plus_enable": false, "disable_adjacent_seat": false, "hide_some_image": true, "block_facebook_network": false, "headless": false, "verbose": true, "auto_guess_options": true, "user_guess_string": "", "online_dictionary_url": "", "auto_reload_page_interval": 1.0, "auto_reload_random_delay": false, "proxy_server_port": ""}} \ No newline at end of file +{"homepage": "https://tixcraft.com", "browser": "chrome", "language": "\u7e41\u9ad4\u4e2d\u6587", "ticket_number": 2, "ocr_captcha": {"enable": true, "beta": true, "force_submit": true, "image_source": "canvas"}, "webdriver_type": "undetected_chromedriver", "kktix": {"auto_press_next_step_button": true, "auto_fill_ticket_number": true}, "tixcraft": {"date_auto_select": {"enable": true, "date_keyword": "", "mode": "random"}, "pass_date_is_sold_out": true, "auto_reload_coming_soon_page": true}, "area_auto_select": {"enable": true, "mode": "random", "area_keyword": ""}, "keyword_exclude": "\"\u8f2a\u6905\",\"\u8eab\u969c\",\"\u8eab\u5fc3 \u969c\u7919\",\"Restricted View\",\"\u71c8\u67f1\u906e\u853d\",\"\u8996\u7dda\u4e0d\u5b8c\u6574\"", "advanced": {"play_captcha_sound": {"enable": true, "filename": "ding-dong.wav"}, "tixcraft_sid": "", "ibonqware": "", "facebook_account": "", "kktix_account": "", "fami_account": "", "cityline_account": "", "urbtix_account": "", "hkticketing_account": "", "kham_account": "", "ticket_account": "", "udn_account": "", "ticketplus_account": "", "facebook_password": "", "kktix_password": "", "fami_password": "", "urbtix_password": "", "cityline_password": "", "hkticketing_password": "", "kham_password": "", "ticket_password": "", "udn_password": "", "ticketplus_password": "", "adblock_plus_enable": false, "disable_adjacent_seat": false, "hide_some_image": true, "block_facebook_network": false, "headless": false, "verbose": false, "auto_guess_options": true, "user_guess_string": "", "online_dictionary_url": "", "auto_reload_page_interval": 1.0, "auto_reload_random_delay": false, "proxy_server_port": ""}} \ No newline at end of file diff --git a/webdriver/Maxbot_1.0.0/js/kktix_registrations_new.js b/webdriver/Maxbot_1.0.0/js/kktix_registrations_reload.js similarity index 100% rename from webdriver/Maxbot_1.0.0/js/kktix_registrations_new.js rename to webdriver/Maxbot_1.0.0/js/kktix_registrations_reload.js diff --git a/webdriver/Maxbot_1.0.0/manifest.json b/webdriver/Maxbot_1.0.0/manifest.json index 9844f0b..42d64d0 100644 --- a/webdriver/Maxbot_1.0.0/manifest.json +++ b/webdriver/Maxbot_1.0.0/manifest.json @@ -35,7 +35,7 @@ ], "web_accessible_resources": [ { - "resources": [ "data/settings.json" ], + "resources": [ "data/*.json" ], "extension_ids": ["*"], "matches": [ "*://*/*" ] } @@ -143,8 +143,8 @@ "matches" : [ "https://kktix.com/events/*/registrations/new" ], - "run_at": "document_end", - "js" : [ "jquery.min.js", "js/kktix_registrations_new.js" ] + "run_at": "document_start", + "js" : [ "jquery.min.js", "js/kktix_registrations_reload.js" ] } ], "version": "1.0.0" diff --git a/webdriver/Maxbot_1.0.0/modules/heartbeatconnect.js b/webdriver/Maxbot_1.0.0/modules/heartbeatconnect.js index 7aaaa18..8d9a233 100644 --- a/webdriver/Maxbot_1.0.0/modules/heartbeatconnect.js +++ b/webdriver/Maxbot_1.0.0/modules/heartbeatconnect.js @@ -11,7 +11,10 @@ class HeartBeatConnector //console.log("start heart beat connector"); //load_font.loadFont(); + sync_status_from_parent(); + // Query the active tab before injecting the content script + /* chrome.tabs.query( { active: true, @@ -36,9 +39,51 @@ class HeartBeatConnector } } }); + */ } } +function sync_status_from_parent() +{ + //console.log("sync_status_from_parent"); + + let data_url = chrome.runtime.getURL("data/status.json"); + fetch(data_url) + .then(response => { + if (response.ok) { + return response.json() + } else if(response.status === 404) { + return Promise.reject('error 404') + } else { + return Promise.reject('some other error: ' + response.status) + } + }) + .then((data) => + { + console.log(data); + if(data) { + let nextState = 'ON'; + if(!data.status) { + nextState = 'OFF'; + } + + //console.log(nextState); + chrome.action.setBadgeText({ + text: nextState + }); + + chrome.storage.local.set( + { + status: nextState + } + ); + } + }) + .catch(error => { + //console.log('error is', error) + }); + } + function ack() { //console.log("act"); }