diff --git a/public/content.js b/public/content.js new file mode 100644 index 0000000..d9b96f4 --- /dev/null +++ b/public/content.js @@ -0,0 +1,34 @@ +/*global chrome*/ +alert("content.js running"); + chrome.tabs.executeScript(null, { + code: "document.body.innerText" + }, receiveText); + +function receiveText(resultsArray) { + alert(resultsArray[0]); + let content = resultsArray[0]; + //"wildfire, black, women" + + // send info to api, get a url back. + const api_url = 'https://us-central1-smooth-brains-mask-evaluation.cloudfunctions.net/donationLink'; + fetch(api_url, { + method: 'POST', + body: JSON.stringify({text:content}), + headers:{ + 'Content-Type': 'application/json' + } }) + .then(data => { + alert(data[0]); + return data.json(); + }) + .then(res => { + alert(res[0]); + + document.getElementById('clickAnalyze').href=res[0]; + + }) + .catch(error => console.error('Error:', error)); + + + +} diff --git a/public/index.html b/public/index.html index 971c41c..a46f0f2 100644 --- a/public/index.html +++ b/public/index.html @@ -10,8 +10,11 @@ - +
+ + + Donate ! diff --git a/public/index.js b/public/index.js index f1cf77e..dbf5fa1 100644 --- a/public/index.js +++ b/public/index.js @@ -1,43 +1,54 @@ -/*global chrome*/ -function homeClick() { - chrome.tabs.executeScript(null, { - code: "document.body.innerText" - }, receiveText); -} -function receiveText(resultsArray) { - alert(resultsArray[0]); - let content = resultsArray[0]; - //"wildfire, black, women" - - // send info to api, get a url back. - const api_url = 'https://us-central1-smooth-brains-mask-evaluation.cloudfunctions.net/donationLink'; - fetch(api_url, { - method: 'POST', - body: JSON.stringify({text:content}), - headers:{ - 'Content-Type': 'application/json' - } }) - .then(data => { - alert(data[0]); - return data.json(); - }) - .then(res => { - alert(res[0]); - chrome.tabs.update({ - url: res[0] - }); - }) - .catch(error => console.error('Error:', error)); - - - - - // update - // chrome.tabs.update({ - // url: "https://mail.google.com/mail/u/0/#inbox" - // }); +function content() { + // chrome.tabs.executeScript(null, { file: "content.js" }); + + /*global chrome*/ + chrome.tabs.executeScript(null, { + code: "document.body.innerText" + }, receiveText); + + function receiveText(resultsArray) { + let content = resultsArray[0]; + //"wildfire, black, women" + + // send info to api, get a url back. + const api_url = 'https://us-central1-smooth-brains-mask-evaluation.cloudfunctions.net/donationLink'; + fetch(api_url, { + method: 'POST', + body: JSON.stringify({text:content}), + headers:{ + 'Content-Type': 'application/json' + } }) + .then(data => { + return data.json(); + }) + .then(res => { + let urlcontent = res[0].split('//')[1]; + let arr = urlcontent.split('/'); + document.getElementById('title').innerText = arr[0].split('.')[1] +"."+ arr[0].split('.')[2]; + document.getElementById('organization').innerText = arr[arr.length-1]; + + + document.getElementById('clickAnalyze').addEventListener('click', function(){ + chrome.tabs.update({url: res[0] }); + }); + + + }) + .catch(error => console.error('Error:', error)); + + + + } + + +function newPage(){ + } -document.getElementById('clickAnalyze').addEventListener('click', homeClick); + + + +} +document.getElementById('clickLoad').addEventListener('click', content); diff --git a/public/manifest.json b/public/manifest.json index 6b79ce0..4a00dac 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -11,5 +11,9 @@ "default_icon": "icon128.png", "default_title": "donate", "default_popup": "index.html" - } +}, +"content_scripts": [{ + "matches": ["