Skip to content

Commit

Permalink
fixed the news bug, reduced the size of images
Browse files Browse the repository at this point in the history
  • Loading branch information
codacy20 committed Jul 19, 2018
1 parent f633d75 commit 75b66f6
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 121 deletions.
Binary file modified extension/background/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extension/background/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extension/background/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extension/background/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extension/background/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extension/background/5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extension/background/6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extension/background/7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extension/background/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extension/background/9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion extension/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ <h4 class="mdl-dialog__title">Enter RSS Url</h4>
<script src="thirdParty/moment.js"></script>
<script src="thirdParty/moment-timezone-with-data.js"></script>
<script src="autoComplete.js"></script>
<script src="news.js"></script>
<script src="worldClock.js"></script>
<script src="weather.js"></script>
<script src="snackBar.js"></script>
<script src="localStorage.js"></script>
<script src="quote.js"></script>

<script src="news.js"></script>
<script src="stock.js"></script>
<script src="clock.js"></script>
<script src="keybindings.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Rhino Tab",
"short_name":"Rhino Tab",
"description": "Modular new tab. WorldClock, Weather, Stock and News",
"version": "1.6.3",
"version": "1.6.5",
"incognito": "split",
"chrome_url_overrides": {
"newtab": "index.html"
Expand Down
234 changes: 115 additions & 119 deletions extension/news.js
Original file line number Diff line number Diff line change
@@ -1,121 +1,120 @@
$(document).ready(function () {

var endsJpg = /.*.jpg/
var loaded = false;
var format = /[<>_{}]/;
var endsJpg = /.*.jpg/
var loaded = false;
var format = /[<>_{}]/;

$('#notif').click(function () {
if ($('.mdl-layout__drawer-right').hasClass('active')) {
$('.mdl-layout__drawer-right').removeClass('active');
}
else {
$('.mdl-layout__drawer-right').addClass('active');
}
$('#notif').click(function () {
if ($('.mdl-layout__drawer-right').hasClass('active')) {
$('.mdl-layout__drawer-right').removeClass('active');
}
else {
$('.mdl-layout__drawer-right').addClass('active');
}

if (!loaded) {
var savedSources = GetLocal("news");
if (savedSources !== '') {
displaySavedSource(savedSources);
}
loaded = true;
if (!loaded) {
var savedSources = GetLocal("news");
if (savedSources !== '') {
displaySavedSource(savedSources);
}
});
loaded = true;
}
});

$('.mdl-layout__obfuscator-right').click(function () {
if ($('.mdl-layout__drawer-right').hasClass('active')) {
$('.mdl-layout__drawer-right').removeClass('active');
}
else {
$('.mdl-layout__drawer-right').addClass('active');
}
$('.mdl-layout__obfuscator-right').click(function () {
if ($('.mdl-layout__drawer-right').hasClass('active')) {
$('.mdl-layout__drawer-right').removeClass('active');
}
else {
$('.mdl-layout__drawer-right').addClass('active');
}

});
});

function addDefaultChip(name, url) {
var spanMainChip = $('<a></a>').addClass('mdl-layout__tab');
spanMainChip.text(name);
name = name.replace(/\s/g, '');
spanMainChip.attr('id', name + 'Tab');
spanMainChip.attr('href', '#' + name);
// spanMainChip.append(spanNestedChip);

var view = $('.scrollable');
var addView = $('<section></section>').addClass('mdl-layout__tab-panel');
addView.attr('id', name);
var pageContent = $('<div></div>').addClass('page-content');
pageContent.attr('id', name);
addView.append(pageContent);
view.append(addView);


spanMainChip.click(function () {
var savedSources = GetLocal("news");
if ($.inArray(url, savedSources) === -1) {
getRssFeed(url);
}
});
function addDefaultChip(name, url) {
var spanMainChip = $('<a></a>').addClass('mdl-layout__tab');
spanMainChip.text(name);
name = name.replace(/\s/g, '');
spanMainChip.attr('id', name + 'Tab');
spanMainChip.attr('href', '#' + name);
// spanMainChip.append(spanNestedChip);

var view = $('.scrollable');
var addView = $('<section></section>').addClass('mdl-layout__tab-panel');
addView.attr('id', name);
var pageContent = $('<div></div>').addClass('page-content');
pageContent.attr('id', name);
addView.append(pageContent);
view.append(addView);


spanMainChip.click(function () {
var savedSources = GetLocal("news");
if ($.inArray(url, savedSources) === -1) {
getRssFeed(url);
}
});

$("#drawerChips").append(spanMainChip);
}
$("#drawerChips").append(spanMainChip);
}

function addSource(title) {
var h5SourceTitle = $("<h5></h5>").addClass('titleRss').text(title);
function addSource(title) {
var h5SourceTitle = $("<h5></h5>").addClass('titleRss').text(title);

$('.drawerContent').append(h5SourceTitle);
}
$('.drawerContent').append(h5SourceTitle);
}

function addCard(data, agency) {
function addCard(data, agency) {

agency = agency.replace(/\s/g, '');
agency = agency.replace(/\s/g, '');

var thumbnail = data['thumbnail'];
var title = data['title'];
var thumbnail = data['thumbnail'];
var title = data['title'];

var linkFullArticle = data['link'];
var description = data['description'].substring(0, 100);
var linkFullArticle = data['link'];
var description = data['description'].substring(0, 100);

var divMain = $("<div></div>").addClass('demo-card-square mdl-card mdl-shadow--2dp');
divMain.attr('id', 'newsCards');
var divMain = $("<div></div>").addClass('demo-card-square mdl-card mdl-shadow--2dp');
divMain.attr('id', 'newsCards');

if (endsJpg.test(thumbnail)) {
var divTitle = $("<div></div>").addClass('mdl-card__title mdl-card--expand thumbnailRss').css('background-image', `url(${thumbnail})`);
}
var h6InTitle = $("<h6></h6>").addClass('titleRss').html(title);
if (endsJpg.test(thumbnail)) {
var divTitle = $("<div></div>").addClass('mdl-card__title mdl-card--expand thumbnailRss').css('background-image', `url(${thumbnail})`);
}
var h6InTitle = $("<h6></h6>").addClass('titleRss').html(title);

var divSupportingText = $('<div></div>').addClass('mdl-card__supporting-text').text('No description');
if (!format.test(description)) {
divSupportingText.html(description + '...');
}
divSupportingText.attr('id', 'divSupportingText');
var divSupportingText = $('<div></div>').addClass('mdl-card__supporting-text').text('No description');
if (!format.test(description)) {
divSupportingText.html(description + '...');
}
divSupportingText.attr('id', 'divSupportingText');

var divActions = $('<div></div>').addClass('mdl-card__actions mdl-card--border');
var aInDivActions = $('<a></a>').attr("href", linkFullArticle).attr('target', '_blank').text("Full Article");
var divActions = $('<div></div>').addClass('mdl-card__actions mdl-card--border');
var aInDivActions = $('<a></a>').attr("href", linkFullArticle).attr('target', '_blank').text("Full Article");

divActions.append(aInDivActions);
divActions.append(aInDivActions);

divMain.append(divTitle);
divMain.append(h6InTitle);
divMain.append(divSupportingText);
divMain.append(divActions);
divMain.append(divTitle);
divMain.append(h6InTitle);
divMain.append(divSupportingText);
divMain.append(divActions);

$('#' + agency).append(divMain);
}
$('#' + agency).append(divMain);
}

function getRssFeed(url) {
var apiUrl = `https://api.rss2json.com/v1/api.json?rss_url=${url}&api_key=ynt9f6whgpjnobo2e41gtsrjf9txxjathhradoad&count=7`;
function getRssFeed(url) {
var apiUrl = `https://api.rss2json.com/v1/api.json?rss_url=${url}&api_key=ynt9f6whgpjnobo2e41gtsrjf9txxjathhradoad&count=7`;

var settings = {
"async": true,
"crossDomain": true,
"url": apiUrl,
"method": "GET",
beforeSend: function () {
var settings = {
"async": true,
"crossDomain": true,
"url": apiUrl,
"method": "GET",
beforeSend: function () {

console.log('started');
},
}
console.log('started');
},
}

$.ajax(settings)
$.ajax(settings)
.done(function (response) {
SaveLocal("news", url);
for (i = 0; i < 7; i++) {
Expand All @@ -124,34 +123,31 @@ $(document).ready(function () {
}
});

}
}

function displaySavedSource(sources) {
sources.forEach(element => {
getRssFeed(element);
});
}

$(document).ready(function () {
var dialog = document.querySelector('dialog');
$('#buttonRss').click(function () {
dialog.showModal();
});
function displaySavedSource(sources) {
sources.forEach(element => {
getRssFeed(element);
});
}

$('#buttonRssCancel').click(function () {
dialog.close();
});
var dialog = document.querySelector('dialog');
$('#buttonRss').click(function () {
dialog.showModal();
});

$('#buttonRssOk').click(function () {
var rssUrlText = $('#rssUrl').val();
getRssFeed(rssUrlText);
dialog.close();
});
$('#buttonRssCancel').click(function () {
dialog.close();
});

addDefaultChip("BBC News - Home", "http://feeds.bbci.co.uk/news/rss.xml?edition=uk#");
addDefaultChip("BBC Sport - Football", "http://feeds.bbci.co.uk/sport/football/rss.xml?edition=int#");
addDefaultChip("The Verge - All Posts", "https://www.theverge.com/rss/index.xml");
addDefaultChip("TechCrunch", "http://feeds.feedburner.com/TechCrunch/");
addDefaultChip("Hacker News", "https://news.ycombinator.com/rss");
});
$('#buttonRssOk').click(function () {
var rssUrlText = $('#rssUrl').val();
getRssFeed(rssUrlText);
dialog.close();
});

addDefaultChip("BBC News - Home", "http://feeds.bbci.co.uk/news/rss.xml?edition=uk#");
addDefaultChip("BBC Sport - Football", "http://feeds.bbci.co.uk/sport/football/rss.xml?edition=int#");
addDefaultChip("The Verge - All Posts", "https://www.theverge.com/rss/index.xml");
addDefaultChip("TechCrunch", "http://feeds.feedburner.com/TechCrunch/");
addDefaultChip("Hacker News", "https://news.ycombinator.com/rss");

0 comments on commit 75b66f6

Please sign in to comment.