Skip to content

Instantly share code, notes, and snippets.

@Zerogoki00
Created January 7, 2024 19:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zerogoki00/111efdfc44855f9583bc89d34a4d738e to your computer and use it in GitHub Desktop.
Save Zerogoki00/111efdfc44855f9583bc89d34a4d738e to your computer and use it in GitHub Desktop.
Danbooru return plus and minus buttons
// ==UserScript==
// @name Danbooru tags buttons
// @namespace danbooru
// @version 0.1
// @description Return +/- buttons to Danbooru
// @author Jallot
// @include http*://*danbooru.donmai.us/posts*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let currentTags = document.getElementById("tags").value.split(" ").filter(String);
function addTagToSearch(tag){
var newTags = [...currentTags]
newTags.push(tag);
return newTags.join("+");
};
function removeTagFromSearch(tag) {
var newTags = [];
for (var i = 0; i < currentTags.length; i++){
if (currentTags[i] != tag){
newTags.push(currentTags[i]);
};
};
return newTags.join("+");
};
const tagList = document.querySelectorAll('ul li[class*="tag-type-"]');
for (const tag of tagList) {
const tagLinks = tag.querySelectorAll("a");
const tagNameNode = tagLinks[1];
const tagUrl = new URLSearchParams(tagNameNode.href.split('?')[1]);
const tagName = tagUrl.get("tags");
var plusLink = document.createElement('a');
plusLink.href = '/posts?tags=' + addTagToSearch(tagName);
plusLink.textContent = '+';
var minusLink = document.createElement('a');
minusLink.href = '/posts?tags=' + removeTagFromSearch(tagName);
minusLink.textContent = '-';
tagNameNode.parentNode.insertBefore(plusLink, tagNameNode);
tagNameNode.parentNode.insertBefore(document.createTextNode(" "), tagNameNode);
tagNameNode.parentNode.insertBefore(minusLink, tagNameNode);
tagNameNode.parentNode.insertBefore(document.createTextNode(" "), tagNameNode);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment