tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testlib.js (1500B)


      1 /*
      2 * Utility functions for script scheduler test
      3 */
      4 (function(){ /* namespace hiding local variables like arOrderOfAllEvents from global scope */
      5    window.testlib = {};
      6    window.eventOrder = [];
      7    var arNumberOfScriptsParsedPerEvent=[];
      8    window.log = function (str){
      9        eventOrder.push(str);
     10        arNumberOfScriptsParsedPerEvent.push(document.getElementsByTagName('script').length);
     11    }
     12 
     13    window.testlib.addScript = function(source, attributes, parent, firstInParent,funcPrepare) {
     14        try{
     15            parent = parent||document.body;
     16            var script = document.createElement('script');
     17            if(funcPrepare) {
     18                funcPrepare(script);
     19            }
     20            if(source)script.appendChild( document.createTextNode(source) );
     21            for( var name in attributes){
     22                if(/^on/i.test(name)) {
     23                    script[name] = attributes[name];
     24                } else {
     25                    script.setAttribute(name, attributes[name]);
     26                }
     27            }
     28            if (firstInParent && parent.firstChild) {
     29                parent.insertBefore(script, parent.firstChild);
     30            } else {
     31                parent.appendChild(script);
     32            }
     33        } catch(e) {
     34            log('ERROR when adding script to DOM!');
     35            alert(e);
     36        }
     37        return script;
     38    }
     39 
     40    window.testlib.urlParam = function(relativeURL) {
     41        return location.href.replace( /\d*\.html$/, relativeURL);
     42    }
     43 })();