/** * Created by cool.blue on 29-Aug-16. */ var load = (function () { var messageDispatcher, weinre; function toggleElement(context, n) { function arrayicate(x) { var _x = x; if(typeof x === 'object') _x = Object.keys(x).map((p) => {return {name: p, value: x[p]}}); return _x ? Array.isArray(_x) ? _x : [_x] : []; } n.mount = n.mount || function(x) {return x}; n.mounted = n.mounted || function(s) {return s.parentNode.removeChild(s)}; var s, e = n.element; if(s = context.querySelector(n.select)) { return n.mounted(s) } return n.mount(arrayicate(e.structure).reduce(function(ret, p) { return (ret[p.name] = p.value, ret) }, context.createElement(e.type))); } function load(context) { var document = context.document; // toggle weinry instrumentation toggleElement(document, { select: '#bkmk-code', element: { type: 'script', structure: {id: "bkmk-code", src: "http://192.168.1.4:8081/target/target-script-min.js#anonymous"} }, mount: function(node) { if(node) document.body.insertBefore(node, document.getElementById('bkmklt')); node.addEventListener('load', function(){ weinre = window.modjewel.getModule("weinre/common/Weinre").exports; weinre.messageDispatcher.getWebSocket().addEventListener("open", startCog); weinre.wi.InspectorNotify.reset(); // weinre.wi.Inspector.reloadPage(startCog) // startCog(); }) }, mounted: function (s) { s.parentNode.removeChild(s); weinre.wi.InspectorNotify.reset(); window.location.reload(); startCog(); } }); function startCog () { // load font-awesome if necessary toggleElement(top.document, { select: 'head link.fa', element: { type: 'link', structure: { className: 'fa', rel: 'stylesheet', href: "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" } }, mount: function(link) { top.document.head.appendChild(link); }, mounted: function (s) { return s} }); // insert cog if necessary and activate it // toggle state between active and in-active once inserted toggleElement(top.document, { select: 'body>div.column h1 i.bkmklt', element: { type: 'i', structure: {className: 'fa fa-cog fa-spin bkmklt', style: 'color: #efa6a6; margin-left: 10px;'} }, mount: function(cog) { var column = top.document.querySelector('body>div.column'), h1 = column.querySelector('h1'); h1.appendChild(cog); }, mounted: function (s) { s.style = (s.classList.toggle('fa-spin')) ? 'color: #efa6a6; margin-left: 10px;' : 'color: #a6a6a6; margin-left: 10px;' } }) } } return load })();