Advertisement
zelman

Grease

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