samlloyd7 / No Top Results - Outlook Office 365

// ==UserScript==
// @name         No Top Results - Outlook Office 365
// @author       samlloyd7
// @version      2.0
// @description  Tampermonkey script that hides "Top Results" from Outlook
// @author       Sam Lloyd
// @match        https://outlook.office.com/*
// @match        https://outlook.office365.com/*
// @namespace    none
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require      https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==
/* global $ */
'use strict';


function validityTestOld() {
    return $( "div[role='heading']:contains('All results')" ).length;
}

function removeTopResultsOld() {

    var numberOfTopResults = 3

    var topResultsHeading = $("div[role='heading']:contains('Top results')")
    if (validityTestOld()) {
        var i;
        for (i = 0; i < numberOfTopResults; i++) {topResultsHeading.next().remove();}
        topResultsHeading.remove();
    } else {
        topResultsHeading.children().first().text('All results');
    }
}

function validityTestNew() {
    return $( "div.alignToMailListPersonaPadding:contains('All results')" ).length;
}


function removeTopResultsNew() {

    var topResultsParent = $("div.alignToMailListPersonaPadding:contains('Top results')").parent()

    if (validityTestNew()) {
        topResultsParent.hide()
        topResultsParent.next().hide()
        topResultsParent.next().next().hide()
        topResultsParent.next().next().next().hide()
    } else {
        topResultsParent.children().first().text('All results');
    }
}

if ($('meta').length < 10) {
    console.log("No Top Results - Using new layout method");
    waitForKeyElements("div.alignToMailListPersonaPadding:contains('Top results')", removeTopResultsNew);
} else {
    console.log("No Top Results - Using old layout method");
    waitForKeyElements("span:contains('Top results')", removeTopResultsOld);
}