-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathimg.js
32 lines (30 loc) · 929 Bytes
/
img.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
"use strict";
window.addEventListener("load", function() {
let url = window.location.href;
let idx = url.indexOf("#!");
if (idx > 0 && idx < url.length - 2) {
let imgURL = url.substring(idx + 2);
document.addEventListener("keydown", function(e) {
if ((window.navigator.platform.match("Mac")?e.metaKey:e.ctrlKey)&&
e.keyCode == 83) {
e.preventDefault();
window.location.href = imgURL;
}
}, false);
let e = document.createElement("img");
e.className = "transparent";
e.src = imgURL;
e.onerror = function() {
fetch(new Request(imgURL)).then(function(r) {
r.blob().then(function(b) {
e.src = URL.createObjectURL(b);
});
});
};
document.body.appendChild(e);
}
// remove url of this generated page from history
browser.permissions.contains({permissions: ["history"]}).then(allowed => {
if (allowed) browser.history.deleteUrl({url: window.location.href});
});
});