Skip to content

Commit

Permalink
Keine Verwendung von innerHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
cadeyrn committed Oct 10, 2016
1 parent f72647e commit c94f79a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
Binary file modified dist/[email protected]
Binary file not shown.
4 changes: 0 additions & 4 deletions src/data/css/feed.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
p:last-of-type {
display: none;
}

#feed-items {
margin-top: 0;
padding: 0;
Expand Down
53 changes: 47 additions & 6 deletions src/data/js/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,52 @@ self.port.on('feed-items', (items) => {
let date = new Date(items[i].pubDate);
let dateAsString = date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear();

let el = document.createElement('li');
el.innerHTML = '<small>' + window.global_i18n.feed_published_at + ' ' + dateAsString + '</small><br />' +
'<a href="' + items[i].link + '" target="_blank"><strong>' + items[i].title + '</strong></a><br />' +
items[i].description + '<a href="' + items[i].link + '" class="button" target="_blank">' +
window.global_i18n.feed_read_more + '</a>';
document.getElementById('feed-items').appendChild(el);
// strip html from description
let description = items[i].description.replace(/<(?:.|\n)*?>/gm, '');

// remove last paragraph from soeren-hentzschel.at feed
description = description.replace(/(.*)\s*Der Beitrag.* erschien zuerst auf.*/, '$1');

let docFragment = document.createDocumentFragment();

let li = document.createElement('li');
docFragment.appendChild(li);

let small = document.createElement('small');
li.appendChild(small);
let text1 = document.createTextNode(window.global_i18n.feed_published_at + ' ' + dateAsString);
small.appendChild(text1);

let br1 = document.createElement('br');
li.appendChild(br1);

let a1 = document.createElement('a');
a1.setAttribute('href', items[i].link);
a1.setAttribute('target', '_blank');
li.appendChild(a1);

let strong = document.createElement('strong');
a1.appendChild(strong);
let text2 = document.createTextNode(items[i].title);
strong.appendChild(text2);

let br2 = document.createElement('br');
li.appendChild(br2);

let p = document.createElement('p');
li.appendChild(p);
let text3 = document.createTextNode(description);
p.appendChild(text3);

let a2 = document.createElement('a');
a2.setAttribute('href', items[i].link);
a2.setAttribute('class', 'button');
a2.setAttribute('target', '_blank');
li.appendChild(a2);

let text4 = document.createTextNode(window.global_i18n.feed_read_more);
a2.appendChild(text4);

document.getElementById('feed-items').appendChild(docFragment);
}
});
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "[email protected]",
"title": "New Tab Override (browser.newtab.url replacement)",
"name": "newtaboverride",
"version": "4.0",
"version": "4.0.1",
"description": "This add-on brings back the ability to change the page which is shown when opening a new tab.",
"main": "index.js",
"author": {
Expand Down

0 comments on commit c94f79a

Please sign in to comment.