123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <span id="currentRiverStatus"></span>
<span id="RiverLevelsTable">
  <h3>Latest Readings</h3>
<table id="RLTable" class="tablepress">
  <thead>
    <tr>
      <th>Date</th>
      <th>Time</th>
      <th>Reading</th>
    </tr>
  </thead>
  <tbody>
    
  </tbody>
  </table>
</span>
<button><a href="https://flood-warning-information.service.gov.uk/station/8208" target="_BLANK">Viking Recorder Gov Page</a></button>


            
          
!
            
              * {
  font-family: sans-serif;
}

h3 {
  color:#89006b;
}

thead {
  color:white;
  background-color:#89006b;
  th {
    padding:10px;
    }
}

tbody {
  color:#89006b;
  td {
    padding: 5px 10px;
    text-align: right;
  }
  .odd {
   background-color:#e8eaed;
  }
}

button {
  font-size: 1rem;
  text-transform: uppercase;
  font-weight: 500;
  border-radius: 5px;
  border: none;
  padding: .625rem 1rem;
  box-shadow: 0 4px 6px rgba(50,50,93,.11), 0 1px 3px rgba(0,0,0,.08);
  cursor: pointer;
  display: inline-block;
  transition: all .22s;
  background: #89006b;
  color: #fff;
  margin: 2rem 2rem 2rem 0;
  a {
    color: #fff;
    text-decoration:none;
  }
}
button:hover{
  transform: translateY(-2px);
  box-shadow: 0 7px 14px rgba(50,50,93,.1), 0 3px 6px rgba(0,0,0,.08);
  filter: brightness(130%);
}

            
          
!
            
              // Work in progress to pull the river level api used by the environment agency in the UK.

// This has been developed for the www.ycrc.co.uk website

// Uses the jquery json parser

// Function to get json from environment agency and then publish into html

var environmentJSON;
$.getJSON("https://environment.data.gov.uk/flood-monitoring/id/measures/L2406-level-stage-i-15_min-m/readings?_sorted&_limit=500", function(json){
    environmentJSON = json;
  
  // collect current reading
  var currentReading = json["items"][0]["value"];

  // collect previous reading
    var previousReading = json["items"][1]["value"];
  
  // decides whether the river is falling, rising or level
  
  if (currentReading > previousReading) {
    var riverStatus = 'rising';
  } else if (currentReading < previousReading) {
    var riverStatus = 'falling';
  } else {
    var riverStatus = 'static';
  }
  
  // works out where the river is in relation to the steps & also what boats can go out on the river
  
  if (currentReading > 4.17) {
    var riverPosition = 'River is in the boathouse';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 4.00) {
    var riverPosition = 'The river is on the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.87) {
    var riverPosition = 'The river is on the top step';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.77) {
    var riverPosition = 'The river is 1 step from the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.68) {
    var riverPosition = 'The river is 2 steps from the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.52) {
    var riverPosition = 'The river is 3 steps from the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.39) {
    var riverPosition = 'The river is 4 steps from the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.23) {
    var riverPosition = 'The river is 5 steps from the road';
    var crewBoats = 'No boats should be out on the water.';
  } else if (currentReading > 3.07) {
    var riverPosition = 'The river is 6 steps from the road';
    var crewBoats = 'Only senior boats during the day can be out on the water.';
  } else if (currentReading > 2.91) {
    var riverPosition = 'The river is 7 steps from the road';
    var crewBoats = 'Only senior boats during the day can be out on the water.';
  } else if (currentReading > 2.75) {
    var riverPosition = 'The river is 11 steps above the tow-path';
  } else if (currentReading > 2.59) {
var riverPosition = 'The river is 10 steps above the tow-path';
  } else if (currentReading > 2.43) {
    var riverPosition = 'The river is 9 steps above the tow-path';
  } else if (currentReading > 2.27) {
    var riverPosition = 'The river is 8 steps above the tow-path';
  } else if (currentReading > 2.11) {
    var riverPosition = 'The river is 7 steps above the tow-path';
  } else if (currentReading > 1.95) {
    var riverPosition = 'The river is 6 steps above the tow-path';
  } else if (currentReading > 1.79) {
    var riverPosition = 'The river is 5 steps above the tow-path';
  } else if (currentReading > 1.63) {
    var riverPosition = 'The river is 4 steps above the tow-path';
  } else if (currentReading > 1.47) {
    var riverPosition = 'The river is 3 steps above the tow-path';
  } else if (currentReading > 1.31) {
    var riverPosition = 'The river is 2 steps above the tow-path';
  } else if (currentReading > 1.15) {
    var riverPosition = 'The river is 1 step above the tow-path';
  } else if (currentReading > 1.06) {
    var riverPosition = 'The river is level just over the towpath';
  } else if (currentReading > 0.95) {
    var riverPosition = 'The river is level with the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  } else if (currentReading > 0.75) {
    var riverPosition = 'The river is 1 step below the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  } else if (currentReading > 0.60) {
    var riverPosition = 'The river is 2 steps below the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  } else if (currentReading > 0.40) {
    var riverPosition = 'The river is 3 steps below the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  } else if (currentReading > 0.20) {
    var riverPosition = 'The river is 4 steps below the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  } else if (currentReading < 0.21) {
    var riverPosition = 'The river is over 4 steps below the towpath';
    var crewBoats = 'No boat restrictions at this time.';
  }
  
  // populates the html with the currentReading and also riverPosition and riverStatus. depending on if the crewBoats variable is set, this information is also included
 
  if (crewBoats) {
    document.getElementById('currentRiverStatus').innerHTML = '<p>' + 'The latest river level is ' + currentReading + ' m and was taken at  ' + json["items"][0]["dateTime"].substring(11,16) + '. ' + riverPosition + ' and is currently ' + riverStatus + '.' + '</p>' + '<p> Current recommendation: ' + crewBoats + '</p>';
  } else {
      document.getElementById('currentRiverStatus').innerHTML = '<p>' + 'The latest river level is ' + currentReading + ' m and was taken at  ' + json["items"][0]["dateTime"].substring(11,16) + '. ' + riverPosition + ' and is currently ' + riverStatus + '.' + '</p>';
  }
  
  // table with sets of readings. We'll want.....
  // Date(split from dateTime value)  Time(split from dateTime value)  Reading
 
  // gets the table already in the html
  var table = document.getElementById("RLTable").getElementsByTagName('tbody')[0];
  
// sets the number of rows to be added
for (var row = 1; row < 6; row++) {
  var addrow = table.insertRow();
  
  // adds odd and even class to each row
  if (row % 2 == 0) {
    addrow.className = 'row-' + row + ' even';
  } else {
    addrow.className = 'row-' + row + ' odd';
  }
  
  //add three cells required to each row 
  var dateCell = addrow.insertCell(0);
  var timeCell = addrow.insertCell(1);
  var valueCell = addrow.insertCell(2);
  
  //adds the content from the river level API to each cell in the row
  dateCell.innerHTML = json["items"][row - 1]["dateTime"].substring(0,10);
  timeCell.innerHTML = json["items"][row - 1]["dateTime"].substring(11,16);
  valueCell.innerHTML = json["items"][row - 1]["value"] + ' m';
}
  
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console