window.addEventListener('load', function() { var chk = document.getElementsByClassName('check'), len = chk.length; for (var i = 0; i < len; i++) { var c = chk[i]; c.id = i; appendTag(c); if (c.checked) enableAutoReload(c); c.onclick = function(e) { enableAutoReload(null, e); }; } }); function appendTag(c) { var v = c.parentNode.getElementsByTagName('input')[1].value; if (v === '') return; var cid = 'container' + c.id, d = document.getElementById(cid); if (d === null) { d = document.createElement('div'); d.id = cid; document.body.appendChild(d); } d.innerHTML = v; var f = d.firstChild, tgn = f.tagName; if (! (tgn === 'IFRAME' || tgn === 'IMG' || tgn === 'OBJECT')) { d.parentNode.removeChild(d); } } function enableAutoReload(c, e) { var t = c || e.target, i = t.id, d = document.getElementById('container' + i), sid = 'script' + i, s = document.getElementById(sid); appendTag(t); if (d === null) return; if (t.checked && s === null) { var f = d.firstChild, s = document.createElement('script'); s.id = sid; s.src = f.src || f.data; document.body.appendChild(s); } else if (!t.checked && s !== null) { s.parentNode.removeChild(s); } }