Al_Caughey / Student photos by cohort

// ==UserScript==
// @name         Student photos by cohort
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  tweaks the student photos page to break alphabetically in to Cohorts A & B
// @author       allan.caughey@ocdsb.ca
// @match        https://staffapps.ocdsb.ca/sid/*Pictures*
// @grant        none
// @require http://code.jquery.com/jquery-3.3.1.min.js
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    var $ = window.jQuery;

    //let cohortExceptions=["Adams, Maya", "O'Brien, Alice", "Wilson, Finn", "Earle, Talia", "Baxter, Sienna"]
    let cohortExceptions=[ "Adams, Maya", "Baxter, Sienna", "Earle, Talia", "Martel, Jayden", "McCallum, Rory", "Newell, Trent", "O'Brien, Alice", "Wilson, Finn" ]

    //break into cohorts
    let found=false
    $('div.divcell').first().before("<h1 class='cohort-break'>Cohort A</h1>")
    $('div.divcell').each(function(a,b){
        if (found) return
        let cn=$(b).find('a')[1]
        if ($(cn).text()<'L'){
            return
        }
        let ba=$('div.divcell')[a]
        $(ba).before("<h1 class='cohort-break cohort-b'>Cohort B</h1>")
        found=true
    })
    $(".cohort-break").css({
        "clear": "both",
        "margin": "12px"
    });
    $(".cohort-b").css({
        //"page-break-before": "always"
    });
    // $('th:contains("Name")').first().text('Cohort A')
    // $('th:contains("Name")').last().text('Cohort B')

    $('div.divcell').each(function(a,b){
        let cn=$(b).find('a')[1], sn=$(cn).text()
        console.log(sn)
        if(cohortExceptions.includes(sn)){
            if(sn<'L'){
                console.log('Append ' + sn + ' to Cohort B')
                $(b).detach().insertAfter($('.cohort-b'))
            }
            else{
                console.log('Append ' + sn + ' to Cohort A')
                $(b).detach().insertBefore($('.cohort-b'))
            }
        }
    })

})();