From 24d6ab01d92d85280b23438080dcd4ce4d7f9c8b Mon Sep 17 00:00:00 2001 From: esyasar Date: Mon, 28 Oct 2019 20:07:27 -0400 Subject: [PATCH 1/4] newslist-hw --- index.html | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ script.js | 63 +++++++++++++++++++++++++++++++++++++++++ style.css | 24 ++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 index.html create mode 100644 script.js create mode 100644 style.css diff --git a/index.html b/index.html new file mode 100644 index 0000000..2404cb4 --- /dev/null +++ b/index.html @@ -0,0 +1,82 @@ + + + + Hello! + + + + + + + +
+
+ + +
+ +
+ +
+
+

+        
+
+ +

NEWS LIST

+
+

+ 1.Article +

+

+

+
+ + +
+

+ 2.Article +

+

+

+
+ + +
+

+ 3.Article +

+

+

+
+ + +
+

+ 4.Article +

+

+

+
+ + +
+

+ 5.Article +

+

+

+
+ + + diff --git a/script.js b/script.js new file mode 100644 index 0000000..4df271c --- /dev/null +++ b/script.js @@ -0,0 +1,63 @@ +let data; +function getData(url, method) { + return new Promise(function(resolve, reject) { + const xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState !== 4) return; + if (xhr.status >= 200 && xhr.status < 300) { + resolve(JSON.parse(xhr.response)); + let data = JSON.parse(this.response) + } else { + reject({ + status: xhr.status, + statusText: xhr.statusText + }); + } + } + + xhr.open(method, url); + xhr.send(); + }); +} + +const url = "https://newsapi.org/v2/everything?q=bitcoin&from=2019-10-13&sortBy=publishedAt&apiKey=0c5aa5107409412a82f137ff8148d6eb" + +getData(url, 'GET').then(function(value) { + console.log('True API', value); + data = value; + for(let i=0; i<5; i++){ + document.getElementsByClassName("art")[i].innerHTML += data.articles[i].author; + document.getElementsByClassName("art")[i].innerHTML += data.articles[i].title; + document.getElementsByClassName("art")[i].innerHTML += data.articles[i].description; + } + +}).catch(function(error) { + console.log('ERROR IS', error); +}) + +let favNews = []; + const addUsername = (ev)=>{ + ev.preventDefault(); //to stop the form submitting + let user = { + username: document.getElementById('userInput').value, + } + //document.write("Hello" + user + "!" + "Welcome to News List.") + favNews.push(user); + document.forms[0].reset(); // to clear the form for the next entries + + console.warn('added' , {favNews} ); + let pre = document.querySelector('#msg pre'); + pre.textContent = '\n' + JSON.stringify(favNews, '\t', 2); + //saving to localStorage + localStorage.setItem('UserLogin', JSON.stringify(favNews) ); + } + document.addEventListener('DOMContentLoaded', ()=>{ + document.getElementById('btn').addEventListener('click', addUsername); + }); + +function addBookmark(){ + var element = document.getElementsByClassName("newsArticle"); + element.classList.add("addedBookmark"); +} + +addBookmark(); \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..ed3d464 --- /dev/null +++ b/style.css @@ -0,0 +1,24 @@ +/* CSS files add styling rules to your content */ + +body { + font-family: helvetica, arial, sans-serif; + margin: 2em; + } + + h1 { + font-style: italic; + color: #373fff; + } + + .bookmark{ + float: right; + } + + .addedBookmark { + width: 100%; + padding: 25px; + background-color: coral; + color: white; + font-size: 20px; + } + \ No newline at end of file From 43405376a5720b659c8a7d24c8659cdcf8cd5828 Mon Sep 17 00:00:00 2001 From: esyasar Date: Mon, 28 Oct 2019 20:11:44 -0400 Subject: [PATCH 2/4] practice with local branch --- index.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.html b/index.html index 2404cb4..48aa515 100644 --- a/index.html +++ b/index.html @@ -78,5 +78,9 @@

+ +

+ 6.Article +

From eeb105dfdc98a621bfe8b6f02f4401f5a7476cd1 Mon Sep 17 00:00:00 2001 From: esyasar Date: Mon, 28 Oct 2019 20:22:43 -0400 Subject: [PATCH 3/4] sampleee --- sample.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 sample.txt diff --git a/sample.txt b/sample.txt new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/sample.txt @@ -0,0 +1 @@ +hello world From c38ba70f8a96da709efe267e809b81e94afdf6e7 Mon Sep 17 00:00:00 2001 From: esyasar <52687177+esyasar@users.noreply.github.com> Date: Mon, 28 Oct 2019 20:49:31 -0400 Subject: [PATCH 4/4] Create created.txt --- created.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 created.txt diff --git a/created.txt b/created.txt new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/created.txt @@ -0,0 +1 @@ +hello world