Created
January 7, 2024 19:55
-
-
Save Zerogoki00/111efdfc44855f9583bc89d34a4d738e to your computer and use it in GitHub Desktop.
Danbooru return plus and minus buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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