Browse Source

code review: avoid using innerHTML

pull/2/head
gorhill 7 years ago
parent
commit
03120f8dd9
No known key found for this signature in database GPG Key ID: 25E1490B761470C2
  1. 11
      src/js/contentscript.js

11
src/js/contentscript.js

@ -504,13 +504,16 @@ var nodeListsAddedHandler = function(nodeLists) {
var renderNoscriptTags = function(response) { var renderNoscriptTags = function(response) {
if ( response !== true ) { return; } if ( response !== true ) { return; }
var parent, span;
var parser = new DOMParser();
var doc, parent, span, meta;
for ( var noscript of noscripts ) { for ( var noscript of noscripts ) {
parent = noscript.parentNode; parent = noscript.parentNode;
if ( parent === null ) { continue; } if ( parent === null ) { continue; }
span = document.createElement('span');
span.innerHTML = noscript.textContent;
doc = parser.parseFromString(
'<span>' + noscript.textContent + '</span>',
'text/html'
);
span = document.adoptNode(doc.querySelector('span'));
span.style.setProperty('display', 'inline', 'important'); span.style.setProperty('display', 'inline', 'important');
parent.replaceChild(span, noscript); parent.replaceChild(span, noscript);
} }

Loading…
Cancel
Save