Danbooru

Danbooru (etc...) userscripts

Posted under General

Because of forum #164992, I created the following bookmarklet and userscript which will remove the commentary inputs on the uploads page so that they don't get added. The bookmarklet allows one to remove the commentary inputs when desired, whereas the userscript will always remove the commentary inputs.

Bookmarklet

javascript:$(".upload_commentary_translation_container, .upload_artist_commentary_container").remove();

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         Remove upload commentary
// @version      1.1
// @description  Removes the commentary inputs on the uploads page.
// @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-end
// ==/UserScript==

const interval = setInterval(function() {
    let $commentaries = $(".upload_commentary_translation_container, .upload_artist_commentary_container");
    if ($commentaries.length) {
        clearInterval(interval);
        $commentaries.remove();
    }
}, 100);
Edit:

Updated

BrokenEagle98 said:

Because of forum #164992, I created the following boorkmarklet which will remove the commentary inputs on the uploads page so that they don't get added when undesired.

Bookmarklet

javascript:$(".upload_commentary_translation_container, .upload_artist_commentary_container").remove();

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

How about this is added naturally?

tapnek said:

I think he means having the commentary sections blank on the upload page at all times regardless of whether he uses the bookmarket or not.

Alright, I updated the above forum post to include a userscript which will always remove the commentary inputs.

Requested by DeusExCalamus on Discord, I'm sharing this in case anyone else finds it useful. I've created issue #4561 so that this can be done by the server instead, but until then, the only way to disable them is via a userscript.

Userscript

// ==UserScript==
// @name         Disable User Tooltips
// @version      3.0
// @description  Removes the CSS class that enables tooltips.
// @match        *://*.donmai.us/*
// @exclude      /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant        none
// @run-at       document-end
// ==/UserScript==

const removeTooltipSelector = function (i,entry) {$(entry).removeClass('user dtext-user-id-link dtext-user-mention-link')};
$(Danbooru.UserTooltip.SELECTOR).each(removeTooltipSelector);
$('.hidden-comments-notice a').click((event)=>{
    let $comments_list = $(event.target).closest('.comments-for-post').find('.list-of-comments');
    new MutationObserver(function(mutations,observer) {
        $(Danbooru.UserTooltip.SELECTOR, $comments_list[0]).each(removeTooltipSelector);
        observer.disconnect();
    }).observe($comments_list[0], {
        childList: true,
    });
});
$('.dtext-preview-button').click((event)=>{
    let $link = $(event.target);
    if (($link.attr('value') === 'Preview')) {
        let $dtext_preview = $link.closest('form').find('.dtext-preview');
        new MutationObserver(function(mutations,observer) {
            if (mutations.length && mutations[0].addedNodes.length && mutations[0].addedNodes[0].nodeType === 3) {
                return;
            }
            $(Danbooru.UserTooltip.SELECTOR, $dtext_preview[0]).each(removeTooltipSelector);
            observer.disconnect();
        }).observe($dtext_preview[0], {
            childList: true,
        });
    }
});
Edit:
  • (2020-08-06)
    • Also Disable user # and @ mention links
    • Account user links in Dtext previews

Updated

I find myself needing to do certain Danbooru searches often, enough that it became useful to create a bookmarklet so that the search can be instantly performed anywhere instead of having to navigate to a page first.

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

Wiki
Other names

Useful for searching non-Roman character words, such as Japanese. Needed because often a character/series name is embedded in a comment instead of as a tag.

javascript:query=prompt("Enter the other name to query:");(query!==null?(location.href='https://danbooru.donmai.us/wiki_pages?redirect=true&search[hide_deleted]=true&search%5Bother_names_match%5D=%2A'+encodeURIComponent(query)+'%2A'):false);
Artist URLs
URL

Useful for checking if other artists share the same URL, such as with duplicate artist entries.

javascript:query=prompt("Enter the URL to query:");(query!==null?(location.href='https://danbooru.donmai.us/artist_urls?search%5Burl_matches%5D=%2A'+encodeURIComponent(query)+'%2A'):false);

See also

Because of forum #179302, I created the following userscript which will disable autocomplete for those that wish to.

Userscript

// ==UserScript==
// @name         Disable Autocomplete
// @version      1.0
// @description  Disables autocomplete on pages that have it.
// @match        *://*.donmai.us/*
// @exclude      /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant        none
// @run-at       document-end
// ==/UserScript==

const interval = setInterval(function() {
    let $inputs = $("[data-autocomplete]");
    let autocomplete = $inputs.data('uiAutocomplete');
    if (autocomplete) {
        clearInterval(interval);
        $inputs.autocomplete('disable');
    }
}, 100);

Related to forum #175804 above. Someone also asked me how to make it so that the autocomplete only activates when using a hotkey. The following uses Ctrl+Space. To change that, alter the string "ctrl+space" so that it has the hotkey that you desire.

