-
Notifications
You must be signed in to change notification settings - Fork 2
/
popup.js
80 lines (74 loc) · 2.08 KB
/
popup.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {
$,
anonymize,
captureScreenshot,
delay,
DOMrestore,
DOMsave,
exec,
getSetting,
setSetting,
} from "./utils.js";
$("#open-guidelines").addEventListener("click", () => {
chrome.tabs.create({
url: "https://review.docs.microsoft.com/help/contribute/contribute-how-to-create-screenshot?branch=master",
});
});
$("#open-contribute").addEventListener("click", () => {
chrome.tabs.create({
url: "https://github.com/manekinekko/ms-moonshot",
});
});
$("#container").addEventListener("click", async () => {
let shouldAnonymize = await getSetting("anonymize");
if (shouldAnonymize) {
await DOMsave();
await anonymize(shouldAnonymize);
await delay(500);
await captureScreenshot(true);
await DOMrestore();
} else {
await captureScreenshot(true);
}
});
$("#anonymize").addEventListener("change", async (event) => {
const shouldAnonymize = event.target.checked;
await setSetting({
anonymize: shouldAnonymize,
});
await anonymize(shouldAnonymize);
});
window.addEventListener("load", async () => {
let dataUrl = await captureScreenshot(false);
// load screenshot
let container = $("#container");
container.src = dataUrl;
let img = new Image();
img.onload = function () {
container.style.cssText = `background-image: url(${dataUrl});`;
};
img.src = dataUrl;
// sync settings
let isAnonymizeEnabled = await getSetting("anonymize");
$("#anonymize").checked = isAnonymizeEnabled;
});
window.addEventListener("load", async () => {
let code = function () {
if (!document.querySelector("#preload")) {
var css = document.createElement("style");
css.id = "preload";
css.type = "text/css";
css.innerHTML = `
# Note: this is just a hack to preload the avatar over the wire!
.preload {
position: absolute;
top: -99999px;
left: -99999px;
background-image: url(https://portal.azure.com/Content/static/MsPortalImpl/AvatarMenu/AvatarMenu_defaultAvatarSmall.png);
}
`;
document.body.appendChild(css);
}
};
await exec(code);
});