diff --git a/README.MD b/README.MD index 015672e..0b590eb 100644 --- a/README.MD +++ b/README.MD @@ -4,7 +4,7 @@ [![Mozilla Add-on](https://img.shields.io/amo/v/view-image.svg)](https://addons.mozilla.org/en-US/firefox/addon/view-image/) [![Travis](https://github.com/bijij/ViewImage/workflows/CI/badge.svg)](https://github.com/bijij/ViewImage/actions) -View Image is a Chrome / Firefox extension which implements the "View Image" and "Search by image" buttons back into Google Image Search. +View Image is a Chrome / Firefox extension which re-implements the "View Image" button back into Google Image Search. ## Install You can get this extension for Firefox or Chrome or as a userscript: diff --git a/_locales/ca/messages.json b/_locales/ca/messages.json index 0aa457c..1ac3ae3 100644 --- a/_locales/ca/messages.json +++ b/_locales/ca/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": "Reimplementa els botons \"Mostra la imatge\" i \"Cerca per imatge\" de Google Imatges.", + "message": "Reimplementa els boton \"Mostra la imatge\" de Google Imatges.", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/cs/messages.json b/_locales/cs/messages.json index 7ff4c3d..9b49a7b 100644 --- a/_locales/cs/messages.json +++ b/_locales/cs/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, displayed on the web store." }, "appDesc": { - "message": "Re-implimentuje tlačítka \"Zobrazit obrázek\" and \"Vyhledat podle obrázku\" na vyhledávači Google.", + "message": "Re-implementuje tlačítko \"Zobrazit obrázek\" na vyhledávači Google.", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/da/messages.json b/_locales/da/messages.json index 2ec2c8e..751bb0d 100644 --- a/_locales/da/messages.json +++ b/_locales/da/messages.json @@ -1,7 +1,7 @@ { "appDesc": { "description": "The description of the application, as shown on the web store.", - "message": "Genindfør \"Vis billede\" og \"Søg efter billede\"-knapperne i Google Billeder." + "message": "Genindfør \"Vis billede\" og \"Vis billede\"-knappen i Google Billeder." }, "appName": { "description": "Title of the application, as displayed on the web store.", diff --git a/_locales/de/messages.json b/_locales/de/messages.json index 67887c8..f367afe 100644 --- a/_locales/de/messages.json +++ b/_locales/de/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": "Dieses Plugin bringt die Schaltfläche \"Bild ansehen\" und die \"Google Bildersuche\" zurück.", + "message": "Dieses Plugin bringt die Schaltfläche \"Bild ansehen\".", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 1dffe35..883ff0a 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": "Re-implements the Google Images' \"View Image\" and \"Search by Image\" buttons.", + "message": "Re-implements the Google Images' \"View Image\" button.", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/es/messages.json b/_locales/es/messages.json index 390339e..458af63 100644 --- a/_locales/es/messages.json +++ b/_locales/es/messages.json @@ -4,7 +4,7 @@ "description": "Título de la aplicación, mostrado en la Tienda Web." }, "appDesc": { - "message": "Reimplementa los botones de Google Imágenes: \"Ver imagen\" y \"Buscar por imagen\".", + "message": "Reimplementa los botón de Google Imágenes: \"Ver imagen\".", "description": "La descripción de la aplicación, mostrada en la Tienda Web." }, "searchImage": { diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index 35089bd..98177c1 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -4,7 +4,7 @@ "description": "Titre de l'application, affiché sur la boutique en ligne." }, "appDesc": { - "message": "Réimplémente les boutons \"Voir l'image\" et \"Recherche par image\".", + "message": "Réimplémente les bouton \"Voir l'image\".", "description": "La description de l'application, comme indiqué sur la boutique en ligne." }, "searchImage": { diff --git a/_locales/he/messages.json b/_locales/he/messages.json index db6703c..147bc73 100644 --- a/_locales/he/messages.json +++ b/_locales/he/messages.json @@ -4,7 +4,7 @@ "description": "כותרת היישום, כפי שמוצג בחנות האינטרנט." }, "appDesc": { - "message": "מחזיר את הלחצנים \"הצג תמונה\" ו \"חפש לפי תמונה\" בגוגל תמונות.", + "message": "מחזיר אתלַחְצָן \"הצג תמונה\" בגוגל תמונות.", "description": "תיאור היישום, כפי שמוצג בחנות האינטרנט." }, "searchImage": { diff --git a/_locales/hu/messages.json b/_locales/hu/messages.json index bc50ae8..4dc478e 100644 --- a/_locales/hu/messages.json +++ b/_locales/hu/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": "Újra elérhetővé válik a \"Kép megtekintése\" és a \"Keresés kép alapján\" gomb a Google képkeresőjében.", + "message": "Újra elérhetővé válik a \"Kép megtekintése\" gomb a Google képkeresőjében.", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/it/messages.json b/_locales/it/messages.json index a0bb9e4..d67360b 100644 --- a/_locales/it/messages.json +++ b/_locales/it/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": "Riattiva i pulsanti \"Visualizza immagine\" e \"Ricerca tramite immagine\" di Google Immagini.", + "message": "Riattiva i pulsante \"Visualizza immagine\" di Google Immagini.", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/ja/messages.json b/_locales/ja/messages.json index 040fae0..094c2a6 100644 --- a/_locales/ja/messages.json +++ b/_locales/ja/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": "Google画像検索に\"画像を表示\"と\"画像を検索\"ボタンを再実装します。", + "message": "Google画像検索に\"画像を表示\"ボタンを再実装します。", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/ko/messages.json b/_locales/ko/messages.json index 6484409..e44f516 100644 --- a/_locales/ko/messages.json +++ b/_locales/ko/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": "Google 이미지의 \"이미지 보기\" 와 \"이미지로 검색\" 버튼을 다시 적용합니다.", + "message": "Google 이미지의 \"이미지 보기\" 버튼을 다시 적용합니다.", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/nl/messages.json b/_locales/nl/messages.json index 03b9047..fcc4717 100644 --- a/_locales/nl/messages.json +++ b/_locales/nl/messages.json @@ -4,7 +4,7 @@ "description": "Titel van de applicatie, zoals weergegeven in de web store." }, "appDesc": { - "message": "Herimplementeert de knoppen \"Afbeelding weergeven\" en \"Afbeelding zoeken\" in Google Afbeeldingen.", + "message": "Herimplementeert de knop \"Afbeelding weergeven\" in Google Afbeeldingen.", "description": "Beschrijving van de applicatie, zoals weergegeven in de web store." }, "searchImage": { diff --git a/_locales/no/messages.json b/_locales/no/messages.json index f0271ad..e1c43a1 100644 --- a/_locales/no/messages.json +++ b/_locales/no/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, displayed on the web store." }, "appDesc": { - "message": "Re-implementerer Google Bilder, \"Se Bilde\" og \"Søk med Bilde\" knappene.", + "message": "Re-implementerer Google Bilder, \"Se Bilde\" og knappe.", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/pl/messages.json b/_locales/pl/messages.json index 2c2a1b4..4527966 100644 --- a/_locales/pl/messages.json +++ b/_locales/pl/messages.json @@ -4,7 +4,7 @@ "description": "Nazwa aplikacji w sklepie internetowym." }, "appDesc": { - "message": "Przywraca przyciski \"Pokaż obraz\" i \"Wyszukaj obrazem\" w Grafice Google.", + "message": "Przywraca przycisk \"Pokaż obraz\" w Grafice Google.", "description": "Opis aplikacji w sklepie internetowym." }, "searchImage": { diff --git a/_locales/pt/messages.json b/_locales/pt/messages.json index 781ad65..e06bfa8 100644 --- a/_locales/pt/messages.json +++ b/_locales/pt/messages.json @@ -4,7 +4,7 @@ "description": "Nome da extensão, como apresentado na web store." }, "appDesc": { - "message": "Reintroduz o botão \"Ver imagem\" e o link \"Pesquisar por imagem\" do Google Imagens.", + "message": "Reintroduz o botão \"Ver imagem\" do Google Imagens.", "description": "A descrição da extensão, como apresentada na web store." }, "searchImage": { diff --git a/_locales/pt_BR/messages.json b/_locales/pt_BR/messages.json index d629b6b..5707bae 100644 --- a/_locales/pt_BR/messages.json +++ b/_locales/pt_BR/messages.json @@ -4,7 +4,7 @@ "description": "Nome da extensão, mostrada na web store." }, "appDesc": { - "message": "Reimplementa no Google Imagens o botão \"Ver Imagem\" e o link \"Pesquisar por imagem\".", + "message": "Reimplementa no Google Imagens o botão \"Ver Imagem\".", "description": "A descrição da extensão, como mostrada na web store." }, "searchImage": { diff --git a/_locales/pt_PT/messages.json b/_locales/pt_PT/messages.json index 781ad65..e06bfa8 100644 --- a/_locales/pt_PT/messages.json +++ b/_locales/pt_PT/messages.json @@ -4,7 +4,7 @@ "description": "Nome da extensão, como apresentado na web store." }, "appDesc": { - "message": "Reintroduz o botão \"Ver imagem\" e o link \"Pesquisar por imagem\" do Google Imagens.", + "message": "Reintroduz o botão \"Ver imagem\" do Google Imagens.", "description": "A descrição da extensão, como apresentada na web store." }, "searchImage": { diff --git a/_locales/ru/messages.json b/_locales/ru/messages.json index c621882..d33e6d9 100644 --- a/_locales/ru/messages.json +++ b/_locales/ru/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": "Возвращает в Google картинки кнопки' \"Открыть в полном размере\" и \"Поиск по картинке\".", + "message": "Возвращает в Google картинки кнопки' \"Открыть в полном размере\".", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/si/messages.json b/_locales/si/messages.json index 8330533..a367f81 100644 --- a/_locales/si/messages.json +++ b/_locales/si/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": " \" පින්තුරය බලන්න \" සහ \" පින්තුරය මගින් සෙවීම \" පහසුකම් වල බොත්තම් නැවත සක්රීය කිරීම", + "message": " \" පින්තුරය බලන්න \" සහ පහසුකම් වල බොත්තම නැවත සක්රීය කිරීම", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/sk/messages.json b/_locales/sk/messages.json index 5248dae..67a3c4f 100644 --- a/_locales/sk/messages.json +++ b/_locales/sk/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, displayed on the web store." }, "appDesc": { - "message": "Pridá tlačidlá \"Zobraziť obrázok\" a \"Vyhľadať podľa obrázku\" do vyhladávača Google.", + "message": "Pridá tlačidlo \"Zobraziť obrázok\" do vyhladávača Google.", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/sl/messages.json b/_locales/sl/messages.json index 787ed25..7cc8b8c 100644 --- a/_locales/sl/messages.json +++ b/_locales/sl/messages.json @@ -4,7 +4,7 @@ "description": "Ime aplikacije, prikazano na spletni trgovini." }, "appDesc": { - "message": "Ponovno prikaže gumba \"Ogled slike\" in \"Iskanje s sliko\" na Google Slikah.", + "message": "Ponovno prikaže gumb \"Ogled slike\" na Google Slikah.", "description": "Opis aplikacije, prikazan na spletni trgovini." }, "searchImage": { diff --git a/_locales/sv/messages.json b/_locales/sv/messages.json index cf5d1fb..4dc8845 100644 --- a/_locales/sv/messages.json +++ b/_locales/sv/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, displayed on the web store." }, "appDesc": { - "message": "Re-implimenterar Google bilden, \"Visa originalbilden\" och \"Fler storlekar\" knapparna.", + "message": "Re-implimenterar Google bilden, \"Visa originalbilden\" knappen.", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/tr/messages.json b/_locales/tr/messages.json index 7e9212c..e5212ef 100644 --- a/_locales/tr/messages.json +++ b/_locales/tr/messages.json @@ -4,7 +4,7 @@ "description": "Uygulamanın web store üzerinde gösterildiği şekliyle başlığı." }, "appDesc": { - "message": "Google Görseller'in \"Resmi Görüntüle\" ve \"Görselle Ara\" düğmelerini sağlar.", + "message": "Google Görsellerin \"Resmi Görüntüle\" vdüğme sağlar.", "description": "Uygulamanın web store üzerinde gösterildiği şekliyle açıklaması." }, "searchImage": { diff --git a/_locales/zh_CN/messages.json b/_locales/zh_CN/messages.json index c37c75b..74893e2 100644 --- a/_locales/zh_CN/messages.json +++ b/_locales/zh_CN/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": "重新实现 Google 图片的“查看图片”和“以图搜图”按钮。", + "message": "重新实现 Google 图片的“查看图片”按钮。", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/_locales/zh_TW/messages.json b/_locales/zh_TW/messages.json index 5f5fdfb..7bce2d7 100644 --- a/_locales/zh_TW/messages.json +++ b/_locales/zh_TW/messages.json @@ -4,7 +4,7 @@ "description": "Title of the application, as displayed on the web store." }, "appDesc": { - "message": "重新實現 Google 圖片的「檢視圖片」和「以圖搜圖」按鈕。", + "message": "重新實現 Google 圖片的「檢視圖片」按鈕。", "description": "The description of the application, as shown on the web store." }, "searchImage": { diff --git a/html/options.html b/html/options.html index 38ee03f..813f60e 100644 --- a/html/options.html +++ b/html/options.html @@ -15,23 +15,29 @@ + + + diff --git a/js/background.js b/js/background.js index 6274eea..92b37e3 100644 --- a/js/background.js +++ b/js/background.js @@ -1,24 +1,24 @@ 'use-strict'; -const DEBUG = false; +const DEBUG = true; -function toI18n(str) { +/* function toI18n(str) { return str.replace(/__MSG_(\w+)__/g, function (match, v1) { return v1 ? chrome.i18n.getMessage(v1) : ''; }); -} +} */ // Default options const defaultOptions = { 'open-in-new-tab': true, - 'open-search-by-in-new-tab': true, - 'show-globe-icon': true, + //'open-search-by-in-new-tab': true, + //'show-globe-icon': true, //'hide-images-subject-to-copyright': false, 'manually-set-button-text': false, 'no-referrer': false, 'button-text-view-image': '', - 'button-text-search-by-image': '', - 'context-menu-search-by-image': true, + //'button-text-search-by-image': '', + //'context-menu-search-by-image': true, //'context-menu-search-by-image-new-tab': false, }; @@ -27,7 +27,8 @@ chrome.storage.sync.get('defaultOptions', function () { chrome.storage.sync.set({ defaultOptions }); }); -chrome.runtime.onInstalled.addListener(() => { +// Deprecated for now, user feedback is that it's not useful +/* chrome.runtime.onInstalled.addListener(() => { chrome.storage.sync.get(['options', 'defaultOptions'], (storage) => { if (!storage.hasOwnProperty('options')) { storage.options = {}; @@ -36,7 +37,8 @@ chrome.runtime.onInstalled.addListener(() => { const options = Object.assign(storage.defaultOptions, storage.options); // Setup "Search by image" context menu item - if (options['context-menu-search-by-image']) { + + if (options['context-menu-search-by-image']) { chrome.contextMenus.create( { 'id': 'ViewImage-SearchByImage', @@ -46,9 +48,10 @@ chrome.runtime.onInstalled.addListener(() => { ); } }); -}); +}); */ -chrome.contextMenus.onClicked.addListener((info, tab) => { +// See above deprecation note +/* chrome.contextMenus.onClicked.addListener((info, tab) => { if (DEBUG) console.log('ViewImage: Search By Image context menu item clicked.', info, tab); @@ -57,4 +60,4 @@ chrome.contextMenus.onClicked.addListener((info, tab) => { url: `https://lens.google.com/uploadbyurl?url=${encodeURIComponent(info.srcUrl)}`, }); } -}); +}); */ \ No newline at end of file diff --git a/js/content-script.js b/js/content-script.js index 4756a77..a9d8081 100644 --- a/js/content-script.js +++ b/js/content-script.js @@ -1,6 +1,6 @@ 'use strict'; -const DEBUG = false; +const DEBUG = true; const VERSIONS = { FEB18: 'FEB18', @@ -9,9 +9,10 @@ const VERSIONS = { }; var images = new Object(); +var options; function toI18n(str) { - return str.replace(/__MSG_(\w+)__/g, function (match, v1) { + return str.replace(/__MSG_(\w+)__/g, function (_, v1) { return v1 ? chrome.i18n.getMessage(v1) : ''; }); } @@ -65,7 +66,7 @@ function findImageURL(container, version) { image = iframe.contentDocument.querySelector('img#irc_mi'); break; case VERSIONS.OCT19: - image = container.querySelector('img[src].n3VNCb, img[src].r48jcc'); + image = container.querySelector('img[src][style][jsaction]'); if (image.src in images) { return images[image.src]; } @@ -114,9 +115,8 @@ function findImageURL(container, version) { } -function addViewImageButton(container, imageURL, version) { - - // get the visit buttonm +function addViewImageButton(container, node, imageURL, version) { + // get the visit button var visitButton; switch (version) { case VERSIONS.FEB18: @@ -126,10 +126,22 @@ function addViewImageButton(container, imageURL, version) { visitButton = container.querySelector('a.irc_hol[href]'); break; case VERSIONS.OCT19: - visitButton = container.querySelector('.ZsbmCf[href], a.J2oL9c, a.jAklOc, a.uZ49bd, a.e0XTue, a.kWgFk, a.j7ZI7c'); + var nodeRoot = node.parentElement.parentElement; + + visitButton = nodeRoot.parentElement?.nextSibling?.nextSibling?.querySelector('div a span')?.parentElement?.parentElement; + + // if the above fails, we're possibly on a mobile device + if (!visitButton) { + visitButton = nodeRoot.nextSibling.nextSibling.querySelector('div a span').parentElement.parentElement; + } break; } + if (DEBUG && !visitButton) + console.log('ViewImage: Adding View-Image button failed, visit button was not found.'); + + console.log(visitButton); + // Create the view image button var viewImageButton = visitButton.cloneNode(true); viewImageButton.classList.add('vi_ext_addon'); @@ -178,7 +190,8 @@ function addViewImageButton(container, imageURL, version) { } // Remove globe icon if not wanted - if (!options['show-globe-icon']) { + // Deprecated, new google image search doesn't have globe icon + /* if (!options['show-globe-icon']) { switch (version) { case VERSIONS.FEB18: viewImageButton.querySelector('.RL3J9c').remove(); @@ -190,7 +203,7 @@ function addViewImageButton(container, imageURL, version) { viewImageButton.querySelector('.XeEBj.AJkoub').remove(); break; } - } + } */ // Place the view image button visitButton.parentElement.insertBefore(viewImageButton, visitButton); @@ -198,7 +211,8 @@ function addViewImageButton(container, imageURL, version) { } -function addSearchImageButton(container, imageURL, version) { +// Deprecared, google has removed the endpoints required for this to work +/* function addSearchImageButton(container, imageURL, version) { var link; switch (version) { @@ -255,7 +269,7 @@ function addSearchImageButton(container, imageURL, version) { link.parentElement.insertBefore(searchImageButton, link); link.parentElement.insertBefore(link, searchImageButton); -} +} */ // Adds links to an object @@ -292,61 +306,95 @@ function addLinks(node) { return; } - addViewImageButton(container, imageURL, version); - addSearchImageButton(container, imageURL, version); + addViewImageButton(container, node, imageURL, version); + + // Deprecated, see comment on function definition + //addSearchImageButton(container, imageURL, version); } function parseDataSource(array) { - var meta = array[31][0][12][2]; - for (var i = 0; i < meta.length; i++) { - try { - images[meta[i][1][2][0]] = meta[i][1][3][0]; - } catch (error) { - if (DEBUG) - console.log('ViewImage: Skipping image'); + + if (DEBUG) + console.log('ViewImage: Parsing data source...'); + + var meta; + try { + meta = array[31][0][12][2]; + + for (var i = 0; i < meta.length; i++) { + try { + images[meta[i][1][2][0]] = meta[i][1][3][0]; + } catch (error) { + if (DEBUG) + console.log('ViewImage: Skipping image'); + } + } + } + catch { + // I encountered this alternative so I've added it here + // We should probably find a way to do this dynamically + meta = array[56][1][0][0][1][0]; + + for (var i = 0; i < meta.length; i++) { + try { + var data = Object.values(meta[i][0][0])[0]; + images[data[1][2][0]] = data[1][3][0]; + } catch (error) { + if (DEBUG) + console.log('ViewImage: Skipping image'); + } } } } -function parseDataSource1() { - const start_search = /AF_initDataCallback\({key:\s'ds:1',\sisError:\s{2}false\s,\shash:\s'\d+',\sdata:/; - const end_search = ', sideChannel: {}});'; - - var match = document.documentElement.innerHTML.match(start_search); - - var start_index = match.index + match[0].length; - var end_index = start_index + document.documentElement.innerHTML.slice(start_index).indexOf(end_search); +function parseDataSourceType1(params) { + if (DEBUG) + console.log('ViewImage: Parsing data source type 1...'); - parseDataSource(JSON.parse(document.documentElement.innerHTML.slice(start_index, end_index))); -} + const data_start_search = /\sdata:\[/; + const data_end_search = '], '; -function parseDataSource2() { - const start_search = /AF_initDataCallback\({key:\s'ds:2',\sisError:\s{2}false\s,\shash:\s'\d+',\sdata:function(){return\s/; - const end_search = '}});'; + var match = params.match(data_start_search); - var match = document.documentElement.innerHTML.match(start_search); + var start_index = match.index + match[0].length - 1; + var end_index = start_index + params.slice(start_index).indexOf(data_end_search) + 1; - var start_index = match.index + match[0].length; - var end_index = start_index + document.documentElement.innerHTML.slice(start_index).indexOf(end_search); - parseDataSource(JSON.parse(document.documentElement.innerHTML.slice(start_index, end_index))); + parseDataSource(JSON.parse(params.slice(start_index, end_index))); } // Check if source holds array of images try { + const start_search = />AF_initDataCallback\(/g; + const end_search = ');'; - if (document.documentElement.innerHTML.indexOf('key: \'ds:1\'') != -1) { - if (DEBUG) - console.log('ViewImage: Attempting to parse data source 1.'); - parseDataSource1(); - } else if (document.documentElement.innerHTML.indexOf('key: \'ds:2\'') != -1) { - if (DEBUG) - console.log('ViewImage: Attempting to parse data source 2.'); - parseDataSource2(); - } else { - throw 'Could not determine data source type.'; + var success = false; + + let match; + while (!success && ((match = start_search.exec(document.documentElement.innerHTML)) !== null)) { + var start_index = match.index + match[0].length; + var end_index = start_index + document.documentElement.innerHTML.slice(start_index).indexOf(end_search); + + var params = document.documentElement.innerHTML.slice(start_index, end_index); + + const ds_search = /key:\s\'ds:(\d)\'/ + var ds_match = params.match(ds_search); + + if (ds_match === null) { + continue; + } + + if (ds_match[1] == 1) { + // data source 1 + parseDataSourceType1(params); + success = true; + } } - if (DEBUG) + if (!success) { + if (DEBUG) + console.log('ViewImage: Failed to find data source.'); + } + else if (DEBUG) console.log('ViewImage: Successfully created source images array.'); } catch (error) { @@ -356,38 +404,24 @@ try { } } - // Define the mutation observers var observer = new MutationObserver(function (mutations) { - if (DEBUG) console.log('ViewImage: Mutations detected: ', mutations); - var node; for (var mutation of mutations) { - if (mutation.addedNodes && mutation.addedNodes.length > 0) { - for (node of mutation.addedNodes) { - if (node.classList) { - // Check for new image nodes - if (['irc_mi', 'irc_mut', 'irc_ris', 'n3VNCb', 'r48jcc'].some(className => node.classList.contains(className))) { - addLinks(node); - } + if (mutation.addedNodes) { + for (var node of mutation.addedNodes) { + var imageContainerClass = document.querySelector('img[src][style][jsaction]')?.classList[0]; + if (node.classList && [...node.classList].some(clsName => clsName === imageContainerClass)) { + addLinks(node); } } } - - if (mutation.target.classList && mutation.target.classList.contains('n3VNCb', 'r48jcc')) { - node = mutation.target.closest('.tvh9oe'); - - if (!node.hasAttribute('aria-hidden')) { - addLinks(node); - } - } } }); // Get options and start adding links -var options; chrome.storage.sync.get(['options', 'defaultOptions'], function (storage) { options = Object.assign(storage.defaultOptions, storage.options); @@ -401,7 +435,6 @@ chrome.storage.sync.get(['options', 'defaultOptions'], function (storage) { }); }); - // inject CSS into document if (DEBUG) console.log('ViewImage: Injecting CSS...'); @@ -413,19 +446,19 @@ customStyle.innerText = ` .PvkmDc.vi_ext_addon, .qnLx5b.vi_ext_addon { - margin: 0 4pt!important +margin: 0 4pt!important } .irc_hol.vi_ext_addon { - flex-grow:0!important +flex-grow:0!important } .zSA7pe[href^="/searchbyimage"] { - margin-left: 4px; +margin-left: 4px; } .ZsbmCf.vi_ext_addon{ - flex-grow:0 +flex-grow:0 }`; -document.head.appendChild(customStyle); +document.head.appendChild(customStyle); \ No newline at end of file diff --git a/js/options.js b/js/options.js index 45679da..246629e 100644 --- a/js/options.js +++ b/js/options.js @@ -84,7 +84,8 @@ chrome.storage.sync.get('defaultOptions', function (storage) { load(); }); -const update_context_menu = function (enabled) { +// Deprecated for now, user feedback is that it's not useful +/* const update_context_menu = function (enabled) { if (enabled) { chrome.contextMenus.create( { @@ -96,15 +97,16 @@ const update_context_menu = function (enabled) { } else { chrome.contextMenus.remove('ViewImage-SearchByImage'); } -}; +}; */ // On change, save document.addEventListener('change', event => { // Update the visibility of the context menu - if (event.target.id === 'context-menu-search-by-image') { + // Deprecated for now, user feedback is that it's not useful + /* if (event.target.id === 'context-menu-search-by-image') { update_context_menu(event.target.checked); - } + } */ switch (event.target.type) { case ('checkbox'): diff --git a/manifest.base.json b/manifest.base.json index 195cbb6..0675e48 100644 --- a/manifest.base.json +++ b/manifest.base.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "__MSG_appName__", - "version": "4.1.1", + "version": "5.0.0", "description": "__MSG_appDesc__", "default_locale": "en", "icons": { @@ -17,7 +17,6 @@ "default_popup": "html/popup.html" }, "permissions": [ - "contextMenus", "storage" ], "options_ui": { @@ -30,13 +29,13 @@ ], "matches": [ "*://*.google.com/*", - "*://*.google.ac/*", "*://*.google.ad/*", + "*://*.google.ae/*", "*://*.google.com.af/*", "*://*.google.com.ag/*", - "*://*.google.com.ai/*", + "*://*.google.al/*", "*://*.google.am/*", - "*://*.google.it.ao/*", + "*://*.google.co.ao/*", "*://*.google.com.ar/*", "*://*.google.as/*", "*://*.google.at/*", @@ -54,16 +53,13 @@ "*://*.google.com.bo/*", "*://*.google.com.br/*", "*://*.google.bs/*", + "*://*.google.bt/*", "*://*.google.co.bw/*", - "*://*.google.com.by/*", "*://*.google.by/*", "*://*.google.com.bz/*", "*://*.google.ca/*", - "*://*.google.com.kh/*", - "*://*.google.cc/*", "*://*.google.cd/*", "*://*.google.cf/*", - "*://*.google.cat/*", "*://*.google.cg/*", "*://*.google.ch/*", "*://*.google.ci/*", @@ -93,15 +89,12 @@ "*://*.google.fm/*", "*://*.google.fr/*", "*://*.google.ga/*", - "*://*.google.gd/*", "*://*.google.ge/*", - "*://*.google.gf/*", "*://*.google.gg/*", "*://*.google.com.gh/*", "*://*.google.com.gi/*", "*://*.google.gl/*", "*://*.google.gm/*", - "*://*.google.gp/*", "*://*.google.gr/*", "*://*.google.com.gt/*", "*://*.google.gy/*", @@ -111,12 +104,11 @@ "*://*.google.ht/*", "*://*.google.hu/*", "*://*.google.co.id/*", - "*://*.google.iq/*", "*://*.google.ie/*", "*://*.google.co.il/*", "*://*.google.im/*", "*://*.google.co.in/*", - "*://*.google.io/*", + "*://*.google.iq/*", "*://*.google.is/*", "*://*.google.it/*", "*://*.google.je/*", @@ -132,7 +124,6 @@ "*://*.google.kz/*", "*://*.google.la/*", "*://*.google.com.lb/*", - "*://*.google.com.lc/*", "*://*.google.li/*", "*://*.google.lk/*", "*://*.google.co.ls/*", @@ -146,8 +137,8 @@ "*://*.google.mg/*", "*://*.google.mk/*", "*://*.google.ml/*", + "*://*.google.com.mm/*", "*://*.google.mn/*", - "*://*.google.ms/*", "*://*.google.com.mt/*", "*://*.google.mu/*", "*://*.google.mv/*", @@ -156,10 +147,9 @@ "*://*.google.com.my/*", "*://*.google.co.mz/*", "*://*.google.com.na/*", - "*://*.google.ne/*", - "*://*.google.com.nf/*", "*://*.google.com.ng/*", "*://*.google.com.ni/*", + "*://*.google.ne/*", "*://*.google.nl/*", "*://*.google.no/*", "*://*.google.com.np/*", @@ -169,6 +159,7 @@ "*://*.google.com.om/*", "*://*.google.com.pa/*", "*://*.google.com.pe/*", + "*://*.google.com.pg/*", "*://*.google.com.ph/*", "*://*.google.com.pk/*", "*://*.google.pl/*", @@ -179,7 +170,6 @@ "*://*.google.com.py/*", "*://*.google.com.qa/*", "*://*.google.ro/*", - "*://*.google.rs/*", "*://*.google.ru/*", "*://*.google.rw/*", "*://*.google.com.sa/*", @@ -192,40 +182,39 @@ "*://*.google.sk/*", "*://*.google.com.sl/*", "*://*.google.sn/*", - "*://*.google.sm/*", "*://*.google.so/*", + "*://*.google.sm/*", + "*://*.google.sr/*", "*://*.google.st/*", "*://*.google.com.sv/*", "*://*.google.td/*", "*://*.google.tg/*", "*://*.google.co.th/*", "*://*.google.com.tj/*", - "*://*.google.tk/*", "*://*.google.tl/*", "*://*.google.tm/*", + "*://*.google.tn/*", "*://*.google.to/*", - "*://*.google.com.tn/*", "*://*.google.com.tr/*", "*://*.google.tt/*", "*://*.google.com.tw/*", "*://*.google.co.tz/*", "*://*.google.com.ua/*", "*://*.google.co.ug/*", - "*://*.google.ae/*", "*://*.google.co.uk/*", - "*://*.google.us/*", "*://*.google.com.uy/*", "*://*.google.co.uz/*", "*://*.google.com.vc/*", "*://*.google.co.ve/*", - "*://*.google.vg/*", "*://*.google.co.vi/*", "*://*.google.com.vn/*", "*://*.google.vu/*", "*://*.google.ws/*", + "*://*.goocatgle.rs/*", "*://*.google.co.za/*", "*://*.google.co.zm/*", - "*://*.google.co.zw/*" + "*://*.google.co.zw/*", + "*://*.google.cat/*" ], "include_globs": [ "*tbm=isch*",