fix AMO validation errors: innerHTML is forbidden

pull/2/head
gorhill 7 years ago
parent 84aa1fd0e6
commit acf318d83c

@ -64,12 +64,6 @@ vAPI.download = function(details) {
/******************************************************************************/ /******************************************************************************/
vAPI.insertHTML = function(node, html) {
node.innerHTML = html;
};
/******************************************************************************/
vAPI.getURL = chrome.runtime.getURL; vAPI.getURL = chrome.runtime.getURL;
/******************************************************************************/ /******************************************************************************/

@ -21,12 +21,12 @@
/* global vAPI, uDom */ /* global vAPI, uDom */
'use strict';
/******************************************************************************/ /******************************************************************************/
uDom.onLoad(function() { uDom.onLoad(function() {
'use strict';
/******************************************************************************/ /******************************************************************************/
var messager = vAPI.messaging.channel('about.js'); var messager = vAPI.messaging.channel('about.js');
@ -120,13 +120,14 @@ var resetUserData = function() {
(function() { (function() {
var renderStats = function(details) { var renderStats = function(details) {
uDom('#aboutVersion').html(details.version); document.getElementById('aboutVersion').textContent = details.version;
var template = uDom('[data-i18n="aboutStorageUsed"]').text(); var template = uDom('[data-i18n="aboutStorageUsed"]').text();
var storageUsed = '?'; var storageUsed = '?';
if ( typeof details.storageUsed === 'number' ) { if ( typeof details.storageUsed === 'number' ) {
storageUsed = details.storageUsed.toLocaleString(); storageUsed = details.storageUsed.toLocaleString();
} }
uDom('#aboutStorageUsed').html(template.replace('{{storageUsed}}', storageUsed)); document.getElementById('aboutStorageUsed').textContent =
template.replace('{{storageUsed}}', storageUsed);
}; };
messager.send({ what: 'getSomeStats' }, renderStats); messager.send({ what: 'getSomeStats' }, renderStats);
})(); })();

@ -34,7 +34,7 @@ var messager = vAPI.messaging.channel('asset-viewer.js');
/******************************************************************************/ /******************************************************************************/
var onAssetContentReceived = function(details) { var onAssetContentReceived = function(details) {
uDom('#content').html(details && (details.content || '')); document.getElementById('content').textContent = details && (details.content || '');
}; };
/******************************************************************************/ /******************************************************************************/

@ -168,28 +168,31 @@ var onInitialize = function(options) {
fetchCloudData(); fetchCloudData();
var html = [ var xhr = new XMLHttpRequest();
'<button id="cloudPush" type="button" title="cloudPush"></button>', xhr.open('GET', 'cloud-ui.html', true);
'<span data-i18n="cloudNoData"></span>', xhr.overrideMimeType('text/html;charset=utf-8');
'<button id="cloudPull" type="button" title="cloudPull" disabled></button>', xhr.responseType = 'text';
'<span id="cloudCog" class="fa">&#xf013;</span>', xhr.onload = function() {
'<div id="cloudOptions">', this.onload = null;
' <div>', var parser = new DOMParser(),
' <p><label data-i18n="cloudDeviceNamePrompt"></label> <input id="cloudDeviceName" type="text" value="">', parsed = parser.parseFromString(this.responseText, 'text/html'),
' <p><button id="cloudOptionsSubmit" type="button" data-i18n="genericSubmit"></button>', fromParent = parsed.body;
' </div>', while ( fromParent.firstElementChild !== null ) {
'</div>', widget.appendChild(
].join(''); document.adoptNode(fromParent.firstElementChild)
);
vAPI.insertHTML(widget, html); }
vAPI.i18n.render(widget);
widget.classList.remove('hide'); vAPI.i18n.render(widget);
widget.classList.remove('hide');
uDom('#cloudPush').on('click', pushData);
uDom('#cloudPull').on('click', pullData); uDom('#cloudPush').on('click', pushData);
uDom('#cloudCog').on('click', openOptions); uDom('#cloudPull').on('click', pullData);
uDom('#cloudOptions').on('click', closeOptions); uDom('#cloudCog').on('click', openOptions);
uDom('#cloudOptionsSubmit').on('click', submitOptions); uDom('#cloudOptions').on('click', closeOptions);
uDom('#cloudOptionsSubmit').on('click', submitOptions);
};
xhr.send();
}; };
messager.send({ what: 'cloudGetOptions' }, onInitialize); messager.send({ what: 'cloudGetOptions' }, onInitialize);

@ -48,8 +48,6 @@ var directiveSort = function(a, b) {
var processUserRules = function(response) { var processUserRules = function(response) {
var rules, rule, i; var rules, rule, i;
var permanentList = [];
var temporaryList = [];
var allRules = {}; var allRules = {};
var permanentRules = {}; var permanentRules = {};
var temporaryRules = {}; var temporaryRules = {};
@ -71,29 +69,48 @@ var processUserRules = function(response) {
temporaryRules[rule] = allRules[rule] = true; temporaryRules[rule] = allRules[rule] = true;
} }
} }
var permanentList = document.createDocumentFragment(),
temporaryList = document.createDocumentFragment(),
li;
rules = Object.keys(allRules).sort(directiveSort); rules = Object.keys(allRules).sort(directiveSort);
for ( i = 0; i < rules.length; i++ ) { for ( i = 0; i < rules.length; i++ ) {
rule = rules[i]; rule = rules[i];
onLeft = permanentRules.hasOwnProperty(rule); onLeft = permanentRules.hasOwnProperty(rule);
onRight = temporaryRules.hasOwnProperty(rule); onRight = temporaryRules.hasOwnProperty(rule);
if ( onLeft && onRight ) { if ( onLeft && onRight ) {
permanentList.push('<li>', rule); li = document.createElement('li');
temporaryList.push('<li>', rule); li.textContent = rule;
permanentList.appendChild(li);
li = document.createElement('li');
li.textContent = rule;
temporaryList.appendChild(li);
} else if ( onLeft ) { } else if ( onLeft ) {
permanentList.push('<li>', rule); li = document.createElement('li');
temporaryList.push('<li class="notRight toRemove">', rule); li.textContent = rule;
permanentList.appendChild(li);
li = document.createElement('li');
li.textContent = rule;
li.className = 'notRight toRemove';
temporaryList.appendChild(li);
} else if ( onRight ) { } else if ( onRight ) {
permanentList.push('<li>&nbsp;'); li = document.createElement('li');
temporaryList.push('<li class="notLeft">', rule); li.textContent = '\xA0';
permanentList.appendChild(li);
li = document.createElement('li');
li.textContent = rule;
li.className = 'notLeft';
temporaryList.appendChild(li);
} }
} }
// TODO: build incrementally. // TODO: build incrementally.
uDom('#diff > .left > ul > li').remove(); uDom('#diff > .left > ul > li').remove();
uDom('#diff > .left > ul').html(permanentList.join('')); document.querySelector('#diff > .left > ul').appendChild(permanentList);
uDom('#diff > .right > ul > li').remove(); uDom('#diff > .right > ul > li').remove();
uDom('#diff > .right > ul').html(temporaryList.join('')); document.querySelector('#diff > .right > ul').appendChild(temporaryList);
uDom('#diff').toggleClass('dirty', response.temporaryRules !== response.permanentRules); uDom('#diff').toggleClass('dirty', response.temporaryRules !== response.permanentRules);
}; };

Loading…
Cancel
Save