Danbooru

Read the rules before proceeding!

Topic: Danbooru (etc...) userscripts

Posted under General

BrokenEagle98

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
// @match          *://*.donmai.us/posts/*
// @match          *://*.donmai.us/uploads/new
// @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
// @match          *://*.donmai.us/posts/*
// @match          *://*.donmai.us/uploads/new
// @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:
  • (2017-09-21)
    • Added continuous version in response to forum #136258
    • Added the uploads page to the pages the userscript runs on

Updated by BrokenEagle98

  • ID: 136245
  • Permalink
  • BrokenEagle98

    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
    // @match          *://*.donmai.us/posts?*
    // @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;
    });
    

    Updated by BrokenEagle98

  • ID: 136251
  • Permalink
  • southrim

    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 by southrim

  • ID: 136389
  • Permalink
  • BrokenEagle98

    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
    // @match          *://*.donmai.us/posts/*
    // @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>`
    });
    
  • ID: 138888
  • Permalink
  • BrokenEagle98

    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
    // @match        *://*.donmai.us/moderator/post/queue*
    // @match        *://*.donmai.us/posts/*
    // @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)});
    });
    
  • ID: 142167
  • Permalink
  • Gollgagh

    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.');}})();
    
  • ID: 142450
  • Permalink
  • Laethiel

    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 by Laethiel

  • ID: 143665
  • Permalink

    worldendDominator

    I've found a bug when I use both Note Assist and BBB. In add notes mode, clicking anywhere on the image, or in the note edit window, duplicates the note I created last.
    This doesn't happen when only one of those scripts is enabled.

  • ID: 143683
  • Permalink
  • BrokenEagle98

    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.3
    // @description  Corrects images to point to own domain
    // @match        *://*.donmai.us/*
    // @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

    Updated by BrokenEagle98

  • ID: 144867
  • Permalink
  • OniTea

    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.

  • ID: 144869
  • Permalink
  • BrokenEagle98

    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"
    
  • ID: 144872
  • Permalink
  • OniTea

    BrokenEagle98 said:
    I believe I fixed those issues in Version 1.2

    Works perfect now. Many thanks again.

  • ID: 144873
  • Permalink
  • Fiveflower

    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.

  • ID: 144875
  • Permalink
  • BrokenEagle98

    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.

  • ID: 144876
  • Permalink
  • kittey

    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
      }
    }
    
  • ID: 146849
  • Permalink
  • 1
  • 2
  • 3
  • >>