-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbrowser_integration_stop.py
More file actions
64 lines (51 loc) · 2.06 KB
/
Copy pathbrowser_integration_stop.py
File metadata and controls
64 lines (51 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from .browser_integration import *
stop_macro_js = """
storage = []
localStorage.removeItem('__bi_tracking_events');
localStorage.removeItem('__bi_counter');
localStorage.removeItem('__bi_event_time');
for (var p in localStorage) {
if (p.substr(0, 10) === '__bi_event') {
storage.push(JSON.parse(localStorage[p]));
localStorage.removeItem(p);
}
}
return storage;
"""
class BrowserIntegrationStopCommand(sublime_plugin.WindowCommand):
plugin_name = "Stop recording"
plugin_description = "Stop recording browser interaction," \
" and collect macro data."
@staticmethod
def visible():
return browser.connected() and browser.recording
@require_browser
@async
def run(self):
@async
def cancel_macro():
if sublime.ok_cancel_dialog("If you cancel the macro saving, "
"all its data will be lost. "
"There is no way to recover "
"this data later. "
"Are you sure you want to "
"forget this macro?",
"Yes, I wan't to forget the macro!"):
return
stop_macro()
@async
def stop_macro(name='untitled'):
view = self.window.new_file()
# view.set_syntax_file('Packages/JSON/JSON.tmLanguage')
view.set_name(name + '.macro')
view.run_command('insert_into_view', {'text': macro})
browser.recording = False
storage = browser.execute(stop_macro_js)
if storage:
with loading('Collecting events.'):
storage.sort(key=lambda x: x['idx'])
macro = sublime.encode_value(storage, pretty=True)
self.window.show_input_panel('Macro name:', '', stop_macro,
None, None)
else:
warning('No events recorded.')