From a0d830deb9a7cac4dd37386def0d29f52c38439d Mon Sep 17 00:00:00 2001 From: Cris Motinha Date: Fri, 7 Jul 2017 22:50:10 -0300 Subject: [PATCH 1/2] Grab all images on the website and apply alt tag --- main.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/main.js b/main.js index b6a1120..401fe85 100644 --- a/main.js +++ b/main.js @@ -1,16 +1,19 @@ const img = document.getElementsByTagName("IMG"); -if (img[0].src) { - const apiUrl = 'https://api.ocr.space/parse/imageurl'; - const apikey = 'helloworld'; - const imgUrl = img[0].src; - const queryString = apiUrl +'?apikey=' + apikey + '&url=' + imgUrl; - const myRequest = new Request(queryString, {method: 'GET'}); +for (let i = 0; i < img.length; i++){ + if (img[i].src) { + const apiUrl = 'https://api.ocr.space/parse/imageurl'; + const apikey = '538df4ddfd88957'; + const imgUrl = img[i].src; + const queryString = apiUrl +'?apikey=' + apikey + '&url=' + imgUrl; + const myRequest = new Request(queryString, {method: 'GET'}); - fetch(myRequest) - .then(function(response) { return response.json(); }) + fetch(myRequest) + .then(function(response) { return response.json(); }) .then(function(data) { const text = data.ParsedResults[0].ParsedText; - img[0].setAttribute('alt', text); - }) -} \ No newline at end of file + img[i].setAttribute('alt', text); + }) + } +} + From 1e7e883aa4844048a632632a284a5664a4857540 Mon Sep 17 00:00:00 2001 From: Cris Motinha Date: Fri, 7 Jul 2017 22:50:35 -0300 Subject: [PATCH 2/2] Change manifest version and delete duplicated tag --- manifest.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/manifest.json b/manifest.json index 8dabe4f..56c554b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,18 +1,15 @@ { - "manifest_version": 1, + "manifest_version": 2, "name": "ocr-extension", "version": "1.0", "description": "Recreates the webpage adding alt tag to images", - "version": "1.0", "permissions": [ "", "contextMenus", "activeTab", - "tabs", - "*://developer.mozilla.org/*", - "about:debugging" + "tabs" ], "content_scripts": [