-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpageBridge.js
More file actions
37 lines (33 loc) · 1.3 KB
/
Copy pathpageBridge.js
File metadata and controls
37 lines (33 loc) · 1.3 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
(function() {
try {
let code = null;
let languageId = null;
if (window.monaco && window.monaco.editor) {
const editors = typeof window.monaco.editor.getEditors === 'function'
? window.monaco.editor.getEditors()
: [];
if (editors.length > 0) {
const editor = editors[0];
code = editor.getValue();
const model = editor.getModel && editor.getModel();
if (model && typeof model.getLanguageId === 'function') {
languageId = model.getLanguageId();
}
}
if (code === null && typeof window.monaco.editor.getModels === 'function') {
const models = window.monaco.editor.getModels();
if (models.length > 0) {
code = models[0].getValue();
languageId = models[0].getLanguageId();
}
}
}
document.dispatchEvent(new CustomEvent('LeetCodeCodeSaver_CodeExtracted', {
detail: { code: code, languageId: languageId }
}));
} catch (e) {
document.dispatchEvent(new CustomEvent('LeetCodeCodeSaver_CodeExtracted', {
detail: { code: null, languageId: null }
}));
}
})();