0 people like it.

Extract script blocks from html page

This module extracts all the blocks out of an html page's header. This can be useful if you are writing tools to merge all the js for future minifaction, or for otherwise manipulating the files.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
81: 
82: 
83: 
84: 
85: 
86: 
87: 
88: 
89: 
90: 
91: 
92: 
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>

<p id="demo"></p>
<p id="demo1"></p>
<p id="demo2"></p>

<script>
    // Create an object:

    function findDeepestLake(varLake) {
        var LakeName;
        var LakeDepth;

        var len = varLake.length,
            i, j, stop;

        var text="";

        for (i=0; i < len; i++){
            for (j=0; j < len-i-1; j++){
                if (varLake[j].Depth <= varLake[j+1].Depth){
                    LakeName = varLake[j].Name;
                    varLake[j].Name = varLake[j+1].Name;
                    varLake[j+1].Name=LakeName;
                    LakeDepth = varLake[j].Depth;
                    varLake[j].Depth = varLake[j+1].Depth;
                    varLake[j+1].Depth=LakeDepth;

                }
            }
        }

        for (i=0;i< len; i++){
            text += varLake[i].Name + "&nbsp&nbsp&nbsp&nbsp&nbsp" + varLake[i].Depth+ "</br> ";
        }
        document.getElementById("demo").innerHTML = text;
        console.log(text);
        return varLake;
    }

    function printTotalLake(toSortLake) {
        var sortedLake = findDeepestLake(toSortLake)
        var count = ["Zero","One", "Two",            "Three","Four","Five","Six","Seven","Eight","Nine"];
        var len = sortedLake.length;
        document.getElementById("demo1").innerHTML = "There are "+"<i>"+count[len]+"</i> Lakes.";
        return sortedLake;
    }

    function DeepestLake(){
        let Lake = [
            {
                "Name": "Caspian Sea",
                "Depth": 560
            },
            {
                "Name": "Tarn Hows",
                "Depth": 53
            },
            {
                "Name": "Crater Lake",
                "Depth": 324
            },
            {
                "Name": "Lake Tanganyika",
                "Depth": 803
            },
            {
                "Name": "Lake Vostok",
                "Depth": 546
            },
            {
                "Name": "Lake Baikal",
                "Depth": 897
            }

        ]

        sortedLake = printTotalLake(Lake)
        document.getElementById("demo2").innerHTML = "The deepest Lake is "+sortedLake[0].Name+". "+sortedLake[0].Name+" is "
            +(sortedLake[0].Depth*1.8288).toFixed(2)+"m deep";
    }

    DeepestLake()

</script>

</body>
</html>
val id : x:'T -> 'T

More information

Link:http://fssnip.net/iR
Posted:2 months ago
Author:devshorts
Tags: html , parsing