asterleen / Interpals: Show Image Links

// ==UserScript==
// @name         Interpals: Show Image Links
// @namespace    https://asterleen.com
// @version      0.1
// @description  Allows opening Interpals users' photos in a new tab/window and downloading them
// @author       Asterleen
// @match        https://*interpals.net/app/photo*
// @license      MIT
// @copyright    2020, Asterleen (https://asterleen.com)
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const sOriginalLinkId = "addnl-originalImageLink";


    function addOriginalLink() {
        var
        oImageLink = $('#bigPhotoLnk'), //eslint-disable-line no-undef
            sImageUrl = oImageLink.css('background-image').match(/(https.+)\"/)[1],
            oOriginalLink = $('#' + sOriginalLinkId); //eslint-disable-line no-undef

        if (sImageUrl) {
            if (oOriginalLink.length) {
                oOriginalLink.attr("href", sImageUrl);
            } else {
                $('#photoCont>.photoBox').append('<a id="' + sOriginalLinkId + '" href="' + sImageUrl + '" style="display:block;padding:5px">Original image</a>');//eslint-disable-line no-undef
            }
        }

    }

    var observer = new MutationObserver(addOriginalLink);

    observer.observe(document, {
        childList: true,
        subtree: true,
        attributes: false,
        characterData: false
    });

    addOriginalLink();


})();