-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
35 lines (32 loc) · 1.38 KB
/
main.js
File metadata and controls
35 lines (32 loc) · 1.38 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
let swapped = false;
document.addEventListener('keydown', e => {
if (e.key === 's' && e.ctrlKey) {
if (!swapped) {
doSwap();
swapped = true;
} else {
alert('This page is already in generation mode. Hover over an image on the page to generate an image from the alt text');
}
}
});
const doSwap = () => {
const elements = document.body.querySelectorAll('img');
for (let i = 0; i < elements.length; i++) {
const element = elements[i];
const computedStyle = window.getComputedStyle(element);
const attrs = element.attributes;
const replacer = document.createElement('img-replace');
for (let i = 0; i < attrs.length; i++) {
replacer.setAttribute(attrs[i].name, attrs[i].value);
}
chrome.storage.sync.get(['serviceURL', 'sampler', 'steps']).then(result => {
replacer.setAttribute('image-service', result.serviceURL || 'http://localhost:5000');
replacer.setAttribute('sampler', result.sampler || 'DDIM');
replacer.setAttribute('steps', result.sampler || '35');
});
replacer.style.width = computedStyle.width;
replacer.style.height = computedStyle.height;
element.replaceWith(replacer);
}
alert('Generative mode activated! Hover over an image on the page to generate an image from the alt text')
};