Sleazy Fork is available in English.

F95 Random Latest Update Choice

Randomly selects a resource(e.g. game,asset,animation) from the 'Latest Update' page. Just press the '?' button in the filter drawer.

Verze ze dne 08. 07. 2024. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name F95 Random Latest Update Choice
  3. // @namespace f95-random-latest-update-choice
  4. // @match https://f95zone.to/sam/latest_alpha/*
  5. // @icon https://external-content.duckduckgo.com/ip3/f95zone.to.ico
  6. // @grant none
  7. // @version 1.0
  8. // @author Edexal
  9. // @license Unlicense
  10. // @description Randomly selects a resource(e.g. game,asset,animation) from the 'Latest Update' page. Just press the '?' button in the filter drawer.
  11. // ==/UserScript==
  12. (() => {
  13. const LATEST_PAGE_QUERY = 'lppos';
  14. let stylesCSS = `
  15. .fa-question {
  16. color: yellow;
  17. background:#641c1c;
  18. font-size: 15px;
  19. }
  20.  
  21. .fa-question:hover{
  22. cursor: pointer;
  23. opacity: 0.7;
  24. }
  25.  
  26. .fa-question::before {
  27. content: "\\3f";
  28. }
  29.  
  30. /*Tooltip for button*/
  31. #filter-random::before {
  32. content: "lucky";
  33. }
  34.  
  35. /*Chosen item*/
  36. #chosen {
  37. box-shadow: #c00 1px 0 10px 8px !important;
  38. }
  39. #chosen > a.resource-tile_link {
  40. color: yellow !important;
  41. text-shadow: #cc0000 1px 0 8px;
  42. }
  43.  
  44. `;
  45.  
  46. //Random number
  47. function getRandIntInc(min, max) {
  48. //Inclusive random number generator
  49. return Math.floor(Math.random() * (max - min + 1) ) + min;
  50. }
  51. //Apply custom styles in a style tag
  52. function applyCSS(css) {
  53. let styleEl = document.querySelector("style");
  54. if (styleEl === null) {
  55. styleEl = document.createElement('style');
  56. }
  57. styleEl.appendChild(document.createTextNode(css));
  58. document.head.appendChild(styleEl);
  59. }
  60.  
  61. //Chooses a random item on the page
  62. function selectAnItem(){
  63. if(!location.search.includes(LATEST_PAGE_QUERY)) {
  64. return;
  65. }
  66. //Change the URL to one w/o 'lppos' query param
  67. let curURL = new URL(location.href);
  68. curURL.searchParams.delete(LATEST_PAGE_QUERY);
  69. history.replaceState({},"",curURL.toString());
  70.  
  71. //Selects a random item on the page
  72. let allItemsEls = document.querySelectorAll(".resource-tile"); // Gets all resource tiles
  73. let randNumChoice = getRandIntInc(1, allItemsEls.length);
  74. let chosenEl = allItemsEls[randNumChoice - 1];
  75. chosenEl.id = "chosen";
  76. chosenEl.scrollIntoView(false);//scroll selected bookmark into view from the bottom of the page
  77. }
  78. //Chooses a random page and goes to it
  79. function goToAPage() {
  80. let maxPageNum = document.querySelector(".sub-nav_info-paging_nums .nav_num:last-child").dataset.page;
  81. let chosenNum = getRandIntInc(1,+maxPageNum);
  82. let curURL = new URL(location.href);//Get the current URL
  83. //Customize URL to add latest page query parameter
  84. curURL.searchParams.set(LATEST_PAGE_QUERY,1);
  85. //Change page to random one
  86. let newURL = curURL.toString().replace(/page=\d+/i,`page=${chosenNum}`);
  87. location.replace(newURL);//Go To randomly chosen bookmark page
  88. }
  89.  
  90. //Creates the random button
  91. function makeRandbtn(){
  92. let randLinkEl = document.createElement("a");
  93. randLinkEl.classList.add("button-icon");
  94. randLinkEl.id = "filter-random";
  95.  
  96. let randIconEl = document.createElement("i");
  97. randIconEl.classList.add("fa-solid", "fa-question");
  98.  
  99. let parentEl = document.querySelector("#filter-controls");
  100. randLinkEl.addEventListener("click",goToAPage);
  101. randLinkEl.append(randIconEl);
  102. parentEl.append(randLinkEl);
  103. }
  104.  
  105. function run(){
  106. applyCSS(stylesCSS);
  107. makeRandbtn();
  108. setTimeout(selectAnItem, 3000); // [VALUE] Wait for elements to load before executing
  109. }
  110.  
  111. run();
  112.  
  113. })();