window.__loadRecipe = function(p) {
    p.recipeOnStart = function(pad) {
        if (!localStorage.getItem('_cs_desktopNotifsEnabled')) {
            var v = {
                __t: (new Date).getTime(),
                __v: true
            };
            localStorage._cs_desktopNotifsEnabled = v;
            localStorage.setItem('_cs_desktopNotifsEnabled', JSON.stringify(v));
            localStorage.setItem('CacheStorageVersion', '3b'); // until we migrate to WKWebView
        }
    };

    p.recipeGetPassiveBadge = function(pad) {
        let count = document.querySelectorAll('._5fx8:not(._569x),._1ht3:not(._569x)').length;
        const messageRequestsElement = document.querySelector('._5nxf');
        if (messageRequestsElement) {
          count += parseInt(messageRequestsElement.innerHTML, 10);
        }
        return count;
        //const title = document.title;
        //if (title.match("^\\((\\d+)\\)") != null) {
        //    return 1
        //} else {
        //    return 0
        //}
    };

    p.recipeOnLoad = function(pad) {
        var filter = Array.prototype.filter,
            result = document.head.querySelectorAll("script"),
            filtered = filter.call(result, function(s) {
                return s.src === "" && s.innerText.startsWith("requireLazy([");
            });

        if (filtered.length === 0) {
            return
        }

        let index = filtered[0].innerText.indexOf('"NAME"')
        let nameText = filtered[0].innerText.substring(index, index + 100)
        let name = nameText.split('"')[3]
        if (name !== undefined) {
            pad._cachedMessengerName = name
        }
    }

    p.recipeGetTitle = function(pad) {
        if (pad._cachedMessengerName === undefined) {
            return ""
        } else {
            return pad._cachedMessengerName
        }
    };

    p.recipeGetPrimaryIcon = function(pad) {
        return "";
    };
}