TGA Update HTML code converter

This takes the stock 'Latest Updates' code and converts each list item to the format below

by timmah

HTML

<!-- TGA Update HTML code converter -->

<ul class="list-variant-a">          <li class="views-row views-row-1 views-row-odd views-row-first">  
          <div class="ds-1col node node-page node-teaser contextual-links-region view-mode-teaser clearfix">

    <div class="contextual-links-wrapper contextual-links-processed"><a class="contextual-links-trigger" href="#">Configure</a><ul class="contextual-links"><li class="node-edit first"><a href="/node/4194/edit?destination=node/3394">New draft</a></li>
<li class="node-delete"><a href="/node/4194/delete?destination=node/3394">Delete</a></li>
<li class="node-clone-"><a href="/node/4194/clone/confirm?destination=node/3394">Clone</a></li>
<li class="node-node-export"><a href="/node/4194/node_export?destination=node/3394">Node export</a></li>
<li class="manage-display last"><a href="/admin/structure/types/manage/page/display/teaser?destination=node/3394">Manage display</a></li>
</ul></div>  
  <div class="field field-name-title field-type-ds field-label-hidden">

  
      <div class="field-item"><h3 class="title"><a href="/australian-public-assessment-reports-prescription-medicines-auspars">Australian Public Assessment Reports for prescription medicines (AusPARs)</a></h3></div>
  
</div>
<div class="field field-name-field-date field-type-datetime field-label-hidden">

  
      <div class="field-item">23 January 2017</div>
  
</div>
<div class="field field-name-body field-type-text-with-summary field-label-hidden">

  
      <div class="field-item">Added Human Papillomavirus 9 valent vaccine (Gardasil 9) and Kaldyeco (Ivacaftor)</div>
  
</div>
</div>

  </li>
          <li class="views-row views-row-2 views-row-even">  
          <div class="ds-1col node node-publication-issue node-teaser contextual-links-region view-mode-teaser clearfix">

    <div class="contextual-links-wrapper contextual-links-processed"><a class="contextual-links-trigger" href="#">Configure</a><ul class="contextual-links"><li class="node-edit...

CSS

.checkthis {
	background-color:pink;
}

JavaScript

/*** TGA Update HTML code converter ***
This takes the stock 'Latest Updates' code and converts each list item to the format below 

<p><a href="URL">Link text</a><br>
	Description</p>

TO USE: Paste in the entire '<ul class="list-variant-a">' into the HTML window above and hit 'Run'

TODO: auto-flag if a news item contains the words 'alert, recall, hazard'
*/

// Create an array to hold the results
var $newItems = [];

$('.views-row').each(function() {

    var $thisItem,
		$this = $(this),
        $title = $this.find('h3.title'),
	// Capture the date. We aren't using it, but to keep it consistent...
        $date = $this.find('div.field-name-field-date > div.field-item'),
		$description = $this.find('div.field-name-body > div.field-item');

    // Strip any Drupal controls
    $this.find('.contextual-links-wrapper').remove();

	// Make the link absolute
	$title.find('a').attr('href', 'https://www.tga.gov.au' + $title.find('a').attr('href'));
		
	// Assemble the result using the captured fields
	$thisItem = '<p>' + $title.html() + '<br>' + $description.text() + '</p>';

	// Push the result into the array
	$newItems.push($thisItem);
});

// Remove the original HTML and replace it with the results
$('.list-variant-a').empty().append($newItems);