-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStash Tagger View Div Remover.js
85 lines (83 loc) · 3 KB
/
Stash Tagger View Div Remover.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// ==UserScript==
// @name Stash-Tagger-View-Scene-Remove-Button
// @namespace https://github.com/7dJx1qP/stash-userscripts
// @version 0.3
// @description Adds remove tag button to div elements in tagger view, so if on mass scrape there is scene miss match. You can remove the scene before saving all.
// @author Echoman
// @match http://localhost:9999/*
// @require https://raw.githubusercontent.com/7dJx1qP/stash-userscripts/master/src\StashUserscriptLibrary.js
// @grant unsafeWindow
// @grant GM_getResourceText
// ==/UserScript==
(function () {
"use strict";
const {
stash,
Stash,
waitForElementId,
waitForElementClass,
waitForElementByXpath,
getElementByXpath,
getClosestAncestor,
updateTextInput,
} = unsafeWindow.stash;
async function run() {
await waitForElementByXpath(
"//div[contains(@class, 'tagger-container mx-md-auto')]",
function (xpath, el) {
// Get all div elements with class "mt-3" and "search-item"
const divs = document.querySelectorAll(".mt-3.search-item");
// Loop through each div element and add a remove button
divs.forEach((div) => {
// Check if a remove button has already been added to the current element
if (!div.querySelector(".tagger-remover")) {
const divContainer = document.createElement("div");
divContainer.setAttribute("class", "mt-2 text-right");
const removeBtn = document.createElement("button");
removeBtn.innerText = "Remove";
removeBtn.setAttribute("class", "tagger-remover btn btn-danger");
// Add click event listener to remove button
removeBtn.addEventListener("click", () => {
div.parentNode.removeChild(div);
});
divContainer.appendChild(removeBtn);
// Get the first child element with class "col-md-6 my-1"
const col = div.querySelector(".col-md-6.my-1");
if (col) {
// Get the div element without a class
const innerDiv = col.querySelector("div:not([class])");
if (innerDiv) {
// Append the new element as a child inside the inner div
innerDiv.appendChild(divContainer);
}
}
}
});
}
);
}
function updateElements() {
run();
}
stash.addEventListener("tagger:searchitem", () => {
console.log("Loaded");
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
Array.from(mutation.addedNodes).forEach((addedNode) => {
if (addedNode.matches && addedNode.matches(".mt-3.search-item")) {
setTimeout(function () {
updateElements();
}, 2000);
}
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
});
stash.addEventListener("tagger:searchitem", function () {
run();
});
})();