Skip to content

Commit 0c819ea

Browse files
committed
avoid assigning to innerHTML
mozilla validation script dislike it
1 parent 555f765 commit 0c819ea

File tree

4 files changed

+84
-29
lines changed

4 files changed

+84
-29
lines changed

ext/data/config.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@
2626
tr td:nth-child(4) { text-align:center;}
2727
tr td:nth-child(5) { text-align:center;}
2828
td img { width: 15px; height:15px;}
29+
.backdrop {
30+
position:fixed;
31+
width:100%;
32+
height:100%;
33+
top:0;
34+
left:0;
35+
background:rgba(0,0,0,0.7);
36+
z-index:500;
37+
}
38+
.dialog {
39+
border:2px black inset;
40+
position:fixed;
41+
top:5em;left:5em;
42+
width:50%;
43+
background:white;
44+
padding: 1em;
45+
}
2946
</style>
3047
<body style="margin:0;padding:0;padding-left:1em;">
3148
<img src="icon64.png" style="float:left;height:4em;padding-top:0;padding-right:0.5em">
@@ -35,6 +52,17 @@ <h2>Stored sites:</h2>
3552
<p>(You can drag-drop a .mpsites file here to import it)</p>
3653
<table id="stored_sites" style="padding-left:2em">
3754
<thead><tr><th>sitename<th>(matching)<th>Login<th>count<th>type<th>ver
55+
<template id="stored_sites_row">
56+
<tr>
57+
<td>sitename</td>
58+
<td><input class="domainvalue" type="text" data-old="domain" value="domain"></td>
59+
<td>loginname</td>
60+
<td>count</td>
61+
<td>type</td>
62+
<td>ver</td>
63+
<td><img class="delete" src="delete.png"></td>
64+
</tr>
65+
</template>
3866
<tbody>
3967
</table>
4068
<button class="export_mpsites">export</button>
@@ -45,6 +73,20 @@ <h2>Stored sites:</h2>
4573
your password list can not be imported in apps supporting max revision 2 (notably the
4674
official iOS and osX apps with version 2.1.x and earlier)</p>
4775

76+
<div id="conflict_resolve" class="backdrop" style="display:none">
77+
<div class="dialog">
78+
<h2>Conflicting <span class="sitename"></span> (<small class="domainvalue"></small>)</h2>
79+
<h3>existing</h3>
80+
type: <span class="existing_type"></span>
81+
count: <span class="existing_count"></span>
82+
username: <span class="existing_username"></span>
83+
<h3>importing</h3>
84+
type: <span class="new_type"></span>
85+
count: <span class="new_count"></span>
86+
username: <span class="new_username"></span>
87+
<div style="padding-top:1em"><button id="existing">Keep existing</button> <button id="imported">Replace with imported</button></div>
88+
</div>
89+
</div>
4890

4991
<script src="mpw-utils.js"></script>
5092
<script src="config.js"></script>

ext/data/config.js

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ function passtype_to_str(type) {
5151
}
5252

