BVLA Invoice Links

Fixes BVLA Invoice Links

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        BVLA Invoice Links
// @namespace   BVLA Invoice Links
// @description Fixes BVLA Invoice Links
// @license     MIT
// @author      joeltron
// @version     0.03
// @grant       none
// gettimley
// @include     *://*bvla.*
// @match       *://portal.bvla.com/JobHistory.aspx*
 
// ==/UserScript==

// Fix links
function bvlaFixLinks() {
    // get all elements
    elems=document.getElementsByClassName('InvoiceReportLink');

    // variables
    var reportType = null;
    var invoiceId = null;
     
    // cycle through elements
    for (var i = 0; i < elems.length; i++) {
        // invoice-id
        if(elems.item(i).hasAttribute('invoice-id')) {
            reportType="INVOICERPT";
            invoiceId = elems.item(i).getAttribute('invoice-id');
        }

        // job-id
        if(elems.item(i).hasAttribute('job-id')) {
            reportType="JOBINVOICERPT";
            invoiceId = elems.item(i).getAttribute('job-id');
        }

        // insert link
        elems.item(i).innerHTML = '<a target="_BLANK" href="https://portal.bvla.com/Handlers/ShowReport.ashx?ReportType='+reportType+'&EntityID='+invoiceId+'">💾&nbsp;'+elems.item(i).innerText+'</a>';
     
        // remove click action
        $(elems.item(i)).off()
    }

    // all done
    console.log("bvlaFixLinks complete");
}

// Observe function
var observeDOM = (function(){
  var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;

  return function( obj, callback ){
    if( !obj || obj.nodeType !== 1 ) return; 

    if( MutationObserver ){
      // define a new observer
      var mutationObserver = new MutationObserver(callback)

      // have the observer observe for changes in children
      mutationObserver.observe( obj, { childList:true, subtree:false })
      return mutationObserver
    }
  }
})()

// Observe DOM element:
var listElm = document.getElementById('ContentPlaceHolder1_UpdatePnl');
var currentlyFixing = false; // global
observeDOM( listElm, function(m){ bvlaFixLinks(); } );

// Page loaded
bvlaFixLinks();
//window.document.onload = function(e){ bvlaFixLinks(); };