. | function show_sketch_menu(tab) { |
| async function show_sketch_menu(tab) { |
| |
| try { |
| // https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/background.js |
| // https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/background.js |
. | let loaded_first = false; |
| const result = await browser.tabs.executeScript(tab.id, { |
| browser.tabs.executeScript(tab.id, { |
| |
| code: "typeof SketchSwitch === 'function'", |
| code: "typeof SketchSwitch === 'function'", |
. | }).then(result => { |
| }); |
| if (!result || result[0] !== true) { // SketchSwitch is not defined |
| if (!result || result[0] !== true) { // SketchSwitch is not defined |
. | loaded_first = true; |
| |
| // for malformed URI --- SketchSwitch.Utils.convertStringEncoding() |
| // for malformed URI --- SketchSwitch.Utils.convertStringEncoding() |
. | return browser.tabs.executeScript(tab.id, { |
| await browser.tabs.executeScript(tab.id, { |
| code: ` |
| code: ` |
| original__decodeURIComponent = decodeURIComponent; |
| original__decodeURIComponent = decodeURIComponent; |
| decodeURIComponent = s => unescape(s); |
| decodeURIComponent = s => unescape(s); |
| true; // Script '<anonymous code>' result is non-structured-clonable data |
| true; // Script '<anonymous code>' result is non-structured-clonable data |
| `, |
| `, |
| }); |
| }); |
. | } |
| await browser.tabs.executeScript(tab.id, { |
| }).then(result => { |
| |
| if (loaded_first) { |
| |
| return browser.tabs.executeScript(tab.id, { |
| |
| file: "/content/SketchSwitch.js", |
| file: "/content/SketchSwitch.js", |
| }); |
| }); |
. | } |
| await browser.tabs.executeScript(tab.id, { |
| }).then(_ => { |
| |
| if (loaded_first) { |
| |
| return browser.tabs.executeScript(tab.id, { |
| |
| code: ` |
| code: ` |
| decodeURIComponent = original__decodeURIComponent; |
| decodeURIComponent = original__decodeURIComponent; |
| true; |
| true; |
| `, |
| `, |
| }); |
| }); |
. | } |
| await browser.tabs.executeScript(tab.id, { |
| }).then(_ => { |
| |
| if (loaded_first) { |
| |
| return browser.tabs.executeScript(tab.id, { |
| |
| file: "/content/sketch-patch.js", |
| file: "/content/sketch-patch.js", |
| }); |
| }); |
| } |
| } |
. | }).then(_ => { |
| await browser.tabs.executeScript(tab.id, { |
| return browser.tabs.executeScript(tab.id, { |
| |
| code: ` |
| code: ` |
| (_ => { |
| (_ => { |
| const canvas = document.getElementById("__sketch_switch_canvas__"); |
| const canvas = document.getElementById("__sketch_switch_canvas__"); |
| if (canvas) { |
| if (canvas) { |
| // Sketch Menu is shown. |
| // Sketch Menu is shown. |
| return; |
| return; |
| } |
| } |
| |
| |
| const sketch = new SketchSwitch(window, {}); |
| const sketch = new SketchSwitch(window, {}); |
| sketch.show(); |
| sketch.show(); |
| })(); |
| })(); |
| `, |
| `, |
| }); |
| }); |
. | }).catch(error => { |
| } catch(error) { |
| console.error(error.message || error); |
| console.error(error.message || error); |
| console.dir(error); |
| console.dir(error); |
. | }); |
| } |
| } |
| } |
| |
| |