Advertisement
zelman

Tamper

Mar 17th, 2025
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Max Datum
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.0
  5. // @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.
  6. // @match https://play.max.com/*
  7. // @grant GM_xmlhttpRequest
  8. // @connect default.any-emea.prd.api.max.com
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function checkForVideoPage() {
  15. const btnEl = document.getElementById("convertLinkBtn");
  16. if (window.location.href.includes("/video/watch/")) {
  17. if (btnEl) btnEl.style.display = "none";
  18. } else {
  19. if (btnEl) {
  20. btnEl.style.display = "block";
  21. btnEl.innerText = "Dostupno do:";
  22. }
  23. }
  24. }
  25.  
  26. // Detekcija promjena URL-a bez intervala
  27. const wrapHistoryMethod = method => {
  28. const original = history[method];
  29. return function() {
  30. const result = original.apply(this, arguments);
  31. window.dispatchEvent(new Event("locationchange"));
  32. return result;
  33. };
  34. };
  35. history.pushState = wrapHistoryMethod("pushState");
  36. history.replaceState = wrapHistoryMethod("replaceState");
  37. window.addEventListener("popstate", () => window.dispatchEvent(new Event("locationchange")));
  38. window.addEventListener("locationchange", checkForVideoPage);
  39. checkForVideoPage();
  40.  
  41. // Kreiramo tipku ako ne postoji
  42. let btn = document.getElementById("convertLinkBtn");
  43. if (!btn) {
  44. btn = document.createElement("button");
  45. btn.id = "convertLinkBtn";
  46. btn.innerText = "Dostupno do:";
  47. btn.style.position = "fixed";
  48. btn.style.bottom = "20px";
  49. btn.style.right = "20px";
  50. btn.style.zIndex = "9999";
  51. btn.style.padding = "10px";
  52. btn.style.backgroundColor = "#002BE7";
  53. btn.style.color = "#fff";
  54. btn.style.border = "none";
  55. btn.style.borderRadius = "5px";
  56. btn.style.cursor = "pointer";
  57. document.body.appendChild(btn);
  58. }
  59.  
  60. btn.addEventListener("click", () => {
  61. const currentUrl = window.location.href;
  62. // Pokušavamo dohvatiti token iz {{ ... }} ili koristimo dio URL-a nakon domene
  63. let token = (currentUrl.match(/{{\s*([^}]+)\s*}}/) || [])[1] || window.location.pathname.substring(1);
  64. if (token) {
  65. const apiUrl = `https://default.any-emea.prd.api.max.com/cms/routes/${token}?include=default&decorators=viewingHistory,isFavorite,contentAction,badges&page[items.size]=10`;
  66. GM_xmlhttpRequest({
  67. method: "GET",
  68. url: apiUrl,
  69. responseType: "json",
  70. onload: response => {
  71. if (response.status === 200) {
  72. const jsonData = response.response;
  73. function findDownload(obj) {
  74. if (typeof obj !== "object" || obj === null) return null;
  75. if (obj.code === "DOWNLOAD" && obj.availability && obj.availability.to) return obj.availability.to;
  76. for (const key in obj) {
  77. if (obj.hasOwnProperty(key)) {
  78. const found = findDownload(obj[key]);
  79. if (found) return found;
  80. }
  81. }
  82. return null;
  83. }
  84. const toDate = findDownload(jsonData);
  85. if (toDate) {
  86. const dateObj = new Date(toDate);
  87. const options = { timeZone: 'Europe/Zagreb', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' };
  88. const localDate = dateObj.toLocaleString('hr-HR', options);
  89. btn.innerText = "Dostupno do: " + localDate;
  90. } else {
  91. console.error("Nije pronađen objekt s 'code: DOWNLOAD' ili ne postoji availability.to.");
  92. }
  93. } else {
  94. console.error("HTTP greška: " + response.status);
  95. }
  96. },
  97. onerror: err => console.error("Pogreška prilikom zahtjeva:", err)
  98. });
  99. } else {
  100. alert("Nije moguće pronaći token u URL-u.");
  101. }
  102. });
  103. })();
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement