chuijs 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +113 -0
- package/README.md +43 -632
- package/framework/appLayout/default/chui_app_layout.js +314 -273
- package/framework/appLayout/default/global_style.css +93 -53
- package/framework/components/chui_accordion/accordion.js +29 -26
- package/framework/components/chui_accordion/styles.css +6 -5
- package/framework/components/chui_action_sheet/action_sheet.js +59 -33
- package/framework/components/chui_action_sheet/styles.css +2 -1
- package/framework/components/chui_affix/affix.js +11 -6
- package/framework/components/chui_alert/alert.js +23 -14
- package/framework/components/chui_avatar/avatar.js +23 -22
- package/framework/components/chui_avatar_group/avatar_group.js +21 -19
- package/framework/components/chui_backtop/backtop.js +35 -19
- package/framework/components/chui_badge/badge.js +15 -13
- package/framework/components/chui_breadcrumb/breadcrumb.js +15 -13
- package/framework/components/chui_button/button.js +42 -22
- package/framework/components/chui_button/styles.css +2 -2
- package/framework/components/chui_calendar/calendar.js +12 -10
- package/framework/components/chui_card/card.js +43 -23
- package/framework/components/chui_chat/chat.js +72 -33
- package/framework/components/chui_clipboard_history/clipboard_history.js +30 -21
- package/framework/components/chui_clipboard_history/styles.css +4 -2
- package/framework/components/chui_code/code.js +2 -2
- package/framework/components/chui_code/styles.css +2 -2
- package/framework/components/chui_code_editor/code_editor.js +47 -31
- package/framework/components/chui_code_editor/styles.css +3 -2
- package/framework/components/chui_command_palette/command_palette.js +60 -37
- package/framework/components/chui_console/console.js +5 -5
- package/framework/components/chui_console/styles.css +1 -1
- package/framework/components/chui_content_block/content_block.js +33 -19
- package/framework/components/chui_content_block/styles.css +2 -2
- package/framework/components/chui_context_menu/context_menu.js +9 -4
- package/framework/components/chui_custom_element/custom_element.js +22 -15
- package/framework/components/chui_data_grid/data_grid.js +396 -234
- package/framework/components/chui_data_grid/styles.css +10 -8
- package/framework/components/chui_descriptions/descriptions.js +34 -17
- package/framework/components/chui_details/details.js +32 -26
- package/framework/components/chui_details/styles.css +5 -4
- package/framework/components/chui_diff_viewer/diff_viewer.js +91 -66
- package/framework/components/chui_diff_viewer/styles.css +1 -1
- package/framework/components/chui_divider/divider.js +13 -11
- package/framework/components/chui_drawer/drawer.js +27 -25
- package/framework/components/chui_drop_zone/drop_zone.js +31 -21
- package/framework/components/chui_empty_state/empty_state.js +20 -15
- package/framework/components/chui_fieldset/fieldset.js +37 -20
- package/framework/components/chui_fieldset/styles.css +1 -1
- package/framework/components/chui_file_explorer/file_explorer.js +157 -86
- package/framework/components/chui_file_explorer/styles.css +2 -1
- package/framework/components/chui_form/form.js +31 -19
- package/framework/components/chui_form/styles.css +1 -1
- package/framework/components/chui_gantt/gantt.js +64 -40
- package/framework/components/chui_graphs/graphs.js +301 -200
- package/framework/components/chui_graphs/styles.css +1 -1
- package/framework/components/chui_hero/hero.js +40 -22
- package/framework/components/chui_html_block/html_block.js +6 -6
- package/framework/components/chui_html_block/styles.css +2 -2
- package/framework/components/chui_hx/hx.js +3 -3
- package/framework/components/chui_hx/styles.css +11 -4
- package/framework/components/chui_icons/icons.js +2109 -2109
- package/framework/components/chui_icons/styles.css +2 -2
- package/framework/components/chui_inputs/chui_check_box/check_box.js +31 -19
- package/framework/components/chui_inputs/chui_check_box/styles.css +18 -18
- package/framework/components/chui_inputs/chui_chips/chips.js +50 -40
- package/framework/components/chui_inputs/chui_chips/styles.css +4 -2
- package/framework/components/chui_inputs/chui_color_picker/color_picker.js +36 -24
- package/framework/components/chui_inputs/chui_combo_box/combo_box.js +100 -82
- package/framework/components/chui_inputs/chui_combo_box/styles.css +14 -12
- package/framework/components/chui_inputs/chui_date/date.js +102 -66
- package/framework/components/chui_inputs/chui_date/styles.css +12 -11
- package/framework/components/chui_inputs/chui_date_range/date_range.js +40 -29
- package/framework/components/chui_inputs/chui_datetime/datetime.js +35 -27
- package/framework/components/chui_inputs/chui_email/email.js +43 -31
- package/framework/components/chui_inputs/chui_email/styles.css +5 -5
- package/framework/components/chui_inputs/chui_file/file.js +68 -41
- package/framework/components/chui_inputs/chui_file/styles.css +13 -12
- package/framework/components/chui_inputs/chui_hotkey/hotkey.js +61 -36
- package/framework/components/chui_inputs/chui_masked/masked.js +39 -28
- package/framework/components/chui_inputs/chui_mention/mention.js +77 -30
- package/framework/components/chui_inputs/chui_multi_combo_box/multi_combo_box.js +173 -153
- package/framework/components/chui_inputs/chui_multi_combo_box/styles.css +9 -7
- package/framework/components/chui_inputs/chui_number/number.js +58 -41
- package/framework/components/chui_inputs/chui_number/styles.css +7 -7
- package/framework/components/chui_inputs/chui_otp/otp.js +38 -29
- package/framework/components/chui_inputs/chui_password/password.js +58 -36
- package/framework/components/chui_inputs/chui_password/styles.css +8 -8
- package/framework/components/chui_inputs/chui_radio_button/radio_button.js +37 -25
- package/framework/components/chui_inputs/chui_radio_button/styles.css +20 -20
- package/framework/components/chui_inputs/chui_rating/rating.js +26 -22
- package/framework/components/chui_inputs/chui_select_box/select_box.js +102 -78
- package/framework/components/chui_inputs/chui_select_box/styles.css +11 -11
- package/framework/components/chui_inputs/chui_slider/slider.js +29 -26
- package/framework/components/chui_inputs/chui_slider/styles.css +2 -1
- package/framework/components/chui_inputs/chui_text/styles.css +8 -8
- package/framework/components/chui_inputs/chui_text/text.js +65 -44
- package/framework/components/chui_inputs/chui_text_area/styles.css +6 -6
- package/framework/components/chui_inputs/chui_text_area/text_area.js +51 -28
- package/framework/components/chui_inputs/chui_time/styles.css +5 -3
- package/framework/components/chui_inputs/chui_time/time.js +38 -27
- package/framework/components/chui_inputs/chui_toggle/styles.css +3 -3
- package/framework/components/chui_inputs/chui_toggle/toggle.js +16 -16
- package/framework/components/chui_json_editor/json_editor.js +53 -43
- package/framework/components/chui_json_viewer/json_viewer.js +52 -33
- package/framework/components/chui_json_viewer/styles.css +3 -2
- package/framework/components/chui_kanban/kanban.js +52 -34
- package/framework/components/chui_kbd/kbd.js +12 -10
- package/framework/components/chui_label/label.js +14 -12
- package/framework/components/chui_label/styles.css +2 -2
- package/framework/components/chui_link/link.js +27 -20
- package/framework/components/chui_list/list.js +31 -27
- package/framework/components/chui_list/styles.css +2 -1
- package/framework/components/chui_markdown_editor/markdown_editor.js +60 -44
- package/framework/components/chui_media/audio.js +326 -227
- package/framework/components/chui_media/audio_styles.css +40 -21
- package/framework/components/chui_media/image.js +70 -38
- package/framework/components/chui_media/image_compare.js +52 -21
- package/framework/components/chui_media/image_styles.css +3 -3
- package/framework/components/chui_media/video.js +155 -62
- package/framework/components/chui_media/video_styles.css +33 -16
- package/framework/components/chui_menu_bar/menu_bar.js +26 -24
- package/framework/components/chui_menu_bar/styles.css +4 -2
- package/framework/components/chui_modal/modal.js +44 -43
- package/framework/components/chui_modal/styles.css +3 -2
- package/framework/components/chui_notification/notification.js +50 -34
- package/framework/components/chui_notification/notification_download.js +31 -25
- package/framework/components/chui_notification/notification_download_progress.css +3 -2
- package/framework/components/chui_notification/notification_download_progress.js +47 -41
- package/framework/components/chui_notification/notification_update.js +23 -16
- package/framework/components/chui_notification/status_plate.js +2 -2
- package/framework/components/chui_notification/styles_download.css +1 -1
- package/framework/components/chui_notification/styles_update.css +1 -1
- package/framework/components/chui_org_chart/org_chart.js +74 -35
- package/framework/components/chui_pagination/pagination.js +62 -27
- package/framework/components/chui_paragraph/paragraph.js +2 -2
- package/framework/components/chui_paragraph/styles.css +1 -1
- package/framework/components/chui_popover/popover.js +49 -28
- package/framework/components/chui_popups/popups.js +137 -108
- package/framework/components/chui_popups/styles.css +2 -2
- package/framework/components/chui_print_button/print_button.js +33 -23
- package/framework/components/chui_progress_bar/progress_bar.js +23 -15
- package/framework/components/chui_progress_bar/styles.css +2 -2
- package/framework/components/chui_progress_ring/progress_ring.js +17 -15
- package/framework/components/chui_qrcode/qrcode.js +75 -31
- package/framework/components/chui_query_builder/query_builder.js +216 -123
- package/framework/components/chui_radio_group/radio_group.js +36 -26
- package/framework/components/chui_radio_group/styles.css +1 -1
- package/framework/components/chui_result/result.js +26 -16
- package/framework/components/chui_scheduler/scheduler.js +57 -35
- package/framework/components/chui_scheduler/styles.css +6 -2
- package/framework/components/chui_segmented_control/segmented_control.js +27 -21
- package/framework/components/chui_settings/settings.js +122 -48
- package/framework/components/chui_shortcut_help/shortcut_help.js +55 -32
- package/framework/components/chui_sidebar_nav/sidebar_nav.js +33 -23
- package/framework/components/chui_skeleton/skeleton.js +29 -24
- package/framework/components/chui_slideshow/slideshow.js +60 -41
- package/framework/components/chui_slideshow/styles.css +18 -12
- package/framework/components/chui_spinner/spinner.js +8 -8
- package/framework/components/chui_spinner/styles.css +0 -1
- package/framework/components/chui_split_button/split_button.js +23 -18
- package/framework/components/chui_split_button/styles.css +1 -1
- package/framework/components/chui_splitter/splitter.js +35 -28
- package/framework/components/chui_statistic/statistic.js +65 -38
- package/framework/components/chui_status_bar/status_bar.js +11 -9
- package/framework/components/chui_stepper/stepper.js +27 -22
- package/framework/components/chui_sticky_bar/sticky_bar.js +9 -4
- package/framework/components/chui_sticky_bar/styles.css +3 -1
- package/framework/components/chui_tabs/chui_tabs.js +28 -22
- package/framework/components/chui_tabs/styles.css +3 -3
- package/framework/components/chui_text_editor/styles.css +20 -19
- package/framework/components/chui_text_editor/text_editor.js +85 -61
- package/framework/components/chui_text_editor/text_editor_panel.js +346 -284
- package/framework/components/chui_theme_toggle/theme_toggle.js +27 -22
- package/framework/components/chui_timeline/timeline.js +14 -12
- package/framework/components/chui_toast_queue/toast_queue.js +52 -46
- package/framework/components/chui_toolbar/toolbar.js +20 -13
- package/framework/components/chui_tooltip/tooltip.js +37 -24
- package/framework/components/chui_tour/styles.css +8 -3
- package/framework/components/chui_tour/tour.js +61 -27
- package/framework/components/chui_transfer/styles.css +2 -1
- package/framework/components/chui_transfer/transfer.js +75 -42
- package/framework/components/chui_tree_table/tree_table.js +43 -29
- package/framework/components/chui_tree_view/styles.css +4 -2
- package/framework/components/chui_tree_view/tree_view.js +142 -99
- package/framework/components/chui_watermark/watermark.js +24 -16
- package/framework/components/chui_webview/styles.css +2 -2
- package/framework/components/chui_webview/webview.js +62 -50
- package/framework/components/telegram_bot/chui_telegram_bot.js +71 -64
- package/framework/modules/chui_a11y/chui_a11y.js +77 -46
- package/framework/modules/chui_animations/animations.js +42 -42
- package/framework/modules/chui_animations/styles.css +1 -1
- package/framework/modules/chui_bridge/preload.js +56 -26
- package/framework/modules/chui_functions.js +52 -50
- package/framework/modules/chui_highlight/chui_highlight.js +25 -22
- package/framework/modules/chui_i18n/chui_i18n.js +9 -7
- package/framework/modules/chui_i18n/locales/a11y.js +5 -5
- package/framework/modules/chui_i18n/locales/app_layout.js +5 -5
- package/framework/modules/chui_i18n/locales/calendar.js +3 -3
- package/framework/modules/chui_i18n/locales/common.js +3 -3
- package/framework/modules/chui_i18n/locales/data.js +36 -26
- package/framework/modules/chui_i18n/locales/editors.js +40 -13
- package/framework/modules/chui_i18n/locales/feedback.js +3 -3
- package/framework/modules/chui_i18n/locales/forms.js +8 -8
- package/framework/modules/chui_i18n/locales/graphics.js +8 -8
- package/framework/modules/chui_i18n/locales/media.js +4 -4
- package/framework/modules/chui_i18n/locales/navigation.js +8 -8
- package/framework/modules/chui_i18n/locales/validate.js +3 -3
- package/framework/modules/chui_json/chui_json.js +9 -9
- package/framework/modules/chui_layout/chui_layout.js +12 -10
- package/framework/modules/chui_logger/chui_logger.js +29 -25
- package/framework/modules/chui_page/page.js +33 -27
- package/framework/modules/chui_page/styles.css +3 -26
- package/framework/modules/chui_qr/chui_qr.js +158 -67
- package/framework/modules/chui_scrollbar/chui_scrollbar.js +35 -24
- package/framework/modules/chui_scrollbar/styles.css +3 -1
- package/framework/modules/chui_services/chui_channels.js +76 -11
- package/framework/modules/chui_services/chui_services.js +39 -31
- package/framework/modules/chui_services/desktop.js +149 -30
- package/framework/modules/chui_sortable/chui_sortable.js +17 -12
- package/framework/modules/chui_validate/chui_validate.js +7 -4
- package/framework/tray_bar/chui_menu_items.js +136 -46
- package/index.d.ts +4814 -0
- package/index.js +449 -334
- package/package.json +79 -68
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const { Animation } = require(
|
|
2
|
-
const { Spinner } = require(
|
|
3
|
-
const {Log} = require("../../../framework/modules/chui_logger/chui_logger");
|
|
1
|
+
const { Animation } = require("../../modules/chui_animations/animations");
|
|
2
|
+
const { Spinner } = require("../chui_spinner/spinner");
|
|
3
|
+
const { Log } = require("../../../framework/modules/chui_logger/chui_logger");
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Встроенный браузер на `<webview>`.
|
|
@@ -25,7 +25,7 @@ class WebView {
|
|
|
25
25
|
userAgent: undefined,
|
|
26
26
|
webPreferences: "allowRunningInsecureContent, javascript=yes",
|
|
27
27
|
partition: undefined,
|
|
28
|
-
preload: undefined
|
|
28
|
+
preload: undefined,
|
|
29
29
|
};
|
|
30
30
|
/** Безопасный набор для недоверенного контента: без Node, с webSecurity и без попапов */
|
|
31
31
|
static SECURE = {
|
|
@@ -33,43 +33,52 @@ class WebView {
|
|
|
33
33
|
webSecurity: true,
|
|
34
34
|
allowPopups: false,
|
|
35
35
|
plugins: false,
|
|
36
|
-
webPreferences: "javascript=yes"
|
|
36
|
+
webPreferences: "javascript=yes",
|
|
37
37
|
};
|
|
38
|
-
#id = require("randomstring").generate()
|
|
39
|
-
#main_block = document.createElement(
|
|
40
|
-
#WebView = document.createElement(
|
|
41
|
-
#chui_load = document.createElement(
|
|
38
|
+
#id = require("randomstring").generate();
|
|
39
|
+
#main_block = document.createElement("chui_webview");
|
|
40
|
+
#WebView = document.createElement("webview");
|
|
41
|
+
#chui_load = document.createElement("chui_load");
|
|
42
42
|
constructor(url = String(), dev = false, options = {}) {
|
|
43
|
-
require(
|
|
44
|
-
const settings = {...WebView.DEFAULTS};
|
|
43
|
+
require("../../modules/chui_functions").setStyles(__dirname + "/styles.css", "chUiJS_WebView");
|
|
44
|
+
const settings = { ...WebView.DEFAULTS };
|
|
45
45
|
// undefined в объекте опций означает «как по умолчанию», а не «перезаписать пустым»
|
|
46
46
|
for (const [key, value] of Object.entries(options)) {
|
|
47
47
|
if (value !== undefined) settings[key] = value;
|
|
48
48
|
}
|
|
49
|
-
this.#WebView.setAttribute(
|
|
50
|
-
this.#WebView.setAttribute(
|
|
51
|
-
if (settings.nodeIntegration === true) this.#WebView.setAttribute(
|
|
52
|
-
if (settings.plugins === true) this.#WebView.setAttribute(
|
|
53
|
-
this.#WebView.setAttribute(
|
|
49
|
+
this.#WebView.setAttribute("id", this.#id);
|
|
50
|
+
this.#WebView.setAttribute("src", url);
|
|
51
|
+
if (settings.nodeIntegration === true) this.#WebView.setAttribute("nodeintegration", "true");
|
|
52
|
+
if (settings.plugins === true) this.#WebView.setAttribute("plugins", "true");
|
|
53
|
+
this.#WebView.setAttribute(
|
|
54
|
+
"useragent",
|
|
55
|
+
settings.userAgent === undefined ? getFirefoxUserAgent() : String(settings.userAgent)
|
|
56
|
+
);
|
|
54
57
|
// Атрибут отрицательный: ставим его только когда webSecurity выключен явно
|
|
55
|
-
if (settings.webSecurity === false) this.#WebView.setAttribute(
|
|
56
|
-
if (settings.allowPopups === true) this.#WebView.setAttribute(
|
|
57
|
-
if (settings.webPreferences !== undefined)
|
|
58
|
+
if (settings.webSecurity === false) this.#WebView.setAttribute("disablewebsecurity", "true");
|
|
59
|
+
if (settings.allowPopups === true) this.#WebView.setAttribute("allowpopups", "true");
|
|
60
|
+
if (settings.webPreferences !== undefined)
|
|
61
|
+
this.#WebView.setAttribute(
|
|
62
|
+
"webpreferences",
|
|
63
|
+
settings.nodeIntegration === true
|
|
64
|
+
? withNodeIntegration(String(settings.webPreferences))
|
|
65
|
+
: String(settings.webPreferences)
|
|
66
|
+
);
|
|
58
67
|
if (settings.partition !== undefined) this.#WebView.setAttribute("partition", String(settings.partition));
|
|
59
68
|
if (settings.preload !== undefined) this.#WebView.setAttribute("preload", String(settings.preload));
|
|
60
69
|
let spinner = new Spinner(Spinner.SIZE.BIG);
|
|
61
70
|
this.#chui_load.appendChild(spinner.set());
|
|
62
|
-
this.#main_block.appendChild(this.#WebView)
|
|
71
|
+
this.#main_block.appendChild(this.#WebView);
|
|
63
72
|
const loadStart = () => {
|
|
64
|
-
this.#main_block.appendChild(this.#chui_load)
|
|
65
|
-
}
|
|
73
|
+
this.#main_block.appendChild(this.#chui_load);
|
|
74
|
+
};
|
|
66
75
|
const loadStop = () => {
|
|
67
76
|
new Animation(this.#WebView).fadeIn();
|
|
68
|
-
this.#main_block.removeChild(this.#chui_load)
|
|
77
|
+
this.#main_block.removeChild(this.#chui_load);
|
|
69
78
|
if (dev) this.#WebView.openDevTools();
|
|
70
|
-
}
|
|
71
|
-
this.#WebView.addEventListener(
|
|
72
|
-
this.#WebView.addEventListener(
|
|
79
|
+
};
|
|
80
|
+
this.#WebView.addEventListener("did-start-loading", loadStart);
|
|
81
|
+
this.#WebView.addEventListener("did-stop-loading", loadStop);
|
|
73
82
|
}
|
|
74
83
|
setPartition(partition = String()) {
|
|
75
84
|
this.#WebView.partition = partition;
|
|
@@ -78,51 +87,51 @@ class WebView {
|
|
|
78
87
|
this.#WebView.preload = "file://" + path;
|
|
79
88
|
}
|
|
80
89
|
addStartLoadEvent(listener = () => {}) {
|
|
81
|
-
this.#WebView.addEventListener(
|
|
90
|
+
this.#WebView.addEventListener("did-start-loading", listener);
|
|
82
91
|
}
|
|
83
92
|
addStopLoadEvent(listener = () => {}) {
|
|
84
|
-
this.#WebView.addEventListener(
|
|
93
|
+
this.#WebView.addEventListener("did-stop-loading", listener);
|
|
85
94
|
}
|
|
86
95
|
addFinishLoadEvent(listener = () => {}) {
|
|
87
|
-
this.#WebView.addEventListener(
|
|
96
|
+
this.#WebView.addEventListener("did-finish-load", listener);
|
|
88
97
|
}
|
|
89
98
|
async executeJavaScript(code = String()) {
|
|
90
99
|
try {
|
|
91
100
|
await this.#WebView.executeJavaScript(code);
|
|
92
101
|
} catch (err) {
|
|
93
|
-
Log.error(err)
|
|
102
|
+
Log.error(err);
|
|
94
103
|
}
|
|
95
104
|
}
|
|
96
105
|
insertCustomRes(options = { cssPath: String(), jsPath: String() }) {
|
|
97
|
-
this.#WebView.addEventListener(
|
|
98
|
-
const fs = require(
|
|
106
|
+
this.#WebView.addEventListener("did-frame-finish-load", async () => {
|
|
107
|
+
const fs = require("fs");
|
|
99
108
|
if (options.cssPath !== undefined) {
|
|
100
|
-
let data = fs.readFileSync(options.cssPath,
|
|
101
|
-
this.#WebView.insertCSS(String(data)).catch(r => Log.error(r));
|
|
109
|
+
let data = fs.readFileSync(options.cssPath, "utf8");
|
|
110
|
+
this.#WebView.insertCSS(String(data)).catch((r) => Log.error(r));
|
|
102
111
|
}
|
|
103
112
|
if (options.jsPath !== undefined) {
|
|
104
113
|
try {
|
|
105
|
-
const data = fs.readFileSync(options.jsPath,
|
|
114
|
+
const data = fs.readFileSync(options.jsPath, "utf8");
|
|
106
115
|
await this.#WebView.executeJavaScript(data);
|
|
107
116
|
} catch (err) {
|
|
108
117
|
Log.error(err);
|
|
109
118
|
}
|
|
110
119
|
}
|
|
111
|
-
})
|
|
120
|
+
});
|
|
112
121
|
}
|
|
113
122
|
async send(channel = String(), ...args) {
|
|
114
123
|
// Аргументы передаются как есть: `webview.send(channel, ...args)`. Раньше они
|
|
115
124
|
// уезжали одним массивом, и слушатель в гостевой странице видел один аргумент
|
|
116
|
-
await this.#WebView.send(channel, ...args)
|
|
125
|
+
await this.#WebView.send(channel, ...args);
|
|
117
126
|
}
|
|
118
127
|
setUrl(url = String()) {
|
|
119
|
-
this.#WebView.setAttribute(
|
|
128
|
+
this.#WebView.setAttribute("src", url);
|
|
120
129
|
}
|
|
121
130
|
getWebContentsId() {
|
|
122
|
-
return this.#WebView.getWebContentsId()
|
|
131
|
+
return this.#WebView.getWebContentsId();
|
|
123
132
|
}
|
|
124
133
|
set() {
|
|
125
|
-
return this.#main_block
|
|
134
|
+
return this.#main_block;
|
|
126
135
|
}
|
|
127
136
|
}
|
|
128
137
|
|
|
@@ -141,19 +150,22 @@ const withNodeIntegration = (preferences = String()) => {
|
|
|
141
150
|
|
|
142
151
|
const getFirefoxUserAgent = () => {
|
|
143
152
|
const rootUAs = {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:FXVERSION.0) Gecko/20100101 Firefox/FXVERSION.0",
|
|
154
|
+
windows: "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:FXVERSION.0) Gecko/20100101 Firefox/FXVERSION.0",
|
|
155
|
+
linux: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:FXVERSION.0) Gecko/20100101 Firefox/FXVERSION.0",
|
|
147
156
|
};
|
|
148
157
|
let rootUA;
|
|
149
|
-
if (process.platform ===
|
|
150
|
-
|
|
151
|
-
} else if (process.platform ===
|
|
152
|
-
|
|
158
|
+
if (process.platform === "win32") {
|
|
159
|
+
rootUA = rootUAs.windows;
|
|
160
|
+
} else if (process.platform === "darwin") {
|
|
161
|
+
rootUA = rootUAs.mac;
|
|
153
162
|
} else {
|
|
154
|
-
|
|
163
|
+
rootUA = rootUAs.linux;
|
|
155
164
|
}
|
|
156
|
-
return rootUA.replace(
|
|
165
|
+
return rootUA.replace(
|
|
166
|
+
/FXVERSION/g,
|
|
167
|
+
91 + Math.floor((Date.now() - 1628553600000) / (4.1 * 7 * 24 * 60 * 60 * 1000))
|
|
168
|
+
);
|
|
157
169
|
};
|
|
158
170
|
|
|
159
|
-
exports.WebView = WebView
|
|
171
|
+
exports.WebView = WebView;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
class TelegramBot {
|
|
2
2
|
#main_api = undefined;
|
|
3
3
|
constructor(token = String()) {
|
|
4
|
-
this.#main_api = `https://api.telegram.org/bot${token}
|
|
4
|
+
this.#main_api = `https://api.telegram.org/bot${token}`;
|
|
5
5
|
}
|
|
6
6
|
setToken(token = String()) {
|
|
7
|
-
this.#main_api = `https://api.telegram.org/bot${token}
|
|
7
|
+
this.#main_api = `https://api.telegram.org/bot${token}`;
|
|
8
8
|
}
|
|
9
9
|
// GET
|
|
10
10
|
async getMe() {
|
|
@@ -15,142 +15,142 @@ class TelegramBot {
|
|
|
15
15
|
}
|
|
16
16
|
async getChat(chat_id = String()) {
|
|
17
17
|
return await this.#sendRequestParams("GET", `getChat`, {
|
|
18
|
-
|
|
18
|
+
chat_id: chat_id,
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
async getChatAdministrators(chat_id = String()) {
|
|
22
22
|
return await this.#sendRequestParams("GET", `getChatAdministrators`, {
|
|
23
|
-
|
|
23
|
+
chat_id: chat_id,
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
async getChatMemberCount(chat_id = String()) {
|
|
27
27
|
return await this.#sendRequestParams("GET", `getChatMemberCount`, {
|
|
28
|
-
|
|
28
|
+
chat_id: chat_id,
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
async getChatMember(chat_id = String(), user_id = Number()) {
|
|
32
32
|
return await this.#sendRequestParams("GET", `getChatMember`, {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
chat_id: chat_id,
|
|
34
|
+
user_id: user_id,
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
async getUserProfilePhotos(user_id = Number()) {
|
|
38
38
|
return await this.#sendRequestParams("GET", `getUserProfilePhotos`, {
|
|
39
|
-
|
|
39
|
+
user_id: user_id,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
async getFile(file_id = String()) {
|
|
43
43
|
return await this.#sendRequestParams("GET", `getFile`, {
|
|
44
|
-
|
|
44
|
+
file_id: file_id,
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
// SET
|
|
48
48
|
async setChatTitle(chat_id = String(), title = String()) {
|
|
49
49
|
return await this.#sendRequestFormData("POST", "setChatTitle", {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})
|
|
50
|
+
chat_id: chat_id,
|
|
51
|
+
title: title,
|
|
52
|
+
});
|
|
53
53
|
}
|
|
54
54
|
async setChatDescription(chat_id = String(), description = String()) {
|
|
55
55
|
return await this.#sendRequestFormData("POST", "setChatDescription", {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
})
|
|
56
|
+
chat_id: chat_id,
|
|
57
|
+
description: description,
|
|
58
|
+
});
|
|
59
59
|
}
|
|
60
60
|
async setChatPhoto(chat_id = String(), path = String()) {
|
|
61
61
|
return await this.#sendRequestFormData("POST", "setChatPhoto", {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
})
|
|
62
|
+
chat_id: chat_id,
|
|
63
|
+
photo: path,
|
|
64
|
+
});
|
|
65
65
|
}
|
|
66
66
|
async deleteChatPhoto(chat_id = String()) {
|
|
67
67
|
return await this.#sendRequestFormData("POST", "deleteChatPhoto", {
|
|
68
|
-
|
|
69
|
-
})
|
|
68
|
+
chat_id: chat_id,
|
|
69
|
+
});
|
|
70
70
|
}
|
|
71
71
|
// FUNC
|
|
72
72
|
async forwardMessage(chat_id = String(), from_chat_id = String(), message_id = Number()) {
|
|
73
73
|
return await this.#sendRequestFormData("POST", "forwardMessage", {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
chat_id: chat_id,
|
|
75
|
+
from_chat_id: from_chat_id,
|
|
76
|
+
message_id: message_id,
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
async copyMessage(chat_id = String(), from_chat_id = String(), message_id = Number()) {
|
|
80
80
|
return await this.#sendRequestFormData("POST", "copyMessage", {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
chat_id: chat_id,
|
|
82
|
+
from_chat_id: from_chat_id,
|
|
83
|
+
message_id: message_id,
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
async pinChatMessage(chat_id = String(), message_id = Number()) {
|
|
87
87
|
return await this.#sendRequestFormData("POST", "pinChatMessage", {
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
chat_id: chat_id,
|
|
89
|
+
message_id: message_id,
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
async unpinChatMessage(chat_id = String(), message_id = Number()) {
|
|
93
93
|
return await this.#sendRequestFormData("POST", "unpinChatMessage", {
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
chat_id: chat_id,
|
|
95
|
+
message_id: message_id,
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
async unpinAllChatMessages(chat_id = String()) {
|
|
99
99
|
return await this.#sendRequestFormData("POST", "unpinAllChatMessages", {
|
|
100
|
-
|
|
100
|
+
chat_id: chat_id,
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
// SEND FUNC
|
|
104
104
|
async sendMessage(chat_id = String(), message = String()) {
|
|
105
105
|
return await this.#sendRequestFormData("POST", "sendMessage", {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
chat_id: chat_id,
|
|
107
|
+
text: message,
|
|
108
|
+
parse_mode: "markdown",
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
async sendDocument(chat_id = String(), path = String()) {
|
|
112
112
|
return await this.#sendRequestFormData("POST", "sendDocument", {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
})
|
|
113
|
+
chat_id: chat_id,
|
|
114
|
+
document: path,
|
|
115
|
+
});
|
|
116
116
|
}
|
|
117
117
|
async sendPhoto(chat_id = String(), path = String()) {
|
|
118
118
|
return await this.#sendRequestFormData("POST", "sendPhoto", {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
})
|
|
119
|
+
chat_id: chat_id,
|
|
120
|
+
photo: path,
|
|
121
|
+
});
|
|
122
122
|
}
|
|
123
123
|
async sendAudio(chat_id = String(), path = String()) {
|
|
124
124
|
return await this.#sendRequestFormData("POST", "sendAudio", {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
})
|
|
125
|
+
chat_id: chat_id,
|
|
126
|
+
audio: path,
|
|
127
|
+
});
|
|
128
128
|
}
|
|
129
129
|
async sendVideo(chat_id = String(), path = String()) {
|
|
130
130
|
return await this.#sendRequestFormData("POST", "sendVideo", {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
})
|
|
131
|
+
chat_id: chat_id,
|
|
132
|
+
video: path,
|
|
133
|
+
});
|
|
134
134
|
}
|
|
135
135
|
async sendContact(chat_id = String(), phone_number = String(), first_name = String()) {
|
|
136
136
|
return await this.#sendRequestFormData("POST", "sendContact", {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
})
|
|
137
|
+
chat_id: chat_id,
|
|
138
|
+
phone_number: phone_number,
|
|
139
|
+
first_name: first_name,
|
|
140
|
+
});
|
|
141
141
|
}
|
|
142
142
|
async sendPoll(chat_id = String(), question = String(), options = [], is_anonymous = Boolean()) {
|
|
143
143
|
return await this.#sendRequestFormData("POST", "sendPoll", {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
})
|
|
144
|
+
chat_id: chat_id,
|
|
145
|
+
question: question,
|
|
146
|
+
options: JSON.stringify(options),
|
|
147
|
+
is_anonymous: is_anonymous,
|
|
148
|
+
});
|
|
149
149
|
}
|
|
150
150
|
async sendDice(chat_id = String()) {
|
|
151
151
|
return await this.#sendRequestFormData("POST", "sendDice", {
|
|
152
|
-
|
|
153
|
-
})
|
|
152
|
+
chat_id: chat_id,
|
|
153
|
+
});
|
|
154
154
|
}
|
|
155
155
|
// PRIVATE FUNC
|
|
156
156
|
#sendRequestFormData(method, func, data = {}) {
|
|
@@ -159,12 +159,12 @@ class TelegramBot {
|
|
|
159
159
|
request.open(method, `${this.#main_api}/${func}`);
|
|
160
160
|
if (data !== undefined) {
|
|
161
161
|
let formData = new FormData();
|
|
162
|
-
for (let key of Object.keys(data)) formData.append(key, data[key])
|
|
163
|
-
request.send(formData)
|
|
162
|
+
for (let key of Object.keys(data)) formData.append(key, data[key]);
|
|
163
|
+
request.send(formData);
|
|
164
164
|
} else request.send();
|
|
165
165
|
request.addEventListener("load", () => resolve(JSON.parse(request.responseText)));
|
|
166
166
|
request.addEventListener("error", () => reject(JSON.parse(request.responseText)));
|
|
167
|
-
})
|
|
167
|
+
});
|
|
168
168
|
}
|
|
169
169
|
#sendRequestParams(method, func, params = {}) {
|
|
170
170
|
return new Promise((resolve, reject) => {
|
|
@@ -174,11 +174,18 @@ class TelegramBot {
|
|
|
174
174
|
request.send();
|
|
175
175
|
request.addEventListener("load", () => resolve(JSON.parse(request.responseText)));
|
|
176
176
|
request.addEventListener("error", () => reject(JSON.parse(request.responseText)));
|
|
177
|
-
})
|
|
177
|
+
});
|
|
178
178
|
}
|
|
179
|
-
#formatParams(params){
|
|
180
|
-
return
|
|
179
|
+
#formatParams(params) {
|
|
180
|
+
return (
|
|
181
|
+
"?" +
|
|
182
|
+
Object.keys(params)
|
|
183
|
+
.map((key) => {
|
|
184
|
+
return key + "=" + encodeURIComponent(params[key]);
|
|
185
|
+
})
|
|
186
|
+
.join("&")
|
|
187
|
+
);
|
|
181
188
|
}
|
|
182
189
|
}
|
|
183
190
|
|
|
184
|
-
exports.TelegramBot = TelegramBot
|
|
191
|
+
exports.TelegramBot = TelegramBot;
|