Danbooru

Danbooru (etc...) userscripts

Posted under General

Here's a greasemonkey/tampermonkey script to fix the pool link...

// ==UserScript==
// @name         FixPoolMenuLink
// @version      1.0
// @description  Replace Pools link in top nav with original link.
// @match        *://*.donmai.us/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    $("menu.main li#nav-pools a").attr('href','/pools')
})();

Based on a recent question (topic #15758), I created the following Javascript to navigate to a random page based upon the current tag search query.

Bookmarklet

javascript:var danb_search=location.search.match(/(?:tags|q)=([^&]+)/);danb_search=(danb_search?danb_search[1].replace(/order%3arandom/i,''):'');window.location="/posts/random?tags="+danb_search;

Just when TISAS (topic #15976) comes along, PISAS seems to break.

Am I alone in thinking PISAS doesn't work with the new Pixiv update or is it just me?

edit: when I say it doesn't work I mean on the actual illustration page itself, sorry. It works for searches and the listing page on the profiles and such.

Updated

DreamFromTheLayer said:

Just when TISAS (forum #15976) comes along, PISAS seems to break.

Am I alone in thinking PISAS doesn't work with the new Pixiv update or is it just me?

edit: when I say it doesn't work I mean on the actual illustration page itself, sorry. It works for searches and the listing page on the profiles and such.

It still works for me on the Pixiv post page. Until/unless it changes for myself, I can't really submit a fix.

BrokenEagle98 said:

It still works for me on the Pixiv post page. Until/unless it changes for myself, I can't really submit a fix.

Yeah, it's one of those ones that don't change for everyone at the same time, I looked it up. Anyway, it seems related to the new multi-post page, you'll know it when it happens (in the next month or so?).

In response to forum #155986. Additionally, it also fixes the situation where the width is limited by the window/screen size, which causes the incorrect image sizes to be shown.

// ==UserScript==
// @name         Original Scale
// @version      1.3
// @description  Shows the actual image dimensions.
// @include      /^https?://\w+\.donmai\.us/uploads/\d+(\?|$)/
// @include      /^https?://\w+\.donmai\.us/uploads/\d+/assets/\d+(\?|$)/
// @exclude      /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant        none
// @run-at       document-idle
// ==/UserScript==

const $image = $("#image");
if ($image.length) {
    let timer = setInterval(()=>{
        if ($image[0].naturalWidth !== 0 && $image[0].naturalHeight !== 0) {
            clearInterval(timer);
            $("#scale").html(`Original: ${$image[0].naturalWidth}x${$image[0].naturalHeight}`);
            $("#scale").attr('id','scale-fix');
        }
    },100);
}
Edit:

Updated

BrokenEagle98 said:

In response to forum #155986. Additionally, it also fixes the situation where the width is limited by the window/screen size, which causes the incorrect image sizes to be shown.

Although the script fixed the proper size shown for Twitter uploads, I can't really say the same for uploads from Pixiv and Seiga, in which the dimensions are shown to be 0x0 unless I refresh the page. As said before, this does not happen with Twitter.

https://files.catbox.moe/zes2ev.png

Is there a userscript (or CSS) that can "keep track" of the tags that are added to posts?. In other words, whenever I enter tags in the box, the autocomplete menu would show an indication that the tag is already entered in the field, which would be helpful to prevent repeating tags.

Example: If I try to add the tag smile when it is already in the tagging box, the smile tag in the autocomplete menu would be highlighted to inform me that the tag is already present.

Something like this would be very beneficial when tagging posts that require a large amount of tags, where it is easy to accidentally repeat tags that have already been entered.

inkuJerr said:

Is there a userscript (or CSS) that can "keep track" of the tags that are added to posts?. In other words, whenever I enter tags in the box, the autocomplete menu would show an indication that the tag is already entered in the field, which would be helpful to prevent repeating tags.

Example: If I try to add the tag smile when it is already in the tagging box, the smile tag in the autocomplete menu would be highlighted to inform me that the tag is already present.

Something like this would be very beneficial when tagging posts that require a large amount of tags, where it is easy to accidentally repeat tags that have already been entered.

I added this capability to IndexedAutocomplete in topic #14701.

BrokenEagle98 said:

I added this capability to IndexedAutocomplete in topic #14701.

It works very well and will be very efficient in tagging work. Thanks very much.

Although when selecting a tag from the autocomplete, the dropdown menu would becomes "stuck" and won't disappear until I start typing again; this does not seem to occur in previous versions of the IndexedAutocomplete.

inkuJerr said:

Although when selecting a tag from the autocomplete, the dropdown menu would becomes "stuck" and won't disappear until I start typing again; this does not seem to occur in previous versions of the IndexedAutocomplete.

Fixed in Version 24.1.

Due to the recent issues with layout changes conflicting with custom CSS, I've created the following bookmarklets/userscript to help a user diagnose whether an issue is being caused by the site itself or by their custom CSS.

Bookmarklets

Turn off custom CSS
javascript:var temp=window.custom_CSS=$('head>link[href^="/users/custom_style.css"]').remove();
Turn on custom CSS
javascript:var temp=window.custom_CSS&&$(document.head).append(window.custom_CSS);

Note: Unfortunately, DText doesn't allow one to create a link out of the above, so the bookmarklets will have to be set manually.

Userscript

// ==UserScript==
// @name         Custom CSS Switch
// @version      1.4
// @description  Add a link to turn on/off custom CSS
// @match        *://*.donmai.us/*
// @exclude      /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @run-at       document-end
// ==/UserScript==

var switch_on = true;

var $custom_css = $('head > link[href^="/users/custom_style.css"]');
$("#page-footer").append(`<span id="custom-css-switch">&nbsp;-&nbsp;<a style="color:red" href="#">Custom CSS Disable</a></span>`);

$("#custom-css-switch a").click((event)=>{
    if (switch_on) {
        $(event.target).css('color','green').text('Custom CSS Enable');
        $custom_css.remove();
        switch_on = false;
    } else {
        $(event.target).css('color','red').text('Custom CSS Disable');
        $(document.head).append($custom_css);
        switch_on = true;
    }
    event.preventDefault();
});

The above userscript adds a link down in the footer where the custom CSS can be toggled on or off.

Edit:
  • (2019-10-04)
    • Added exclude line for XML/JSON
  • (2019-10-17)
    • Fixed issue with bookmarklets on Firefox
  • (2019-10-31)
    • Adjusted language of links
  • (2020-08-05)
    • Fixed language of initial link language

Updated

Since the old file input method is currently broken, I created the following script which should bring it back.

// ==UserScript==
// @name         Upload File Input
// @version      1.0
// @description  Add the file input back to the uploads page.
// @include      /^https?://\w+\.donmai\.us/uploads/new(\?|$)/
// @exclude      /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant        none
// @run-at       document-end
// ==/UserScript==

const timer = setInterval(()=>{
    if ($('#upload_file').length === 0) {
        clearInterval(timer);
        $("#filedropzone").before(`
<div class="input fallback">
    <label for="upload_file">File</label>
    <input size="50" type="file" name="upload[file]" id="upload_file" />
</div>`);
    }
}, 100);
Edit:
  • (2022-02-20)
    • Update include line to be more precise.

Updated

Using this userscript overrides the CSS I use to hide the Commentary part of the upload page, which I don't want shown when I upload. This is the CSS code I'm using for that.

#c-uploads #a-new #form > div:nth-child(9) { display: none; } /* hide commentary section */ 

tapnek said:

Using this userscript overrides the CSS I use to hide the Commentary part of the upload page, which I don't want shown when I upload. This is the CSS code I'm using for that.

#c-uploads #a-new #form > div:nth-child(9) { display: none; } /* hide commentary section */ 

I created issue #4194 to add CSS IDs to the page so that positional selectors like the above don't have to be used.

The following script can be used to easily switch back and forth between safe mode and regular mode (kudos to @fossilnix for the idea).

Bookmarklet

javascript:$.post(`/users/${Danbooru.CurrentUser.data('id')}.json`,{user:{enable_safe_mode:!Danbooru.CurrentUser.data('enable-safe-mode')},_method:"put"});

Note: Unfortunately, DText doesn't allow one to create a link out of the above, so the bookmarklets will have to be set manually.

Userscript

// ==UserScript==
// @name         Safe mode toggle
// @version      1.0
// @description  Add a hotkey to toggle safe mode on and off.
// @match        *://*.donmai.us/*
// @exclude      /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant        none
// ==/UserScript==

Danbooru.Utility.keydown("[", "safe_mode", (event)=>{
    $.post(`/users/${Danbooru.CurrentUser.data('id')}.json`, {
        user: {
            enable_safe_mode: !Danbooru.CurrentUser.data('enable-safe-mode')
        },
        _method: "put"
    }).then(()=>{
       window.location.reload();
    });
});

Usage

To change the hotkey, change the character in the string "[". Modifiers such as Ctrl, Shift, and/or Alt are allowed, e.g. "ctrl+[".

Updated

The following userscript adds an extra option to the Mode menu on the post index that makes it easier to get a posts ID. This can be useful for assigning parent or child IDs for instance.

Userscript

// ==UserScript==
// @name         Copy Post ID
// @version      1.0
// @description  Copy a post's ID when clicking the post preview
// @match        *://*.donmai.us/
// @include      /^https?://\w+\.donmai\.us/posts(\?|$)/
// @exclude      /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant        none
// ==/UserScript==

function PostModeMenu(event) {
    let s = $("#mode-box select").val();
    if (s === "copy-id") {
        let post_id = $(event.target).closest("article").data("id");
        window.prompt("Copy to clipboard: Ctrl+C, Enter", post_id);
        event.preventDefault();
    }
}

$("#mode-box select option[value=tag-script]").after('<option value="copy-id">Copy ID</option>');
$(".post-preview a").on('click.cpi', PostModeMenu);

Usage

Clicking a post preview while this mode is active will pull up a prompt with the post ID already selected, which can be copied using Ctrl+C or the mouse's right-click function. After that, the prompt can be closed by clicking any of the buttons.

1 2 3 4 5 6 7 8 9