timedStudyBooru

lazy random image timer tampermonkey edition

Ekde 2024/01/22. Vidu La ĝisdata versio.

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         timedStudyBooru
// @namespace    http://tampermonkey.net/
// @version      2024-01-22.2
// @description  lazy random image timer tampermonkey edition
// @author       Izuthree
// @match        https://danbooru.donmai.us/posts/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=donmai.us
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

let studyTopic = GM_getValue('studyTopic');
let fullTimer = parseInt(GM_getValue('studyTimer'));
let timeout = parseInt(GM_getValue('studyTimer'));
let enabled = GM_getValue('enabled');
let countdownTimer;
const $ = window.jQuery; //im lazy

$(window).ready(function(){
    //if any undefined assume first run and get/set defaults
    if (enabled==undefined||studyTopic==undefined||fullTimer==undefined){
        studyTopic = 'order:rank'; GM_setValue('studyTopic','order:rank');
        fullTimer = 150; timeout = 150; GM_setValue('studyTimer','150');
        enabled = false; GM_setValue('enabled','false');
    }
    //embed stuff after you fixed for defaults not before dumbass
    embeds();
    $('.studymode').prop('disabled',true);

    //if enabled is true, start immediately
    if (enabled==true) {$('.studymode').prop('disabled',false); countdownTimer = setInterval(countdown, 1000);}

    //study button click handler
    $('.studyButton').click(function(){ enabled = !enabled; setValues();
    if(enabled==true){ countdownTimer = setInterval(countdown, 1000); }
    else{ clearInterval(countdownTimer); timeout = parseInt($('.studyTimer')[0].value); $('.timer').html(fullTimer);}
    });
    //skip button
    $('.skipButton').click(function(){ setValues(); window.location.href = "https://danbooru.donmai.us/posts/random?tags="+studyTopic;});
    $('.showHideStudy').click(function(){enabled=false; setValues(); $('.studymode').prop('disabled',!$('.studymode').prop('disabled'))});

});

//set localstorage variables
function setValues(){
    //reset timeout means you can't pause and resume but I don't care to fix this rn
    timeout = parseInt($('.studyTimer')[0].value);
    studyTopic = $('.studyTopic')[0].value;
    fullTimer = parseInt($('.studyTimer')[0].value);
    GM_setValue('studyTopic',$('.studyTopic')[0].value);
    GM_setValue('studyTimer',$('.studyTimer')[0].value);
    GM_setValue('enabled',enabled);
}

//solely so I can collapse this mess lol
function embeds(){
$('body').append("<div class='studyContainer' style='display:none'><div class='studyButton'>⏯</div><input type='text' class='studyTopic' value='"+studyTopic+"'></input><input type='number' class='studyTimer' value='"+fullTimer+"'></input><div class='skipButton'>⏩</div></div>");
$('body').append("<div class='timer'></div>");
$('body').append("<div class='showHideStudy' style='position:fixed;height:25px;background:#333;color:white;bottom:0px;right:0px;padding:5px;z-index:99;'>Toggle Study Mode</div>");
$('body').append("<style class='studymode'>\
.timer{position:fixed;bottom:40px;left:0;font-size:8vw;padding:10px;height:8vw;line-height:calc(10vw - 20px);color:rgba(255,255,255,1);text-shadow:0px 0px 7px black;z-index:99;}\
.image-container{position:fixed;top:0!important;left:0;width:100vw;height:100vh;background:black;margin:0!important;z-index:98;}\
.image-container>picture{display:flex!important;width:100vw!important;height:calc(100vh - 26px)!important;}\
.image-container>picture>img{max-height:100%;max-width:100%;object-fit:contain!important;margin:auto!important;text-align:center!important;}\
.studyContainer{width:400px;height:24px;position:fixed;bottom:0px;left:0px;z-index:999999999990;display:flex!important;}\
.studyContainer>input{width:180px;box-sizing:border-box;resize:none;}\
.studyButton,.skipButton{height:22px;width:30px;font-size:22px;line-height:22px;cursor:pointer;}\
</style>");
}

//shitty countdown but it does its job enough:tm:
function countdown(){
    if(enabled){
        if(timeout < 1){setValues(); window.location.href = "https://danbooru.donmai.us/posts/random?tags="+studyTopic;}
        else{timeout--; $('.timer').html(timeout);}
    }
}