5353
function stored_sites_table_append(domain, site, type, loginname, count, ver) {
54-
type = passtype_to_str(type);
55-
let tr = document.createElement('tr');
56-
tr.innerHTML = '<td>'+site+'<td><input class="domainvalue" type="text" data-old="'+
57-
domain+'" value="'+domain+'"><td>'+loginname+'<td>'+count+'<td>'+type+'<td>'+ver+
58-
'<td><img class="delete" src="delete.png">';
54+
let tr = document.importNode(document.querySelector('#stored_sites_row').content, true);
55+
let x = tr.querySelector('input.domainvalue');
56+
x.value = domain;
57+
x.setAttribute('data-old', domain);
58+
x = tr.querySelectorAll('td');
59+
x[0].textContent = site;
60+
x[2].textContent = loginname;
61+
x[3].textContent = count;
62+
x[4].textContent = passtype_to_str(type);
63+
x[5].textContent = ver;
5964

6065
document.querySelector('#stored_sites > tbody').appendChild(tr);
6166
}
@@ -153,23 +158,20 @@ function get_sitesearch(sitename) {
153158

154159
function resolveConflict(site) {
155160
return new Promise(function(resolve, reject){
156-
var div = document.createElement('div');
157-
div.style.cssText = "position:fixed;width:100%;height:100%;top:0;left:0;background:rgba(0,0,0,0.7);z-index:500";
158-
div.innerHTML = [
159-
'<div style="border:2px black inset;position:fixed;top:5em;left:5em;width:50%;background:white;padding: 1em"><h2>Conflicting ',
160-
site.sitename,
161-
' (<small>',site.sitesearch,'</small>)',
162-
'</h2><h3>existing</h3>',
163-
'type: ', passtype_to_str(stored_sites[site.sitesearch][site.sitename].type),
164-
' count: ', stored_sites[site.sitesearch][site.sitename].generation,
165-
' username: ', stored_sites[site.sitesearch][site.sitename].username,
166-
'<h3>importing</h3>',
167-
'type: ', passtype_to_str(site.passtype),
168-
' count: ', site.passcnt,
169-
' username: ', site.loginname,
170-
'<div style="padding-top:1em"><button id="existing">Keep existing</button> <button id="imported">Replace with imported</button></div>',
171-
'</div>'].join('');
172-
div.addEventListener('click', function(ev){
161+
let existing = stored_sites[site.sitesearch][site.sitename],
162+
div = document.querySelector('#conflict_resolve');
163+
164+
div.querySelector('.sitename').textContent = site.sitename;
165+
div.querySelector('.domainvalue').textContent = site.sitesearch;
166+
div.querySelector('.existing_type').textContent = passtype_to_str(existing.type);
167+
div.querySelector('.existing_count').textContent = existing.generation;
168+
div.querySelector('.existing_username').textContent = existing.username;
169+
170+
div.querySelector('.new_type').textContent = passtype_to_str(site.passtype);
171+
div.querySelector('.new_count').textContent = site.passcnt;
172+
div.querySelector('.new_username').textContent = site.loginname;
173+
174+
function click_handler(ev) {
173175
switch (ev.target.id) {
174176
case 'existing':
175177
resolve(stored_sites[site.sitesearch][site.sitename]);
@@ -179,11 +181,13 @@ function resolveConflict(site) {
179181
break;
180182
default:
181183
return;
182-
183184
}
184-
div.parentNode.removeChild(div);
185-
});
186-
document.querySelector('body').appendChild(div);
185+
div.removeEventListener('click', click_handler);
186+
div.style.display = 'none';
187+
}
188+
189+
div.addEventListener('click', click_handler);
190+
div.style.display = '';
187191
});
188192
}
189193

ext/data/main_popup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ let ui = {
101101
e = e.appendChild(document.createElement('a'));
102102
e.href = '';
103103
e.id = 'showpass';
104-
e.innerHTML = visible;
104+
e.textContent = visible;
105105
}
106106
},
107107

@@ -174,7 +174,7 @@ function recalculate(hide_after_copy, retry) {
174174
siteconfig.generation,
175175
siteconfig.type);
176176

177-
ui.thepassword(Array(pass.length+1).join('&middot;'), pass);
177+
ui.thepassword(Array(pass.length+1).join("\u00B7"), pass); // &middot;
178178

179179
copy_to_clipboard("text/plain", pass);
180180
update_page_password_input(pass);

ext/test/test-main.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,19 @@ exports["test mpsites upload valid"] = function(assert, async_test_done) {
125125

126126
let DummyDom = scope_import_fake_dom(scope);
127127
let document = scope.document;
128+
document.importNode = function() {
129+
let x = new DummyDom();
130+
x.appendChild(new DummyDom('input.domainvalue')).setAttribute = function(){};
131+
x.querySelectorAll = function() {
132+
return [{},{},{},{},{},{}];
133+
};
134+
return x;
135+
};
128136

129137
document.appendChild(new DummyDom('body'))
130138
.appendChild(new DummyDom('#stored_sites'))
131-
.appendChild(new DummyDom('#stored_sites > tbody'));
139+
.appendChild(new DummyDom('#stored_sites > tbody'))
140+
.appendChild(new DummyDom('#stored_sites_row'));
132141

133142
scope.alert = function(m){ if (/Version mismatch/.test(m)) version_mismatch_received=true; else throw new Error('unexpected alert: '+m);};
134143
scope.confirm = function(m){return true;};

0 commit comments

Comments
 (0)