sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [code] Cleanup After execute_script

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 4 Posters 1.1k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      Jim
      last edited by

      This code cleans-up the cruft left behind when using execute_script. (reference thread)

      Chris' version: (http://forums.sketchucation.com/viewtopic.php?p=274499#p274499)

      
      function corePurge(){
         coll = document.body.childNodes;
         for(a=0; a < coll.length; a += 1){
            if (coll[a].tagName ===   "SCRIPT" && coll[a].id === ""){
               document.body.removeChild(coll[a]); 
                              a -= 1;
            }
         }   
      }
      

      My version:

      function purge_script_tags() {
        var b = document.body;
        var last_node = b.lastChild;
        while(last_node.nodeName === "SCRIPT") {
           b.removeChild(last_node);
           last_node = b.lastChild;
        }
      }
      

      Hi

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        jQuery version:
        $('body script').detach();

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • chrisglasierC Offline
          chrisglasier
          last edited by

          @jim said:

          ...

          My version:

          function purge_script_tags() {
          >   var b = document.body;
          >   var last_node = b.lastChild;
          >   while(last_node.nodeName === "SCRIPT") {
          >      b.removeChild(last_node);
          >      last_node = b.lastChild;
          >   }
          > }
          

          This would remove all last scripts including ones not by execute_script - UHMS

          With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            And in Chris' edition.. if a developer wanted to avoid being cleaned up, he need only set an id attribute on the script object.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement