automatic add host_permissions to extension

master
CHUN YU YAO 2024-01-14 22:50:13 +08:00
parent 4b3f743f33
commit a24c30fb86
4 changed files with 386 additions and 243 deletions

View File

@ -557,6 +557,51 @@ def clean_uc_exe_cache():
return is_cache_exist return is_cache_exist
def dump_settins_to_maxbot_plus_extension(ext, config_dict):
target_path = ext
target_path = os.path.join(target_path, "data")
target_path = os.path.join(target_path, CONST_MAXBOT_CONFIG_FILE)
#print("save as to:", target_path)
try:
os.unlink(target_path)
except Exception as exc:
pass
with open(target_path, 'w') as outfile:
json.dump(config_dict, outfile)
target_path = ext
target_path = os.path.join(target_path, "manifest.json")
manifest_dict = None
if os.path.isfile(target_path):
with open(target_path) as json_data:
manifest_dict = json.load(json_data)
local_remote_url_array = []
local_remote_url = config_dict["advanced"]["remote_url"]
if len(local_remote_url) > 0:
try:
temp_remote_url_array = json.loads("["+ local_remote_url +"]")
for remote_url in temp_remote_url_array:
remote_url_final = remote_url + "*"
local_remote_url_array.append(remote_url_final)
except Exception as exc:
pass
if len(local_remote_url_array) > 0:
is_manifest_changed = False
for remote_url_final in local_remote_url_array:
if not remote_url_final in manifest_dict["host_permissions"]:
#print("local remote_url not in manifest:", remote_url_final)
manifest_dict["host_permissions"].append(remote_url_final)
is_manifest_changed = True
if is_manifest_changed:
json_str = json.dumps(manifest_dict, indent=4)
with open(target_path, 'w') as outfile:
outfile.write(json_str)
def get_uc_options(uc, config_dict, webdriver_path): def get_uc_options(uc, config_dict, webdriver_path):
options = uc.ChromeOptions() options = uc.ChromeOptions()
options.page_load_strategy = 'eager' options.page_load_strategy = 'eager'
@ -581,16 +626,7 @@ def get_uc_options(uc, config_dict, webdriver_path):
if os.path.exists(ext): if os.path.exists(ext):
# sync config. # sync config.
if CONST_MAXBOT_EXTENSION_NAME in ext: if CONST_MAXBOT_EXTENSION_NAME in ext:
target_path = ext dump_settins_to_maxbot_plus_extension(ext, config_dict)
target_path = os.path.join(target_path, "data")
target_path = os.path.join(target_path, CONST_MAXBOT_CONFIG_FILE)
#print("save as to:", target_path)
try:
os.unlink(target_path)
except Exception as exc:
pass
with open(target_path, 'w') as outfile:
json.dump(config_dict, outfile)
load_extension_path += ("," + os.path.abspath(ext)) load_extension_path += ("," + os.path.abspath(ext))
if len(load_extension_path) > 0: if len(load_extension_path) > 0:

View File

@ -2849,7 +2849,6 @@ class VersionHandler(tornado.web.RequestHandler):
def get(self): def get(self):
self.write({"version":self.application.version}) self.write({"version":self.application.version})
class OcrHandler(tornado.web.RequestHandler): class OcrHandler(tornado.web.RequestHandler):
def get(self): def get(self):
self.write({"answer": "1234"}) self.write({"answer": "1234"})

View File

