Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update metadata #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions public/content.js
Original file line number Diff line number Diff line change
@@ -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));



}
5 changes: 4 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@


<img src="https://img.icons8.com/bubbles/200/000000/user-male.png"/>
<a ><button id="clickAnalyze" class="dropbtn" >Donate !</button></a>
<h3 id="title" class="txt"></h3>
<p id="organization" class="txt"></p>

<a class="dropbtn"><button id="clickLoad" class="dropbtn" >More Info !</button></a>
<a href="" id = "clickAnalyze" class="dropbtn">Donate !</a>

<script type="text/javascript" src="index.js" charset="utf-8"> </script>

Expand Down
89 changes: 50 additions & 39 deletions public/index.js
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 5 additions & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
"default_icon": "icon128.png",
"default_title": "donate",
"default_popup": "index.html"
}
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["index.js"]
}]
}
15 changes: 13 additions & 2 deletions public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ button {
color:inherit;
border:none;
font: inherit;
padding: 0;
padding: 0;
margin: 0;
cursor: pointer;

}

ul {
Expand All @@ -36,7 +37,7 @@ li a:hover {
margin-left: auto;
margin-right: auto;
border-radius: 25px;
width: 30%;
width: 20%;
}

.btn{
Expand All @@ -47,5 +48,15 @@ li a:hover {
margin-left: auto;
margin-right: auto;
text-align: center;
background-color: #f0efef;

}
.txt{
color: #77a8a8;
text-align: center;
}
.txt:hover{
color: #c2d4dd;
}

button:focus {outline:0;}