Guest User

Filmweb - return marking as seen

a guest
Oct 12th, 2025
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.40 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name         filmweb.pl - "Widziałem, brak oceny"
  3. // @description  Przywraca przycisk "Widziałem, brak oceny"
  4. // @version      2025-10-12
  5. // @match        https://www.filmweb.pl/*
  6. // @icon         https://fwcdn.pl/prt/static/images/fw/icons2/fw-favicons.ico
  7. // @grant        none
  8. // ==/UserScript==
  9.  
  10. (async function () {
  11.   "use strict";
  12.   const getCookie = (name) => {
  13.     var match = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)"));
  14.     if (match) {
  15.       return match[2];
  16.     }
  17.     return null;
  18.   };
  19.  
  20.   const waitForElement = (elementProvider) =>
  21.     new Promise((resolve) => {
  22.       if (elementProvider()) {
  23.         return resolve(elementProvider());
  24.       }
  25.       const observer = new MutationObserver((_) => {
  26.         if (elementProvider()) {
  27.           observer.disconnect();
  28.           resolve(elementProvider());
  29.         }
  30.       });
  31.       observer.observe(document.body, {
  32.         childList: true,
  33.         subtree: true,
  34.       });
  35.     });
  36.  
  37.   const ratingPanel = await waitForElement(() =>
  38.     document.querySelector(".ratingPanel")
  39.   );
  40.   const ratingText =
  41.     ratingPanel &&
  42.     (await waitForElement(
  43.       () =>
  44.         document.evaluate(
  45.           "//div[starts-with(text(),'Oceń')]",
  46.           ratingPanel,
  47.           null,
  48.           XPathResult.FIRST_ORDERED_NODE_TYPE
  49.         )?.singleNodeValue
  50.     ));
  51.   const xsrfToken = getCookie("XSRF-TOKEN");
  52.  
  53.   if (ratingText && xsrfToken) {
  54.     ratingText.addEventListener("mouseover", () => {
  55.       ratingText.innerText = "Widziałem, brak oceny";
  56.       ratingText.style = "cursor: pointer;";
  57.     });
  58.     ratingText.addEventListener("mouseout", () => {
  59.       ratingText.innerText = "Oceń";
  60.       ratingText.style = "";
  61.     });
  62.     const handleSeenClick = ratingText.addEventListener("click", async () => {
  63.       ratingText.style = "";
  64.       ratingText.removeEventListener("click", handleSeenClick);
  65.       await fetch("https://www.filmweb.pl/api/v1/vote", {
  66.         headers: {
  67.           "content-type": "application/json",
  68.           "x-xsrf-token": xsrfToken,
  69.         },
  70.         body: JSON.stringify({
  71.           entity: window.globals.page.entity.id,
  72.           rate: 0,
  73.           entityName: window.globals.page.entity.type,
  74.         }),
  75.         method: "POST",
  76.       });
  77.       await new Promise(resolve => setTimeout(resolve, 1000));
  78.       window.location.reload();
  79.     });
  80.   }
  81. })();
  82.  
Advertisement
Add Comment
Please, Sign In to add comment