@ -1,237 +1,345 @@
{ {
"author": "Max Yao", "author": "Max Yao",
"name": "MaxBot Plus", "name": "MaxBot Plus",
"description": "Quick way to get expected tickets on some specific websites.", "description": "Quick way to get expected tickets on some specific websites.",
"icons": { "icons": {
"16": "icons/maxbot-16.png", "16": "icons/maxbot-16.png",
"32": "icons/maxbot-32.png", "32": "icons/maxbot-32.png",
"48": "icons/maxbot-48.png", "48": "icons/maxbot-48.png",
"64": "icons/maxbot-64.png", "64": "icons/maxbot-64.png",
"128": "icons/maxbot-128.png" "128": "icons/maxbot-128.png"
},
"manifest_version": 3,
"background": {
"service_worker": "background.js",
"type": "module"
},
"declarative_net_request": {
"rule_resources": [
{
"id": "ruleset_1",
"enabled": true,
"path": "rules_1.json"
}
]
},
"permissions": [
"storage",
"declarativeNetRequest",
"declarativeNetRequestFeedback"
],
"host_permissions": [
"http://127.0.0.1:16888/*"
],
"web_accessible_resources": [
{
"resources": [ "data/*.json" ],
"extension_ids": ["*"],
"matches": [ "*://*/*" ]
}
],
"options_page": "options.html",
"action": {
"default_icon": "icons/maxbot-128.png",
"default_title": "MaxBot"
},
"content_scripts" : [
{
"matches" : [
"https://tixcraft.com/",
"https://www.indievox.com/",
"https://indievox.com/",
"https://ticketmaster.sg/"
],
"run_at": "document_end",
"js" : [ "jquery.min.js", "js/tixcraft_home.js" ]
}, },
{ "manifest_version": 3,
"matches" : [ "background": {
"https://tixcraft.com/activity/detail/*", "service_worker": "background.js",
"https://www.indievox.com/activity/detail/*", "type": "module"
"https://indievox.com/activity/detail/*",
"https://ticketmaster.sg/activity/detail/*"
],
"run_at": "document_start",
"js" : [ "jquery.min.js", "js/tixcraft_detail.js" ]
}, },
{ "declarative_net_request": {
"matches" : [ "rule_resources": [
"https://tixcraft.com/activity/game/*", {
"https://www.indievox.com/activity/game/*", "id": "ruleset_1",
"https://indievox.com/activity/game/*", "enabled": true,
"https://ticketmaster.sg/activity/game/*" "path": "rules_1.json"
], }
"run_at": "document_end", ]
"js" : [ "jquery.min.js", "js/common.js", "js/tixcraft_game.js" ]
}, },
{ "permissions": [
"matches" : [ "storage",
"https://tixcraft.com/ticket/area/*", "declarativeNetRequest",
"https://www.indievox.com/ticket/area/*", "declarativeNetRequestFeedback"
"https://indievox.com/ticket/area/*" ],
], "host_permissions": [
"run_at": "document_end", "http://maxbot.dropboxlike.com:16888/*"
"js" : [ "jquery.min.js", "js/common.js", "js/tixcraft_area.js" ] ],
"web_accessible_resources": [
{
"resources": [
"data/*.json"
],
"extension_ids": [
"*"
],
"matches": [
"*://*/*"
]
}
],
"options_page": "options.html",
"action": {
"default_icon": "icons/maxbot-128.png",
"default_title": "MaxBot"
}, },
{ "content_scripts": [
"matches" : [ {
"https://tixcraft.com/ticket/ticket/*", "matches": [
"https://www.indievox.com/ticket/ticket/*", "https://tixcraft.com/",
"https://indievox.com/ticket/ticket/*", "https://www.indievox.com/",
"https://ticketmaster.sg/ticket/ticket/*" "https://indievox.com/",
], "https://ticketmaster.sg/"
"run_at": "document_end", ],
"js" : [ "jquery.min.js", "js/common.js", "js/tixcraft_ticket.js" ] "run_at": "document_end",
}, "js": [
{ "jquery.min.js",
"matches" : [ "https://ticket.com.tw/application/utk01/utk0101_.aspx" ], "js/tixcraft_home.js"
"run_at": "document_end", ]
"js" : [ "jquery.min.js", "js/ticket_home.js" ] },
}, {
{ "matches": [
"matches" : [ "https://ticket.com.tw/application/UTK02/UTK0201_.aspx?PRODUCT_ID=*" ], "https://tixcraft.com/activity/detail/*",
"run_at": "document_end", "https://www.indievox.com/activity/detail/*",
"world": "MAIN", "https://indievox.com/activity/detail/*",
"js" : [ "jquery.min.js", "js/ticket_event_home.js" ] "https://ticketmaster.sg/activity/detail/*"
}, ],
{ "run_at": "document_start",
"matches" : [ "https://ticket.com.tw/application/UTK02/UTK0201_00.aspx?PRODUCT_ID=*" ], "js": [
"run_at": "document_end", "jquery.min.js",
"world": "MAIN", "js/tixcraft_detail.js"
"js" : [ "jquery.min.js", "js/ticket_date.js" ] ]
}, },
{ {
"matches" : [ "https://ticket.com.tw/application/UTK02/UTK0204_.aspx?*" ], "matches": [
"run_at": "document_end", "https://tixcraft.com/activity/game/*",
"js" : [ "jquery.min.js", "js/common.js", "js/ticket_area.js" ] "https://www.indievox.com/activity/game/*",
}, "https://indievox.com/activity/game/*",
{ "https://ticketmaster.sg/activity/game/*"
"matches" : [ "https://kham.com.tw/application/utk01/UTK0101_03.aspx" ], ],
"run_at": "document_end", "run_at": "document_end",
"js" : [ "jquery.min.js", "js/kham_home.js" ] "js": [
}, "jquery.min.js",
{ "js/common.js",
"matches" : [ "https://kham.com.tw/application/UTK02/UTK0201_.aspx?PRODUCT_ID=*" ], "js/tixcraft_game.js"
"run_at": "document_end", ]
"world": "MAIN", },
"js" : [ "jquery.min.js", "js/kham_event_home.js" ] {
}, "matches": [
{ "https://tixcraft.com/ticket/area/*",
"matches" : [ "https://www.indievox.com/ticket/area/*",
"https://kham.com.tw/application/UTK02/UTK0201_00.aspx?PRODUCT_ID=*" "https://indievox.com/ticket/area/*"
], ],
"run_at": "document_end", "run_at": "document_end",
"world": "MAIN", "js": [
"js" : [ "jquery.min.js", "js/kham_date.js" ] "jquery.min.js",
}, "js/common.js",
{ "js/tixcraft_area.js"
"matches" : [ "https://kham.com.tw/application/UTK02/UTK0204_.aspx?*" ], ]
"run_at": "document_end", },
"js" : [ "jquery.min.js", "js/kham_area.js" ] {
}, "matches": [
{ "https://tixcraft.com/ticket/ticket/*",
"matches" : [ "https://ticket.ibon.com.tw/ActivityInfo/Details/*" ], "https://www.indievox.com/ticket/ticket/*",
"run_at": "document_start", "https://indievox.com/ticket/ticket/*",
"js" : [ "jquery.min.js", "js/ibon_detail.js" ] "https://ticketmaster.sg/ticket/ticket/*"
}, ],
{ "run_at": "document_end",
"matches" : [ "https://orders.ibon.com.tw/application/UTK02/UTK0201_000.aspx?*" ], "js": [
"run_at": "document_end", "jquery.min.js",
"js" : [ "jquery.min.js", "js/ibon_area.js" ] "js/common.js",
}, "js/tixcraft_ticket.js"
{ ]
"matches" : [ },
"https://orders.ibon.com.tw/application/UTK02/UTK0201_001.aspx?PERFORMANCE_ID=*PERFORMANCE_PRICE_AREA_ID=*", {
"https://orders.ibon.com.tw/application/UTK02/UTK0202_.aspx?PERFORMANCE_ID=*PERFORMANCE_PRICE_AREA_ID=*" "matches": [
], "https://ticket.com.tw/application/utk01/utk0101_.aspx"
"run_at": "document_end", ],
"js" : [ "jquery.min.js", "js/ibon_ticket.js" ] "run_at": "document_end",
}, "js": [
{ "jquery.min.js",
"matches" : [ "js/ticket_home.js"
"https://orders.ibon.com.tw/application/UTK02/UTK0201_001.aspx?PERFORMANCE_ID=*PERFORMANCE_PRICE_AREA_ID=*", ]
"https://orders.ibon.com.tw/application/UTK02/UTK0202_.aspx?PERFORMANCE_ID=*PERFORMANCE_PRICE_AREA_ID=*" },
], {
"run_at": "document_end", "matches": [
"world": "MAIN", "https://ticket.com.tw/application/UTK02/UTK0201_.aspx?PRODUCT_ID=*"
"js" : [ "jquery.min.js", "js/ibon_ticket_next.js" ] ],
}, "run_at": "document_end",
{ "world": "MAIN",
"matches" : [ "js": [
"https://msg.cityline.com/*.html*" "jquery.min.js",
], "js/ticket_event_home.js"
"run_at": "document_end", ]
"js" : [ "jquery.min.js", "js/cityline_msg_background.js"] },
}, {
{ "matches": [
"matches" : [ "https://ticket.com.tw/application/UTK02/UTK0201_00.aspx?PRODUCT_ID=*"
"https://msg.cityline.com/*" ],
], "run_at": "document_end",
"run_at": "document_end", "world": "MAIN",
"world": "MAIN", "js": [
"js" : [ "jquery.min.js", "js/cityline_msg_front.js"] "jquery.min.js",
}, "js/ticket_date.js"
{ ]
"matches" : [ },
"https://*.cityline.com/utsvInternet/internet/eventDetail?event=*", {
"https://*.cityline.com/utsvlnternet/*/login?lang=TW" "matches": [
], "https://ticket.com.tw/application/UTK02/UTK0204_.aspx?*"
"run_at": "document_end", ],
"js" : [ "jquery.min.js", "js/cityline_event_common.js"] "run_at": "document_end",
}, "js": [
{ "jquery.min.js",
"matches" : [ "js/common.js",
"https://ticketplus.com.tw/activity/*" "js/ticket_area.js"
], ]
"run_at": "document_end", },
"js" : ["jquery.min.js", "js/ticketplus_activity.js"] {
}, "matches": [
{ "https://kham.com.tw/application/utk01/UTK0101_03.aspx"
"matches" : [ ],
"https://ticketplus.com.tw/order/*" "run_at": "document_end",
], "js": [
"run_at": "document_start", "jquery.min.js",
"js" : [ "jquery.min.js", "js/ticketplus_order.js"] "js/kham_home.js"
}, ]
{ },
"matches" : [ {
"https://kktix.com/" "matches": [
], "https://kham.com.tw/application/UTK02/UTK0201_.aspx?PRODUCT_ID=*"
"run_at": "document_end", ],
"js" : [ "jquery.min.js", "js/kktix_home.js" ] "run_at": "document_end",
}, "world": "MAIN",
{ "js": [
"matches" : [ "jquery.min.js",
"https://*.kktix.cc/events/*" "js/kham_event_home.js"
], ]
"run_at": "document_end", },
"js" : [ "jquery.min.js", "js/kktix_events.js" ] {
}, "matches": [
{ "https://kham.com.tw/application/UTK02/UTK0201_00.aspx?PRODUCT_ID=*"
"matches" : [ ],
"https://kktix.com/events/*/registrations/new" "run_at": "document_end",
], "world": "MAIN",
"world": "MAIN", "js": [
"run_at": "document_end", "jquery.min.js",
"js" : [ "jquery.min.js", "js/common.js", "js/kktix_registrations_assign.js" ] "js/kham_date.js"
}, ]
{ },
"matches" : [ {
"https://kktix.com/events/*/registrations/new" "matches": [
], "https://kham.com.tw/application/UTK02/UTK0204_.aspx?*"
"run_at": "document_start", ],
"js" : [ "jquery.min.js", "js/common.js", "js/kktix_registrations_reload.js" ] "run_at": "document_end",
} "js": [
], "jquery.min.js",
"version": "1.0.4" "js/kham_area.js"
]
},
{
"matches": [
"https://ticket.ibon.com.tw/ActivityInfo/Details/*"
],
"run_at": "document_start",
"js": [
"jquery.min.js",
"js/ibon_detail.js"
]
},
{
"matches": [
"https://orders.ibon.com.tw/application/UTK02/UTK0201_000.aspx?*"
],
"run_at": "document_end",
"js": [
"jquery.min.js",
"js/ibon_area.js"
]
},
{
"matches": [
"https://orders.ibon.com.tw/application/UTK02/UTK0201_001.aspx?PERFORMANCE_ID=*PERFORMANCE_PRICE_AREA_ID=*",
"https://orders.ibon.com.tw/application/UTK02/UTK0202_.aspx?PERFORMANCE_ID=*PERFORMANCE_PRICE_AREA_ID=*"
],
"run_at": "document_end",
"js": [
"jquery.min.js",
"js/ibon_ticket.js"
]
},
{
"matches": [
"https://orders.ibon.com.tw/application/UTK02/UTK0201_001.aspx?PERFORMANCE_ID=*PERFORMANCE_PRICE_AREA_ID=*",
"https://orders.ibon.com.tw/application/UTK02/UTK0202_.aspx?PERFORMANCE_ID=*PERFORMANCE_PRICE_AREA_ID=*"
],
"run_at": "document_end",
"world": "MAIN",
"js": [
"jquery.min.js",
"js/ibon_ticket_next.js"
]
},
{
"matches": [
"https://msg.cityline.com/*.html*"
],
"run_at": "document_end",
"js": [
"jquery.min.js",
"js/cityline_msg_background.js"
]
},
{
"matches": [
"https://msg.cityline.com/*"
],
"run_at": "document_end",
"world": "MAIN",
"js": [
"jquery.min.js",
"js/cityline_msg_front.js"
]
},
{
"matches": [
"https://*.cityline.com/utsvInternet/internet/eventDetail?event=*",
"https://*.cityline.com/utsvlnternet/*/login?lang=TW"
],
"run_at": "document_end",
"js": [
"jquery.min.js",
"js/cityline_event_common.js"
]
},
{
"matches": [
"https://ticketplus.com.tw/activity/*"
],
"run_at": "document_end",
"js": [
"jquery.min.js",
"js/ticketplus_activity.js"
]
},
{
"matches": [
"https://ticketplus.com.tw/order/*"
],
"run_at": "document_start",
"js": [
"jquery.min.js",
"js/ticketplus_order.js"
]
},
{
"matches": [
"https://kktix.com/"
],
"run_at": "document_end",
"js": [
"jquery.min.js",
"js/kktix_home.js"
]
},
{
"matches": [
"https://*.kktix.cc/events/*"
],
"run_at": "document_end",
"js": [
"jquery.min.js",
"js/kktix_events.js"
]
},
{
"matches": [
"https://kktix.com/events/*/registrations/new"
],
"world": "MAIN",
"run_at": "document_end",
"js": [
"jquery.min.js",
"js/common.js",
"js/kktix_registrations_assign.js"
]
},
{
"matches": [
"https://kktix.com/events/*/registrations/new"
],
"run_at": "document_start",
"js": [
"jquery.min.js",
"js/common.js",
"js/kktix_registrations_reload.js"
]
}
],
"version": "1.0.5"
} }

View File

@ -105,7 +105,7 @@
</div> </div>
<div class="col-12"> <div class="col-12">
<label for="remote_url" class="form-label">Remote URL</label> <label for="remote_url" class="form-label">OCR Server URL</label>
<input class="form-control" id="remote_url" value="" /> <input class="form-control" id="remote_url" value="" />
</div> </div>
</div> </div>