NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name ShikiRand
// @updateURL https://openuserjs.org/meta/Dedonych/ShikiRand.meta.js
// @downloadURL https://openuserjs.org/install/Dedonych/ShikiRand.user.js
// @namespace http://tampermonkey.net/
// @copyright 2023, Dedonych (https://openuserjs.org/users/Dedonych)
// @version 0.7
// @description Добавляет на шикимори кнопку рандом-аниме/манги/ранобе.
// @author Dedonych
// @match https://*
// @match http://*
// @include /https?:\/\/(www\.)?shiki(mori)?\.([a-z]+?)\/.*/
// @license MIT
// @icon https://www.google.com/s2/favicons?sz=64&domain=shikimori.me
// @require https://gist.githubusercontent.com/Chortowod/814b010c68fc97e5f900df47bf79059c/raw/chtw_settings.js
// ==/UserScript==
const style = `
#random-btn{
cursor:pointer;
margin-left:-25px
}
#random-btn::before {
content: "🎲";
-webkit-filter: grayscale(1);
filter: grayscale(1);
font-size: 24px;
}
`
let settings = new ChtwSettings('randomButton', `<a target='_blank' href='https://openuserjs.org/scripts/Dedonych/ShikiRand/'>Рандомный тайтл`);
function initSettings() {
settings.createOption('minScore', 'Минимальная оценка', 3, 'number');
settings.createOption('nsfw', 'Включить в поиск NSFW');
settings.createOption('blank', 'Открывать в новой вкладке?');
settings.createOption('showText', 'Показывать текст у кнопки?', false);
settings.createOption('myList', "Тип выбора в своем списке", {
"Выберете вариант": null,
"Запланированно":"planned",
"Смотрю": "watching",
"Пересматриваю": "rewatching",
"Просмотренно":"completed",
"Отложенно":"on_hold",
"Брошенно": "dropped",
}, 'select');
settings.createOption("alwaysList","Всегда рандом по списку?",false);
}
function createRandomButton() {
const {origin} = location;
'use strict'
if (document.getElementById("random-btn")) return
let path = location.pathname.match(/\/\w+\/?/g);
const arr = ["animes", "ranobe", "mangas"];
path = (!path || !arr.includes(path[0].replaceAll("/", ""))) ? 'animes' : path[0].replaceAll("/", "");
const menu_logo = document.querySelector(".menu-logo")
const randomBtn = document.createElement("div");
randomBtn.id = "random-btn";
randomBtn.className='menu-icon';
randomBtn.textContent = settings.getOption('showText') ? "random" : null;
randomBtn.onclick = async function () {
var def = `order=random&score=${settings.getOption("minScore")}&censored=${settings.getOption("nsfw") ? false : true}`
if(settings.getOption("myList")!==null){
if(settings.getOption("alwaysList")||(/.+\/list\/(anime|manga|ranobe)/).test(location.pathname)){
def=`order=random&mylist=${settings.getOption("myList")}`
}
}
console.log(def)
try {
const response = await fetch(`${origin}/api/${path}?` + def)
const data = await response.json();
open(`${origin}/${path}/${data[0].id}`, settings.getOption("blank") ? "_blank" : "_self");
}catch(e){
throw Error(e)
}
}
menu_logo.append(randomBtn)
settings.addStyle(style)
}
ready(createRandomButton);
ready(initSettings);