|
2 | 2 | // @name Google Images - search by paste
|
3 | 3 | // @description Reverse search an image by pasting it
|
4 | 4 | // @license MIT
|
5 |
| -// @version 1.0.0 |
| 5 | +// @version 1.1.0 |
6 | 6 | // @namespace tithen-firion.github.io
|
7 | 7 | // @match *://images.google.com/*
|
| 8 | +// @match *://www.google.com/* |
8 | 9 | // @grant GM.xmlHttpRequest
|
9 | 10 | // @grant GM_xmlhttpRequest
|
10 | 11 | // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
|
|
13 | 14 | document.body.addEventListener('paste', e => {
|
14 | 15 | for(let item of e.clipboardData.items) {
|
15 | 16 | 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 | + |
16 | 26 | 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); |
18 | 30 | GM.xmlHttpRequest({
|
19 | 31 | url: 'https://images.google.com/searchbyimage/upload',
|
20 | 32 | method: 'post',
|
21 | 33 | data: data,
|
22 | 34 | onload: response => {
|
23 | 35 | document.location = response.finalUrl;
|
| 36 | + }, |
| 37 | + onprogress: response => { |
| 38 | + progress.style.width = response.loaded / fileSize * 100 + '%'; |
24 | 39 | }
|
25 | 40 | });
|
26 | 41 | e.preventDefault();
|
|
0 commit comments