F95 Random Bookmark Picker

Randomly picks a bookmark from your f95-like bookmark page. Just press the 'Random' button.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

作者のサイトでサポートを受ける。または、このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         F95 Random Bookmark Picker
// @namespace    1330126-edexal
// @license      Unlicense
// @version      1.3.4
// @description  Randomly picks a bookmark from your f95-like bookmark page. Just press the 'Random' button.
// @author       Edexal
// @match        *://f95zone.to/account/bookmarks*
// @icon         https://external-content.duckduckgo.com/ip3/f95zone.to.ico
// @grant        none
// @homepageURL  https://sleazyfork.org/en/scripts/490810-f95-random-bookmark-picker
// @supportURL   https://github.com/Edexaal/scripts/issues
// @require      https://cdn.jsdelivr.net/gh/Edexaal/scripts@20abbf4a49807e7d11a081eb3a8573d0cab83c1f/_lib/utility.js
// ==/UserScript==
(() => {
  'use strict';
  const BOOKMARK_QUERY = 'bmpos';

  //CSS styles
  Edexal.addCSS(`
		#randbtn{
			color:yellow;
			border: 1px solid #343638;
		}
		#randbtn:hover{
			cursor: pointer;
			opacity: 0.7;
		}
		#randbtn:active{
			background-color: #ec5555;
		}
		#chosen{
			color: yellow;
			text-shadow: #cc0000 1px 0 8px;
      display:inherit !important;
		}
    #randContainer{
      margin-top:20px;
      text-align: center;
      height: 50px;
      #randbtn {
        width: 50%;
        height: 100%;
        font-size: 1.25em;
        border-radius: 4px;
      }
    }
	`);

  function getRandIntInc(min, max) {
    //Inclusive random number generator
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }

  function highlightBookmarkChoice() {
    if (!location.search.includes(BOOKMARK_QUERY)) {
      return;
    }
    let newURL = location.href.substring(0,
      location.search.includes('&' + BOOKMARK_QUERY) ? location.href.indexOf('&' + BOOKMARK_QUERY) : location.href.indexOf(BOOKMARK_QUERY));// removes '&bmpos'  or 'bmpos' from URL
    history.replaceState({}, "", newURL); //Change the URL to one w/o 'bmpos' query param

    let bookmarkListEl = Edexal.$("ol.listPlain");

    let randBookmarkPos = getRandIntInc(0, bookmarkListEl.children.length - 1);// Pick a random bookmark position (usually 0-19, total 20)
    let chosenBookmarkEl = bookmarkListEl.children[randBookmarkPos];
    chosenBookmarkEl.id = "chosen";
    chosenBookmarkEl.scrollIntoView(false); //scroll selected bookmark into view from the bottom of the page
  }

  highlightBookmarkChoice();

  let randBtn = Edexal.newEl({
    element: 'button',
    name: "random",
    type: "button",
    id: "randbtn",
    class: ["pageNav-jump", "pageNav-jump--next"],
    text: 'Random'
  });

  //Pick bookmark from a selection of all pages
  function pickRandomBookmark() {
    let pagination = Edexal.$("ul.pageNav-main");//Select pagination
    let lastPageNum = pagination.children[pagination.children.length - 1].children[0].textContent;//Get the last page number of the pagination
    let randPageChoiceNum = getRandIntInc(1, Number(lastPageNum));//Pick a random page number
    let curURL = new URL(location.href);//Get the current URL
    curURL.searchParams.set("page", randPageChoiceNum);//Customize URL to point to the randomly chosen page number

    //Customize URL to add bookmark query parameter
    curURL.searchParams.set("bmpos", '1');

    //Go To randomly chosen bookmark page
    location.replace(curURL.toString());
  }

  //Pick bookmark on the first page (if 1 page is only available)
  function pickRandBookmarkOne() {
    let curURL = new URL(location.href);//Get the current URL
    curURL.searchParams.set("page", '1');//Customize URL to point to the randomly chosen page number

    //Customize URL to add bookmark query parameter
    curURL.searchParams.set("bmpos", '1');

    //Go To randomly chosen bookmark page
    location.replace(curURL.toString());
  }

  //Add button to F95
  let entirePaginationEl = Edexal.$("nav > div.pageNav");
  //Checks if there is only a single page of bookmarks or more
  if (!!entirePaginationEl) {
    // > 1
    let isPageNavVisible = window.getComputedStyle(Edexal.$(".pageNavWrapper--mixed .pageNav")).getPropertyValue("display") === "none";
    if (isPageNavVisible) {
      //Mobile Pagination (w/ arrows)
      let randContainerEl = Edexal.newEl({element: "div", id: "randContainer"});
      randContainerEl.appendChild(randBtn);
      let pageArrowsEl = Edexal.$(".block-outer--after");
      pageArrowsEl.appendChild(randContainerEl);
    } else {
      //Desktop Pagination
      entirePaginationEl.appendChild(randBtn);
    }
    Edexal.on(randBtn,"click",pickRandomBookmark);

  } else {
    // == 1
    Edexal.$("div > div.breadcrumb.p-breadcrumb--bottom").prepend(randBtn);
    Edexal.on(randBtn,"click",pickRandBookmarkOne);
    Edexal.addCSS(`
		#randbtn {
			position:relative;
			left: 50%;
			width:150px;
			height:40px;
			font-size: 16px;
			border: 1pt inset navajowhite;
			box-shadow: 0 1px 5px #988787;
			border-radius: 50px;
		}
		`);
  }

})();