Danbooru

Danbooru (etc...) userscripts

Posted under General

No longer works!

With the change to the new shortened artist URLs, the following can be used to bring back the full length URLs. Use the Bookmarklet if it's only needed occasionally, or the Userscript if it's to be used all the time. (ref forum #136217)

Bookmarklet

javascript:$.each($("#artist-related-tags-column a[target=_blank]"),(i,entry)=>{entry.innerHTML=entry.href;});

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

Runs once
// ==UserScript==
// @name           Danbooru Artist URLs
// @version        1.3
// @match          *://*.donmai.us/posts/*
// @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
// @description    Show old-style full length artist URLs.
// ==/UserScript==

var artistinterval = setInterval(()=>{
    if ($("#artist-related-tags-column").length === 0) {
        return;
    }
    $.each($("#artist-related-tags-column a[target=_blank]"), (i,entry)=>{
        entry.innerHTML=entry.href;
    });
    clearInterval(artistinterval);
},1000);
Runs continuously
// ==UserScript==
// @name           Danbooru Artist URLs
// @version        1.3
// @match          *://*.donmai.us/posts/*
// @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
// @description    Show old-style full length artist URLs.
// ==/UserScript==

setInterval(()=>{
    if ($("#artist-related-tags-column").length === 0) {
        return;
    }
    $.each($("#artist-related-tags-column a[target=_blank]"), (i,entry)=>{
        entry.innerHTML=entry.href;
    });
},1000);

The interval timer is needed since the artist URLs are only loaded after the edit tab is opened.

Edit:

Updated

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:$(".post-preview a").each((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        2.0
// @match          *://*.donmai.us/*
// @exclude        /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant          none
// @run-at         document-end
// @description    Remove trailing search parameters from image links on the post search page.
// ==/UserScript==

$(".post-preview a").each((i,entry)=>{
    entry.href = entry.pathname;
});
Edit:
  • (2019-10-04)
    • Added exclude line for XML/JSON
    • Added version number
  • (2021-01-25)
    • Made the script active on the entire site
    • Changed the run time
    • Used the instance variation of each

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)

Awesome, thank you so much. I successfully implemented the Danbooru Post URLs user script in Greasemonkey and it's working just fine - being on all the time works for me, since I make heavy use of "bookmark all tabs"

Updated

The following is for those that want or miss the huge textarea that post flag reasons used to have.

Bookmarklet

javascript:$.each($("#post_flag_reason"),(i,entry)=>{entry.outerHTML = `<textarea id="post_flag_reason" class="text optional" rows="20" name="post_flag[reason]" cols="30"></textarea>`});

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 Flags
// @version        1.1
// @match          *://*.donmai.us/posts/*
// @exclude        /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant          none
// @run-at         document-idle
// @description    Switch post flags to use the larger-sized textarea.
// ==/UserScript==

$.each($("#post_flag_reason"),(i,entry)=>{
    entry.outerHTML = `<textarea id="post_flag_reason" class="text optional" rows="20" name="post_flag[reason]" cols="30"></textarea>`
});
Edit:
  • (2019-10-04)
    • Added exclude line for XML/JSON
    • Added version number

Updated

Chinatsu and nonamethanks asked me to make a script for approvers that would automatically upvote approvals and downvote bad quality and breaks rules disapproval reasons. I'm sharing it here in case anyone else finds it useful.

Userscript

// ==UserScript==
// @name         Moderator Voting
// @version      1.1
// @match        *://*.donmai.us/moderator/post/queue*
// @match        *://*.donmai.us/posts/*
// @exclude      /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant        none
// @run-at       document-idle
// @description  Automatically votes on approvals and certain disapprovals
// ==/UserScript==

var $modqueue = $(".mod-queue-preview");
$.each($modqueue, (i,entry)=> {
    var postid = $(entry).data('id');
    $('.approve-link',entry).click((e)=>{Danbooru.Post.vote('up',postid)});
    $('[href*=breaks_rules],[href*=poor_quality]',entry).click((e)=>{Danbooru.Post.vote('down',postid)});
});

var $modpage = $(".quick-mod");
$.each($modpage, (i,entry)=> {
    var postid = Danbooru.meta('post-id');
    $('#quick-mod-approve',entry).click((e)=>{Danbooru.Post.vote('up',postid)});
    $('[href*=breaks_rules],[href*=poor_quality]',entry).click((e)=>{Danbooru.Post.vote('down',postid)});
});
Edit:
  • (2019-10-04)
    • Added exclude line for XML/JSON
    • Added version number

Updated

A little bookmarklet for quick switching between servers:

Bookmarklet

javascript:(function(){if(window.location.toString().indexOf("donmai")<0) {window.location.assign("http://danbooru.donmai.us/");} else if (window.location.toString().indexOf("danbooru")>0) {window.location=window.location.toString().replace(/^http:\/\/danbooru\./,'http://hijiribe.');} else if (window.location.toString().indexOf("hijiribe")>0) {window.location=window.location.toString().replace(/^http:\/\/hijiribe\./,'http://sonohara.');} else {window.location=window.location.toString().replace(/^http:\/\/sonohara\./,'http://danbooru.');}})();

I made a little script to hide the Curated pool navigation, and hide the entire pool navigation box if Curated is the only pool. Tested with both Chrome/Tampermonkey and Firefox/Violentmonkey.

EDIT: The previous version would hide the pools section if Curated was the only Collection type pool, but didn't check for Series pools or favgroups. This is now fixed.

// ==UserScript==
// @name			Danbooru - hide Curated pool, hide pool section if only pool is Curated (JS only)
// @match        *://*.donmai.us/posts/*
// @grant			none
// @run-at          document-idle
// @description  Hide Curated pool navigation, hide pool section (box) if Curated is the only pool
// ==/UserScript==

(function(){
'use strict';
    if (document.getElementById('nav-link-for-pool-12514')) {
        var curatedPool = document.getElementById('nav-link-for-pool-12514');
        curatedPool.style.display = 'none';
        var favgroupNavExists = document.getElementById("favgroup-nav");
        if ( (document.querySelectorAll('#pool-nav .pool-category-collection').length == 1) && (document.querySelectorAll('#pool-nav .pool-category-series').length == 0) && (!favgroupNavExists) ) {
            var navLinks = document.getElementById('nav-links');
            navLinks.style.display = 'none';
        }
    }
})();

Below is an alternate version that pairs with CSS that goes in Settings -> Advanced -> Custom CSS Style. This has the advantage of instantly hiding the Curated pool navigation, which is particularly nice when the post is in at least one other pool (Curated doesn't show up and then get hidden); if Curated is the only pool, a blank pool navigation box will show up briefly before being hidden.

CSS:

/* Hide Curated pool */
#nav-link-for-pool-12514{ display:none; }

Script:

// ==UserScript==
// @name			Danbooru - hide pool section if only pool is Curated (pair with CSS)
// @match        *://*.donmai.us/posts/*
// @grant			none
// @run-at          document-idle
// @description  Hide Pool section (box) if Curated is the only pool
// ==/UserScript==

(function(){
'use strict';
    var favgroupNavExists = document.getElementById("favgroup-nav");
    if ((document.getElementById('nav-link-for-pool-12514')) && (document.querySelectorAll('#pool-nav .pool-category-collection').length == 1) && (document.querySelectorAll('#pool-nav .pool-category-series').length == 0) && (!favgroupNavExists) ) {
        var navLinks = document.getElementById('nav-links');
        navLinks.style.display = 'none';
    }
})();

Updated

Developed the following in response to the ongoing issues from topic #9127.

The following rewrites all image URLs to use the source domain you're on instead of danbooru.donmai.us, which should work for those having issues getting that domain to work.

// ==UserScript==
// @name         RewriteDomainImages
// @version      1.4
// @description  Corrects images to point to own domain
// @match        *://*.donmai.us/*
// @exclude      /^https?://\w+\.donmai\.us/.*\.(xml|json|atom)(\?|$)/
// @grant        none
// @run-at       document-end
// ==/UserScript==

const site_origin = new URL(window.location).origin;

$.each($("img"),(i,entry)=>{
    var pathurl = new URL(entry.src);
    if (pathurl.origin === 'https://danbooru.donmai.us') {
        entry.src = site_origin + pathurl.pathname;
    }
});

$.each($("#image-resize-link,#post-options [download]"),(i,entry)=>{
    var pathurl = new URL(entry.href);
    if (pathurl.origin === 'https://danbooru.donmai.us') {
        entry.href = site_origin + pathurl.pathname;
    }
});
Edit:
  • (2018-04-06)
    • Fixed issue when image URL was from Raikou1 or Raikou2
    • Fixed full-size and download links
    • Fixed preview images in moderation queue
    • Fixed for all <img> HTML entries
  • (2019-10-04)
    • Added exclude line for XML/JSON

Updated

BrokenEagle98 said:

Developed the following in response to the ongoing issues from topic #9127.

You have my thanks BrokenEagle98!

This script partially fix the problem for me, so I still hope that issue #3603 will be fixed soon.
I can see posts now, but if I click "view original" button, it will gone. Same with download button.
If the image originally fits the window it will display properly.
Also no thumbnails in mod queue.

OniTea said:

You have my thanks BrokenEagle98!

This script partially fix the problem for me, so I still hope that issue #3603 will be fixed soon.
I can see posts now, but if I click "view original" button, it will gone. Same with download button.
If the image originally fits the window it will display properly.
Also no thumbnails in mod queue.

@OniTea I believe I fixed those issues in Version 1.2 I just posted above (forum #144867). The size link still doesn't work, but that one becomes difficult to address without relying on element positions, which I typically don't like to do since it's fragile. If you still need it, you can replace the portion between the quotation marks...

"#image-resize-link,#post-options [download]"

...with...

"#image-resize-link,#post-options [download],#post-information li:nth-child(4) a"

Fiveflower said:

Thank you for the fix. The only minor problem, preview images in Comments section still were not loading for me, but adding #c-comments img seems to solve this.

A great point out. Though after I read that, I had an epiphany, in that all <img> links on Danbooru could be given the same treatment. That doesn't work so well on the second section though and <a> links, but oh well... :sigh:

Regardless, updated forum #144867 to Version 1.3.

On-Demand Fancy Tooltips

I like the new fancy tooltips, but not all the time. With the default delay, they pop up way too quickly for my tastes; with a longer delay, I have to wait if I want to see them. This GreaseMonkey script makes the fancy tooltips pop up when right-clicking a thumbnail.

  • A simple right click loads the fancy tooltip. Shift + right click opens the usual context menu instead (tested in Firefox).
  • Disable post tooltips must be set to Yes in your account settings or they will pop up all over the place.
  • The browser’s standard tooltip will be disabled as well. (Remove line 24 if you want it.)
  • If you use TamperMonkey, you probably have to remove every unsafeWindow. from the script.
// ==UserScript==
// @name           On-Demand Tooltips
// @description    Show fancy tooltips when right-clicking a thumbnail.
// @match          *://*.donmai.us/*
// @grant          none
// @run-at         document-idle
// ==/UserScript==

function showQtip(event) {
  event.preventDefault();
  var t = event.currentTarget;
  unsafeWindow.$(t).qtip("enable");
  unsafeWindow.$(t).qtip(unsafeWindow.Danbooru.PostTooltip.QTIP_OPTIONS, event);
}

if (unsafeWindow.Danbooru && unsafeWindow.Danbooru.PostTooltip) {
  unsafeWindow.Danbooru.PostTooltip.QTIP_OPTIONS.show.event = "contextmenu";
  unsafeWindow.Danbooru.PostTooltip.QTIP_OPTIONS.show.delay = 0;

  var thumbs = document.querySelectorAll(unsafeWindow.Danbooru.PostTooltip.POST_SELECTOR);
  for (i=0, l=thumbs.length; i<l; i++) {
    var thumb = thumbs[i];
    thumb.addEventListener('contextmenu', function (ev) {showQtip(ev);}, false);
    thumb.removeAttribute("title"); // Remove standard tooltip
  }
}

Edit: Should be working again as of 2018-08-19.

Updated

kittey said:

On-Demand Fancy Tooltips

I like the new fancy tooltips, but not all the time. With the default delay, they pop up way too quickly for my tastes; with a longer delay, I have to wait if I want to see them. This GreaseMonkey script makes the fancy tooltips pop up when right-clicking a thumbnail.

  • A simple right click loads the fancy tooltip. Shift + right click opens the usual context menu instead (tested in Firefox).
  • Disable post tooltips must be set to Yes in your account settings or they will pop up all over the place.
  • The browser’s standard tooltip will be disabled as well. (Remove line 24 if you want it.)
  • If you use TamperMonkey, you probably have to remove every unsafeWindow. from the script.
// ==UserScript==
// @name           On-Demand Tooltips
// @description    Show fancy tooltips when right-clicking a thumbnail.
// @match          *://*.donmai.us/*
// @grant          none
// @run-at         document-idle
// ==/UserScript==

function showQtip(event) {
  event.preventDefault();
  var t = event.currentTarget;
  unsafeWindow.$(t).qtip("enable");
  unsafeWindow.$(t).qtip(unsafeWindow.Danbooru.PostTooltip.QTIP_OPTIONS, event);
}

if (unsafeWindow.Danbooru && unsafeWindow.Danbooru.PostTooltip) {
  unsafeWindow.Danbooru.PostTooltip.QTIP_OPTIONS.show.event = "contextmenu";
  unsafeWindow.Danbooru.PostTooltip.QTIP_OPTIONS.show.delay = 0;

  var thumbs = document.querySelectorAll(unsafeWindow.Danbooru.PostTooltip.POST_SELECTOR);
  for (i=0, l=thumbs.length; i<l; i++) {
    var thumb = thumbs[i];
    thumb.addEventListener('contextmenu', function (ev) {showQtip(ev);}, false);
    thumb.removeAttribute("title"); // Remove standard tooltip
  }
}

This has stopped working for me the past week or so, it just defaults to popping up the standard tooltip.
The bit of custom script from another thread to just increase the tooltip's popup time has also stopped working. I don't know if it's all just on my end of things or if it's because of some recent site changes..

zigzag said:

This has stopped working for me the past week or so, it just defaults to popping up the standard tooltip.
The bit of custom script from another thread to just increase the tooltip's popup time has also stopped working. I don't know if it's all just on my end of things or if it's because of some recent site changes..

It's because of issue #3795. Many user scripts that rely on Danbooru's Javascript were broken because of that. It hasn't been requested yet, but I'll leave a comment to have the PostToolTip module exported as well.

Kaioshin_Sama said:

Any word on the status of issue#3795? Last update seems to have been about 5 days ago and Javascript for BetterBetterBooru is definitely still not working for me.

Do you have an example of where it does not work/what's broken of it? The script is working fine for me.

nonamethanks said:

Do you have an example of where it does not work/what's broken of it? The script is working fine for me.

The tab for it hadn't been displaying on danbooru for a week where it would normally appear and endless pages and all of the features I normally use like the collapsible side bar just aren't working at all. Strangely this time I reinstalled the exact same version again and this time it worked. I guess everything has to be fine on both the sites code and the scripts code when you add it to tampermonkey in order for it to work properly. Thanks for the heads up that it should be working in any case.

Updated

1 2 3 4 5 6 7 9