Skip to content

Commit

Permalink
Support Blob URL and FileSystem URL
Browse files Browse the repository at this point in the history
Fix #6
  • Loading branch information
ccloli committed Jan 17, 2019
1 parent 8b99e73 commit 7344ce1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ Search By Image | 以图搜图
> 另外,搜索贴吧内图片时,如果出现搜索的 url 为 base64 的情况,请看此贴:http://tieba.baidu.com/p/3145502558
更新历史:

> 2019.01.18 1.6.4 Support Blob URL and FileSystem URL ([#6](https://github.com/ccloli/Search-By-Image/issues/6))
> 2018.10.26 1.6.3 Update WhatAnime to `trace.moe` ([#5](https://github.com/ccloli/Search-By-Image/issues/5))
>
> 2018.03.04 1.6.2 Fix setting is not loaded; Fix previous fixes is not working (Fix GreasyFork [#31706](https://greasyfork.org/en/forum/discussion/31706/x), these bugs makes WhatAnime & Ascii2D save twice or more times.)
Expand Down
19 changes: 17 additions & 2 deletions search-by-image.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Search By Image
// @version 1.6.3
// @version 1.6.4
// @description Search By Image | 以图搜图
// @match <all_urls>
// @include *
Expand Down Expand Up @@ -425,6 +425,20 @@ function hide_panel() {
document.removeEventListener('paste', get_clipboard, false);
}

function upload_blob_url(url) {
if (!url) return;
var req = new XMLHttpRequest();
req.open('GET', url);
req.responseType = 'blob';
req.onload = function() {
reader.readAsDataURL(req.response);
};
req.onerror = function() {
alert(i18n[lang]['uf']);
};
req.send();
}

document.addEventListener('mousedown', function(event) {
//console.log('Search Image >>\nevent.ctrlKey: '+event.ctrlKey+'\nevent.button: '+event.button+'\nevent.target:'+event.target+'\nevent.target.tagName: '+event.target.tagName+'\nevent.target.src: '+event.target.src+'\nevent.pageX: '+event.pageX+'\nevent.pageY: '+event.pageY+'\ndocument.documentElement.clientWidth: '+document.documentElement.clientWidth+'\ndocument.documentElement.clientHeight: '+document.documentElement.clientHeight+'\ndocument.documentElement.scrollWidth: '+document.documentElement.scrollWidth+'\ndocument.documentElement.scrollHeight: '+document.documentElement.scrollHeight+'\ndocument.documentElement.scrollLeft: '+document.documentElement.scrollLeft+'\ndocument.documentElement.scrollTop: '+document.documentElement.scrollTop);
if (disable_contextmenu == true) {
Expand Down Expand Up @@ -469,7 +483,8 @@ document.addEventListener('mousedown', function(event) {
if (event.target.tagName.toLowerCase() == 'img' && event.target.src != null) {
search_panel.getElementsByClassName('search_top_url')[0].style.marginTop = '0px';
search_panel.getElementsByClassName('search_top_url')[0].textContent = event.target.src;
if (event.target.src.match(/^data:\s*.*?;\s*base64,\s*/) != null) upload_file(event.target.src);
if (/^data:\s*.*?;\s*base64,\s*/.test(event.target.src)) upload_file(event.target.src);
else if (/^(?:blob:|filesystem:)/.test(event.target.src)) upload_blob_url(event.target.src);
else img_src = event.target.src;
}
else {
Expand Down

0 comments on commit 7344ce1

Please sign in to comment.