Skip to content

Commit 28fd4dc

Browse files
committed
[google images paste] add progress bar, add support for www.google.com
1 parent 308a09a commit 28fd4dc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Google_Images_-_search_by_paste.user.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// @name Google Images - search by paste
33
// @description Reverse search an image by pasting it
44
// @license MIT
5-
// @version 1.0.0
5+
// @version 1.1.0
66
// @namespace tithen-firion.github.io
77
// @match *://images.google.com/*
8+
// @match *://www.google.com/*
89
// @grant GM.xmlHttpRequest
910
// @grant GM_xmlhttpRequest
1011
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
@@ -13,14 +14,28 @@
1314
document.body.addEventListener('paste', e => {
1415
for(let item of e.clipboardData.items) {
1516
if(item.type.indexOf('image') > -1) {
17+
let progress = document.createElement('div');
18+
progress.style.position = 'fixed';
19+
progress.style.top = 0;
20+
progress.style.left = 0;
21+
progress.style.width = '5%';
22+
progress.style.height = '5px';
23+
progress.style.background = 'green';
24+
document.body.appendChild(progress);
25+
1626
let data = new FormData();
17-
data.set('encoded_image', item.getAsFile());
27+
let file = item.getAsFile();
28+
let fileSize = file.size;
29+
data.set('encoded_image', file);
1830
GM.xmlHttpRequest({
1931
url: 'https://images.google.com/searchbyimage/upload',
2032
method: 'post',
2133
data: data,
2234
onload: response => {
2335
document.location = response.finalUrl;
36+
},
37+
onprogress: response => {
38+
progress.style.width = response.loaded / fileSize * 100 + '%';
2439
}
2540
});
2641
e.preventDefault();

0 commit comments

Comments
 (0)