Booker Gray Optimizations

Various UI fixes for Booker Gray website

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 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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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

// ==UserScript==
// @name         Booker Gray Optimizations
// @namespace    http://tampermonkey.net/
// @version      2024-03-19
// @description  Various UI fixes for Booker Gray website
// @author       m435tr0d
// @match        https://www.bookergray.com/*/*/?page=*
// @match        https://www.bookergray.com/*/*/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bookergray.com
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Remove the darkness from "on vacation" escorts on the actual ad pages.
    document.getElementById("bo_v").firstElementChild.getElementsByTagName('section')[0].firstElementChild.firstElementChild.classList.remove("blackfilter");

    // Change the thumbnails to lightbox the original version of the image and make the linked image as large as possible.
    let $head = document.querySelector('head');
    let $link = document.createElement('link');
    $link.rel = 'stylesheet';
    $link.href = '//cdn.jsdelivr.net/npm/glightbox/dist/css/glightbox.min.css';
    let $script = document.createElement('script');
    $script.type = 'text/javascript';
    $head.append($link);
    $head.append($script);

    $script.onload = () => {
        let dimension_pattern = /(thumb-)(.*)_(\d{2,4})x(\d{2,4})/i;
        let i = 0;

        document.querySelectorAll('#bo_v .images img').forEach(($img) => {
            var dimensions = $img.src.match(dimension_pattern);
            var is_thumb = (dimensions[1] === 'thumb-');

            // If we don't have dimensions then this may not be a proper thumbnail and we fallback to the width/height of the image.
            var width = (is_thumb) ? dimensions[3] : $img.width;
            var height = (is_thumb) ? dimensions[4] : $img.height;
            var width_scape = (width < height) ? 'auto' : '100vw';
            var height_scape = (width > height) ? 'auto' : '100vh';
            //console.log(i + ': ' + width + 'x' + height + ' : ' + width_scape + 'x' + height_scape);
            //i++;

            var a = document.createElement('a');
            if (is_thumb) {
                a.setAttribute('href', $img.src.replace(dimension_pattern, "$2"));
            }
            else { // Fallback to just the src of the img if the image dispayed is not a thumbnail.
                a.setAttribute('href', $img.src);
            }
            a.setAttribute('class', 'glightbox');
            a.setAttribute('data-height', height_scape);
            a.setAttribute('data-width', width_scape);
            $img.parentNode.insertBefore(a, $img);
            a.appendChild($img);
        })

        // init lightbox
        let lightbox = GLightbox({loop: true})
    }
    $script.src = '//cdn.jsdelivr.net/gh/mcstudios/glightbox/dist/js/glightbox.min.js'
})();