Userscript

// ==UserScript==
// @name         Hotkey Autocomplete
// @version      1.2
// @description  Enables autocomplete with a hotkey.
// @match        *://*.donmai.us/*
// @exclude      /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant        none
// @run-at       document-end
// ==/UserScript==

const interval = setInterval(function() {
    let $inputs = $("[data-autocomplete]");
    if (!$inputs.data('uiAutocomplete')) {
        return;
    }
    clearInterval(interval);
    $inputs.autocomplete('disable');
    $inputs.on('keydown.hotkey_autocomplete', null, "ctrl+space", (event)=>{
        $(event.currentTarget).autocomplete('enable').autocomplete('search');
    });
    $inputs.on('autocompleteclose', (event,ui)=>{
        $(event.currentTarget).autocomplete('disable');
    });
}, 100);
Edit:
  • (2021-01-24)
    • Fixed an issue where some autocomplete inputs don't have a select function.
    • Changed to a better way of disabling the autocomplete inputs after selection/closing by using the "autocompleteclose" event. <kittey, Dmail>

Updated

BrokenEagle98 said:

The following will make maintaining bookmarks on Danbooru easier, as it removes the trailing search parameters thereby leaving a clean URL to bookmark. Use the Bookmarklet if it's only needed occasionally, or the Userscript if it's to be used all the time. (ref forum #136183)

Bookmarklet

javascript:$.each($(".post-preview a"),(i,entry)=>{entry.href=entry.pathname;});

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

Userscript

// ==UserScript==
// @name           Danbooru Post URLs
// @version        1.1
// @match          *://*.donmai.us/posts?*
// @exclude        /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant          none
// @run-at         document-idle
// @description    Remove trailing search parameters from image links on the post search page.
// ==/UserScript==

$.each($(".post-preview a"), (i,entry)=>{
    entry.href = entry.pathname;
});
Edit:
  • (2019-10-04)
    • Added exclude line for XML/JSON
    • Added version number

Is there a way to expand this script to also automatically remove parents (and possibly pool IDs) from the URLs?

Schnitzelkoenig said:

Is there a way to expand this script to also automatically remove parents (and possibly pool IDs) from the URLs?

It does that already. I just tried it out and verified that it works when searching using the pool: and parent: metatags.

Oh, I understand now. I does it when you search for it, just not when accessing an image from the pool itself or when accessing a parent from the related image directly. Is it possible to enable it for the latter cases, or is that not feasible?

Schnitzelkoenig said:

Oh, I understand now. I does it when you search for it, just not when accessing an image from the pool itself or when accessing a parent from the related image directly. Is it possible to enable it for the latter cases, or is that not feasible?

Ah, I misunderstood your request. I made those changes and updated the forum #136251 to version 2.0 of the script.

(obsolete)

I've developed a simple webextension to make deleted posts visible by default.

Currently, post searches on Danbooru exclude deleted posts by default, unless a status: term is specified. Recontaminant applies the opposite behaviour, so deleted posts will instead be *included* by default.
This is achieved by automatically adding status:any to your search expression whenever no other status: terms are present in the expression.

Read the readme for more details and installation instructions. If you have issues, please report them to me or on the project's issues page.
[/s]

Updated

I've heard some demand for something to prevent page navigation before submitting an upload, which the following should do except for when the upload gets submitted. If it's desired to have it always confirm even on upload submittal, then just remove the last line.

Userscript

// ==UserScript==
// @name         Upload Page Lock
// @version      1.2
// @description  Confirm navigation away from the page (except for upload submit).
// @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-end
// ==/UserScript==

$(window).on('beforeunload.upl', () => "");
$('#form').on('submit.upl', () => {$(window).off('beforeunload.upl');});
Edit:

Updated

EH-like "jump to page" popup when clicking "...".

UserScript
// ==UserScript==
// @name         Jump to page
// @description  Prompt for page number when clicking "..."
// @namespace    https://danbooru.donmai.us/
// @version      0.1
// @match        https://*.donmai.us/*
// @grant        none
// ==/UserScript==

class JumpToPage {
    static onClick(event) {
        const window = event.view;
        const page = window.prompt("Jump to page:");
        if (page && /^[ab]?[1-9]\d*$/.test(page)) {
            const url = new URL(window.location);
            url.searchParams.set("page", page);
            window.location = url;
        }
    }
    static init(document, mobile) {
        const ellipsis = document.querySelector(mobile ? ".paginator-current" : ".paginator-ellipsis");
        if (ellipsis) {
            ellipsis.style.cursor = "pointer";
            ellipsis.addEventListener("click", this.onClick);
        }
    }
}

if (GM || GM_info) {
    JumpToPage.init(document, false);
}
1 2 3 4 5 6 7 8 9