Utilities

Provides utility functions.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/31227/204776/Utilities.js

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 or Violentmonkey 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!)

/**
 * @author Anthony Pizzimenti
 * @desc Checks whether a parameter exists and is of the desired type.
 * @param {*} param     Paramter to check.
 * @param {string} type Desired type.
 * @returns {boolean}
 * @private
 */
function _paramExist (param, type) {
    return typeof param === type && param !== undefined && param !== null;
}

/**
 * @author Anthony Pizzimenti
 * @desc Creates an absolute URL from the provided path and root.
 * @param {string} root Root URL.
 * @param {string} path Root-relative path.
 * @returns {*}
 */
function absurl (root, path) {
    if (_paramExist(root, "string") && _paramExist(path, "string")) {
        if (root[root.length - 1] === "/") {
            return root + path;
        } else {
            return root + "/" + path;
        }
    }
    return null;
}