Emulate sendBeacon on Perplexity.ai

Emulate sendBeacon if beacon.enabled is disabled in Firefox for https://*.perplexity.ai/*

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Emulate sendBeacon on Perplexity.ai
// @namespace    http://tampermonkey.net/
// @author       ohmylock
// @version      1.0
// @description  Emulate sendBeacon if beacon.enabled is disabled in Firefox for https://*.perplexity.ai/*
// @match        https://*.perplexity.ai/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Переопределяем navigator.sendBeacon для сайта, если это нужно
    if (!navigator.sendBeacon) {
        navigator.sendBeacon = function(url, data) {
            try {
                fetch(url, {
                    method: 'POST',
                    body: data,
                    keepalive: true,
                    credentials: 'include', // если нужен куки
                    headers: {
                        // Если данные в формате Blob или FormData, можно не указывать
                        // 'Content-Type': 'application/x-www-form-urlencoded' // при необходимости
                    }
                });
                return true;
            } catch (e) {
                return false;
            }
        };
    }
})();