OceanHero Requester

Send repeated requests to OceanHero in a controlled way.

  1. // ==UserScript==
  2. // @name OceanHero Requester
  3. // @namespace http://greasyfork.org/
  4. // @version 1.0
  5. // @description Send repeated requests to OceanHero in a controlled way.
  6. // @author Taeyang
  7. // @match https://oceanhero.today/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // Settings
  16. const targetUrl = "https://oceanhero.today/web?q=test"; // URL to send requests
  17. const requestInterval = 1000; // Time between requests in milliseconds (e.g., 1000ms = 1 second)
  18. const maxThreads = 5; // Number of concurrent requests (equivalent to Python threads)
  19.  
  20. // Counter for the number of requests sent
  21. let totalRequests = 0;
  22.  
  23. // Function to perform the fetch request
  24. async function sendRequest(threadName) {
  25. try {
  26. const response = await fetch(targetUrl, {
  27. method: "GET",
  28. credentials: "include", // Include cookies automatically if logged in
  29. });
  30.  
  31. if (response.ok) {
  32. totalRequests++;
  33. console.log(`<${threadName}> Request #${totalRequests}: Success`);
  34. } else {
  35. console.warn(`<${threadName}> Request failed with status: ${response.status}`);
  36. }
  37. } catch (error) {
  38. console.error(`<${threadName}> Error: ${error}`);
  39. }
  40. }
  41.  
  42. // Function to start threads (concurrent requests)
  43. function startThreads() {
  44. for (let i = 1; i <= maxThreads; i++) {
  45. const threadName = `Thread${i}`;
  46. setInterval(() => sendRequest(threadName), requestInterval); // Repeat requests in each thread
  47. }
  48. }
  49.  
  50. // Start the script
  51. console.log("Starting OceanHero Requester script...");
  52. startThreads();
  53. })();