TAMPERMONKEY
// ==UserScript==
// @name         Max Datum
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Preuzima API podatke u pozadini i prikazuje konvertirani datum unutar tipke. Tipka se resetira na "Dostupno do:" za svaki novi link, te se sakriva na video stranicama.
// @match        https://play.max.com/*
// @grant        GM_xmlhttpRequest
// @connect      default.any-emea.prd.api.max.com
// ==/UserScript==

(function() {
    'use strict';

    function checkForVideoPage() {
        const btnEl = document.getElementById("convertLinkBtn");
        if (window.location.href.includes("/video/watch/")) {
            if (btnEl) btnEl.style.display = "none";
        } else {
            if (btnEl) {
                btnEl.style.display = "block";
                btnEl.innerText = "Dostupno do:";
            }
        }
    }

    // Detekcija promjena URL-a bez intervala
    const wrapHistoryMethod = method => {
        const original = history[method];
        return function() {
            const result = original.apply(this, arguments);
            window.dispatchEvent(new Event("locationchange"));
            return result;
        };
    };
    history.pushState = wrapHistoryMethod("pushState");
    history.replaceState = wrapHistoryMethod("replaceState");
    window.addEventListener("popstate", () => window.dispatchEvent(new Event("locationchange")));
    window.addEventListener("locationchange", checkForVideoPage);
    checkForVideoPage();

    // Kreiramo tipku ako ne postoji
    let btn = document.getElementById("convertLinkBtn");
    if (!btn) {
        btn = document.createElement("button");
        btn.id = "convertLinkBtn";
        btn.innerText = "Dostupno do:";
        btn.style.position = "fixed";
        btn.style.bottom = "20px";
        btn.style.right = "20px";
        btn.style.zIndex = "9999";
        btn.style.padding = "10px";
        btn.style.backgroundColor = "#002BE7";
        btn.style.color = "#fff";
        btn.style.border = "none";
        btn.style.borderRadius = "5px";
        btn.style.cursor = "pointer";
        document.body.appendChild(btn);
    }

    btn.addEventListener("click", () => {
        const currentUrl = window.location.href;
        // Pokušavamo dohvatiti token iz {{ ... }} ili koristimo dio URL-a nakon domene
        let token = (currentUrl.match(/{{\s*([^}]+)\s*}}/) || [])[1] || window.location.pathname.substring(1);
        if (token) {
            const apiUrl = `https://default.any-emea.prd.api.max.com/cms/routes/${token}?include=default&decorators=viewingHistory,isFavorite,contentAction,badges&page[items.size]=10`;
            GM_xmlhttpRequest({
                method: "GET",
                url: apiUrl,
                responseType: "json",
                onload: response => {
                    if (response.status === 200) {
                        const jsonData = response.response;
                        function findDownload(obj) {
                            if (typeof obj !== "object" || obj === null) return null;
                            if (obj.code === "DOWNLOAD" && obj.availability && obj.availability.to) return obj.availability.to;
                            for (const key in obj) {
                                if (obj.hasOwnProperty(key)) {
                                    const found = findDownload(obj[key]);
                                    if (found) return found;
                                }
                            }
                            return null;
                        }
                        const toDate = findDownload(jsonData);
                        if (toDate) {
                            const dateObj = new Date(toDate);
                            const options = { timeZone: 'Europe/Zagreb', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' };
                            const localDate = dateObj.toLocaleString('hr-HR', options);
                            btn.innerText = "Dostupno do: " + localDate;
                        } else {
                            console.error("Nije pronađen objekt s 'code: DOWNLOAD' ili ne postoji availability.to.");
                        }
                    } else {
                        console.error("HTTP greška: " + response.status);
                    }
                },
                onerror: err => console.error("Pogreška prilikom zahtjeva:", err)
            });
        } else {
            alert("Nije moguće pronaći token u URL-u.");
        }
    });
})();
21 views

screenshot-20250318053628

Uploaded 1 year ago

TAMPERMONKEY
// ==UserScript==
// @name Max Datum
// @namespace http://tampermonkey.net/
// @version 2.0
// @description Preuzima API podatke u pozadini i prikazuje konvertirani datum unutar tipke. Tipka se resetira na "Dostupno do:" za svaki novi link, te se sakriva na video stranicama.
// @match https://play.max.com/*
// @grant GM_xmlhttpRequest
// @connect default.any-emea.prd.api.max.com
// ==/UserScript==

(function() {
'use strict';

function checkForVideoPage() {
const btnEl = document.getElementById("convertLinkBtn");
if (window.location.href.includes("/video/watch/")) {
if (btnEl) btnEl.style.display = "none";
} else {
if (btnEl) {
btnEl.style.display = "block";
btnEl.innerText = "Dostupno do:";
}
}
}

// Detekcija promjena URL-a bez intervala
const wrapHistoryMethod = method => {
const original = history[method];
return function() {
const result = original.apply(this, arguments);
window.dispatchEvent(new Event("locationchange"));
return result;
};
};
history.pushState = wrapHistoryMethod("pushState");
history.replaceState = wrapHistoryMethod("replaceState");
window.addEventListener("popstate", () => window.dispatchEvent(new Event("locationchange")));
window.addEventListener("locationchange", checkForVideoPage);
checkForVideoPage();

// Kreiramo tipku ako ne postoji
let btn = document.getElementById("convertLinkBtn");
if (!btn) {
btn = document.createElement("button");
btn.id = "convertLinkBtn";
btn.innerText = "Dostupno do:";
btn.style.position = "fixed";
btn.style.bottom = "20px";
btn.style.right = "20px";
btn.style.zIndex = "9999";
btn.style.padding = "10px";
btn.style.backgroundColor = "#002BE7";
btn.style.color = "#fff";
btn.style.border = "none";
btn.style.borderRadius = "5px";
btn.style.cursor = "pointer";
document.body.appendChild(btn);
}

btn.addEventListener("click", () => {
const currentUrl = window.location.href;
// Pokušavamo dohvatiti token iz {{ ... }} ili koristimo dio URL-a nakon domene
let token = (currentUrl.match(/{{\s*([^}]+)\s*}}/) || [])[1] || window.location.pathname.substring(1);
if (token) {
const apiUrl = `https://default.any-emea.prd.api.max.com/cms/routes/${token}?include=default&decorators=viewingHistory,isFavorite,contentAction,badges&page[items.size]=10`;
GM_xmlhttpRequest({
method: "GET",
url: apiUrl,
responseType: "json",
onload: response => {
if (response.status === 200) {
const jsonData = response.response;
function findDownload(obj) {
if (typeof obj !== "object" || obj === null) return null;
if (obj.code === "DOWNLOAD" && obj.availability && obj.availability.to) return obj.availability.to;
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
const found = findDownload(obj[key]);
if (found) return found;
}
}
return null;
}
const toDate = findDownload(jsonData);
if (toDate) {
const dateObj = new Date(toDate);
const options = { timeZone: 'Europe/Zagreb', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' };
const localDate = dateObj.toLocaleString('hr-HR', options);
btn.innerText = "Dostupno do: " + localDate;
} else {
console.error("Nije pronađen objekt s 'code: DOWNLOAD' ili ne postoji availability.to.");
}
} else {
console.error("HTTP greška: " + response.status);
}
},
onerror: err => console.error("Pogreška prilikom zahtjeva:", err)
});
} else {
alert("Nije moguće pronaći token u URL-u.");
}
});
})();