Danbooru tags buttons

Return +/- buttons to Danbooru

  1. // ==UserScript==
  2. // @name Danbooru tags buttons
  3. // @namespace danbooru
  4. // @version 0.2
  5. // @description Return +/- buttons to Danbooru
  6. // @author Jallot
  7. // @include http*://*danbooru.donmai.us/posts*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. let currentTags = document.getElementById("tags").value.split(" ").filter(String);
  15.  
  16. function addTagToSearch(tag, negative=false){
  17. var newTags = [...currentTags]
  18. if (negative){
  19. tag = "-" + tag;
  20. }
  21. newTags.push(tag);
  22. return newTags.join("+");
  23. };
  24.  
  25.  
  26. const tagList = document.querySelectorAll('ul li[class*="tag-type-"]');
  27. for (const tag of tagList) {
  28. const tagLinks = tag.querySelectorAll("a");
  29. const tagNameNode = tagLinks[1];
  30. const tagUrl = new URLSearchParams(tagNameNode.href.split('?')[1]);
  31. const tagName = tagUrl.get("tags");
  32. var plusLink = document.createElement('a');
  33. plusLink.href = '/posts?tags=' + addTagToSearch(tagName);
  34. plusLink.textContent = '+';
  35. var minusLink = document.createElement('a');
  36. minusLink.href = '/posts?tags=' + addTagToSearch(tagName, true);
  37. minusLink.textContent = '-';
  38. tagNameNode.parentNode.insertBefore(plusLink, tagNameNode);
  39. tagNameNode.parentNode.insertBefore(document.createTextNode(" "), tagNameNode);
  40. tagNameNode.parentNode.insertBefore(minusLink, tagNameNode);
  41. tagNameNode.parentNode.insertBefore(document.createTextNode(" "), tagNameNode);
  42. };
  43. })();