Skip to content

Commit

Permalink
fix google image conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ttop32 committed Apr 23, 2024
1 parent b0e100d commit 88a5e09
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions doc/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ English, Russian, Japanese, Chinese and so on
# Change Log
- 0.1.138
- Fix mouseover detect performance issue (request by eSKej)
- Fix google image load
- 0.1.137
- Fix reddit site conflict
- 0.1.136
Expand Down
21 changes: 11 additions & 10 deletions src/translator/googleWebImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ export default class googleWebImage extends BaseTranslator {
}).text();
}
static async wrapResponse(res, text, sourceLang, targetLang) {
var AFScript = res.match(/AF_initDataCallback\(([^<]+)\);/g)[1];
var AFScript1 = AFScript.match(/AF_initDataCallback\(([^<]+)\);/)[1];
var urlDataText = AFScript1.match(
/\"b-GRID_STATE0\"(.*)sideChannel:\s?{}}/
)[0];
var urlsMeta = urlDataText.match(
/\[\"(https\:\/\/encrypted-tbn0\.gstatic\.com\/images\?.*?)\",\d+,\d+\]/g
);
var imageUrls = urlsMeta.map((urlMeta) => JSON.parse(urlMeta)[0]);
var urlJSONData = res.match(/google.ldi=(\{[^{]+\});/)[1];
var urlJSON = JSON.parse(urlJSONData);
var imageUrl = urlJSON[Object.keys(urlJSON)[0]];
var detectedLang = await util.detectLangBrowser(text);
var base64Url = await util.getBase64(imageUrls[0]);
var base64Url = await util.getBase64(imageUrl);

return {
targetText: "image",
Expand All @@ -36,3 +30,10 @@ export default class googleWebImage extends BaseTranslator {
};
}
}

// var res = "";
// async function getImageSite() {
// const response = await fetch("https://www.google.com/search?q=apple&udm=2");
// res = await response.text();
// }
// getImageSite();

0 comments on commit 88a5e09

Please sign in to comment.