timedStudyBooru

lazy random image timer tampermonkey edition

Verzia zo dňa 25.01.2024. Pozri najnovšiu verziu.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name         timedStudyBooru
// @namespace    http://tampermonkey.net/
// @version      2024-01-25
// @description  lazy random image timer tampermonkey edition
// @author       Izuthree
// @match        https://danbooru.donmai.us/posts/*
// @match        https://safebooru.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 domain = window.location.hostname;
let studyTopic = GM_getValue('studyTopic');
let fullTimer = parseInt(GM_getValue('studyTimer'));
let timeout = parseInt(GM_getValue('studyTimer'));
let enabled = GM_getValue('enabled');
let toggled = GM_getValue('exerciseVisible');
let countdownTimer;
const $ = window.jQuery; //im lazy

$(window).ready(function(){
    //skip immediately if blacklisted, upgrade needed or removed and the script is active
    if($('.image-container [href="/upgrade').length>0 || $('#blacklist-list>li').length>0){window.location.href = "https://"+domain+"/posts/random?tags="+studyTopic;}
    else if($('#page>p').length>0){
        if($('#page>p').html().indexOf('takedown request.')>-1){
            window.location.href = "https://"+domain+"/posts/random?tags="+studyTopic;
    }}


    else{
    //if any undefined assume first run and get/set defaults
    if (enabled==undefined||studyTopic==undefined||fullTimer==undefined||toggled==undefined){
        studyTopic = 'order:rank'; GM_setValue('studyTopic','order:rank');
        fullTimer = 150; timeout = 150; GM_setValue('studyTimer','150');
        enabled = false; GM_setValue('enabled','false');
        toggled = false; GM_setValue('exerciseVisible','false');
    }
    //embed stuff after you fixed for defaults not before dumbass
    embeds();
    if(!toggled){$('.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(){changeImage() });
    //toggle study mode
    $('.showHideStudy').click(function(){enabled=false; setValues(); $('.studymode').prop('disabled',!$('.studymode').prop('disabled'));toggled = !$('.studymode').prop('disabled'); GM_setValue('exerciseVisible',toggled);});
    }
});

//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);
    GM_setValue('exerciseVisible',toggled);
    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>");
$('html').bind('keypress', function(e) {
    if(e.keyCode==50){
        changeImage();
    }
});
}

function changeImage(){
setValues();
window.location.href = "https://"+domain+"/posts/random?tags="+studyTopic;
}

//shitty countdown but it does its job enough:tm:
function countdown(){
    if(enabled){
        if(timeout < 1){changeImage()}
        else{timeout--; $('.timer').html(timeout);}
    }
}