forked from stashapp/CommunityScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstashdb_submission_helper.user.js
445 lines (395 loc) · 13.1 KB
/
stashdb_submission_helper.user.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
// ==UserScript==
// @name StashDB Submission Helper
// @author mmenanno
// @version 0.7
// @description Adds button to add all unmatched aliases, measurements, and urls to a performer.
// @icon https://raw.githubusercontent.com/stashapp/stash/develop/ui/v2.5/public/favicon.png
// @namespace https://github.com/mmenanno
// @match https://stashdb.org/drafts/*
// @match https://stashdb.org/performers/*/edit
// @match https://stashdb.org/performers/add
// @homepageURL https://github.com/stashapp/CommunityScripts/tree/main/userscripts/StashDB_Submission_Helper
// @downloadURL https://raw.githubusercontent.com/stashapp/CommunityScripts/main/userscripts/StashDB_Submission_Helper/stashdb_submission_helper.user.js
// @updateURL https://raw.githubusercontent.com/stashapp/CommunityScripts/main/userscripts/StashDB_Submission_Helper/stashdb_submission_helper.user.js
// ==/UserScript==
function setNativeValue(element, value) {
const valueSetter = Object.getOwnPropertyDescriptor(element, "value")?.set;
const prototype = Object.getPrototypeOf(element);
const prototypeValueSetter = Object.getOwnPropertyDescriptor(
prototype,
"value"
)?.set;
if (prototypeValueSetter && valueSetter !== prototypeValueSetter) {
prototypeValueSetter.call(element, value);
} else if (valueSetter) {
valueSetter.call(element, value);
} else {
throw new Error("The given element does not have a value setter");
}
const eventName = element instanceof HTMLSelectElement ? "change" : "input";
element.dispatchEvent(new Event(eventName, { bubbles: true }));
}
function waitForElm(selector) {
return new Promise((resolve) => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver((mutations) => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
});
}
const aliasInputSelector = 'label[for="aliases"] + div input';
function unmatchedTargetElement(targetProperty) {
var targetRegex =
'//h6/following-sibling::ul/li[b[contains(text(), "' +
targetProperty +
'")]]/span/text()';
var targetElement = document.evaluate(
targetRegex,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
return targetElement;
}
function unmatchedTargetValue(targetProperty) {
var targetElement = unmatchedTargetElement(targetProperty);
if (targetElement == null) {
return;
}
return targetElement.data;
}
function unmatchedTargetButton(targetProperty) {
var targetRegex =
'//h6/following-sibling::ul/li[b[contains(text(), "' +
targetProperty +
'")]]';
var targetElement = document.evaluate(
targetRegex,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
return targetElement;
}
function wrapUrlTag(url) {
return "<a href='" + url + "' target='_blank'>" + url + "</a>";
}
function makeUrlLink(element) {
const currentUrls = element.data.split(", ");
const wrappedUrls = currentUrls.map((url) => {
return wrapUrlTag(url);
});
element.parentElement.innerHTML = wrappedUrls.join(", ");
}
function formTab(tabName) {
const tabRegex =
'//ul[@role="tablist"]/li/button[contains(text(), "' + tabName + '")]';
return document.evaluate(
tabRegex,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
}
function addAlias(alias) {
alias = alias.trim();
const existingAliases = Array.from(
document.querySelectorAll(
'label[for="aliases"] + div .react-select__multi-value__label'
)
);
let aliasMatch = existingAliases.find((element) => {
return element.innerText == alias;
});
if (typeof aliasMatch !== "undefined") {
console.warn(
"Skipping alias '" + alias + "' as it is already added to this performer."
);
return;
}
const aliasInput = document.querySelector(aliasInputSelector);
setNativeValue(aliasInput, alias);
var addButton = document.querySelector(
'label[for="aliases"] + div .react-select__option'
);
formTab("Personal Information").click();
addButton.click();
}
function existingUrlObjects() {
const existingUrls = Array.from(
document.querySelectorAll(".URLInput ul .input-group")
);
const urlObjects = existingUrls.map((urlGroup) => {
let site = urlGroup.childNodes[1].innerText;
let url = urlGroup.childNodes[2].innerText;
let urlObject = {
site: site,
url: url,
};
return urlObject;
});
return urlObjects;
}
function urlSite(url) {
let site;
if (
/(^https?:\/\/(?:www\.)?adultfilmdatabase\.com\/(?:video|studio|actor)\/.+)\??/.test(
url
)
) {
site = "AFDB";
} else if (/(https?:\/\/www.babepedia.com\/babe\/[^?]+)\??/.test(url)) {
site = "Babepedia";
} else if (
/(^https?:\/\/(?:www\.)?bgafd\.co\.uk\/(?:films|actresses)\/details.php\/id\/[^?]+)\??/.test(
url
)
) {
site = "BGAFD";
} else if (/(https?:\/\/www.boobpedia.com\/boobs\/[^?]+)\??/.test(url)) {
site = "Boobpedia";
} else if (/(https?:\/\/www.data18.com\/[^?]+)\??/.test(url)) {
site = "DATA18";
} else if (
/(^https?:\/\/(?:www\.)?egafd\.com\/(?:films|actresses)\/details.php\/id\/[^?]+)\??/.test(
url
)
) {
site = "EGAFD";
} else if (
/(https?:\/\/(www\.)?eurobabeindex.com\/sbandoindex\/.*?.html)/.test(url)
) {
site = "Eurobabeindex";
} else if (/(^https?:\/\/(?:www.)?facebook\.com\/[^?]+)/.test(url)) {
site = "Facebook";
} else if (/(https?:\/\/www.freeones.com\/[^/?]+)\??/.test(url)) {
site = "FreeOnes";
} else if (/(https?:\/\/www.iafd.com\/[^?]+)\??/.test(url)) {
site = "IAFD";
} else if (
/(^https?:\/\/(?:www\.)?imdb\.com\/(?:name|title)\/[^?]+)\/?/.test(url)
) {
site = "IMDB";
} else if (/(https?:\/\/www.indexxx.com\/[^?]+)\??/.test(url)) {
site = "Indexxx";
} else if (/(https?:\/\/www.instagram.com\/[^/?]+)\??/.test(url)) {
site = "Instagram";
} else if (/(https?:\/\/www.manyvids.com\/[^?]+)\??/.test(url)) {
site = "ManyVids";
} else if (
/(^https?:\/\/(?:www.)?minnano-av\.com\/actress\d+.html)/.test(url)
) {
site = "Minnano-av";
} else if (/(^https?:\/\/(?:www.)?myspace\.com\/[^?]+)/.test(url)) {
site = "Myspace";
} else if (/(https?:\/\/onlyfans.com\/[^?]+)\??/.test(url)) {
site = "OnlyFans";
} else if (/(https?:\/\/www.thenude.com\/[^?]+\.htm)/.test(url)) {
site = "theNude";
} else if (/(^https?:\/\/(?:www.)?tiktok\.com\/@[^?]+)/.test(url)) {
site = "TikTok";
} else if (/(https?:\/\/twitter.com\/[^?]+)\??/.test(url)) {
site = "Twitter";
} else if (/(^https?:\/\/(www\.)?wikidata.org\/wiki\/[^?]+)/.test(url)) {
site = "Wikidata";
} else if (/(^https?:\/\/(?:\w+\.)?wikipedia\.org\/wiki\/[^?]+)/.test(url)) {
site = "Wikipedia";
} else if (/(^https?:\/\/xslist\.org\/en\/model\/\d+\.html)/.test(url)) {
site = "XsList";
} else if (
/(^https?:\/\/(?:www.)?youtube\.com\/(?:c(?:hannel)?|user)\/[^?]+)/.test(
url
)
) {
site = "YouTube";
} else {
return;
}
return site;
}
function siteMatch(url, selections) {
const match = Array.from(selections.options).find(
(option) => option.text == urlSite(url)
);
return match;
}
function addUrl(url) {
const existingUrls = existingUrlObjects();
let urlMatch = existingUrls.find((element) => {
return element.url == url;
});
if (typeof urlMatch !== "undefined") {
console.warn(
"Skipping url '" + url + "' as it is already added to this performer."
);
return;
}
const urlForm = document.querySelector("form .URLInput");
const urlInput = urlForm.querySelector(":scope > .input-group");
const selections = urlInput.children[1];
const inputField = urlInput.children[2];
const addButton = urlInput.children[3];
const selection = siteMatch(url, selections);
setNativeValue(selections, selection.value);
setNativeValue(inputField, url);
if (addButton.disabled) {
console.warn("Unable to add url (Add button is disabled)");
}
formTab("Links").click();
addButton.click();
}
function setStyles(element, styles) {
Object.assign(element.style, styles);
return element;
}
function baseButtonContainer() {
const container = document.createElement("span");
return container;
}
function baseButtonSet(name) {
const set = document.createElement("a");
set.innerText = "add " + name;
set.classList.add("fw-bold");
setStyles(set, {
color: "var(--bs-yellow)",
cursor: "pointer",
"margin-left": "0.5em",
});
return set;
}
function insertButton(action, element, name) {
const container = baseButtonContainer();
const set = baseButtonSet(name);
set.addEventListener("click", action);
container.append(set);
element.appendChild(container);
}
function addMeasurements(measurements) {
const splitMeasurements = measurements.split("-");
if (splitMeasurements.length > 0) {
const braSize = splitMeasurements[0].trim();
const braInput = document.querySelector('input[name="braSize"]');
setNativeValue(braInput, braSize);
}
if (splitMeasurements.length > 1) {
const waistSize = splitMeasurements[1].trim();
const waistInput = document.querySelector('input[name="waistSize"]');
setNativeValue(waistInput, waistSize);
}
if (splitMeasurements.length > 2) {
const hipSize = splitMeasurements[2].trim();
const hipInput = document.querySelector('input[name="hipSize"]');
setNativeValue(hipInput, hipSize);
}
formTab("Personal Information").click();
}
function createAliasButton(unmatched, element) {
const addAliases = () => unmatched.forEach(addAlias);
insertButton(addAliases, element, "aliases");
}
function createMeasurementsButton(unmatched, element) {
const insertMeasurements = () => addMeasurements(unmatched);
insertButton(insertMeasurements, element, "measurements");
}
function createUrlsButton(unmatched, element) {
const addUrls = () => unmatched.forEach(addUrl);
insertButton(addUrls, element, "urls");
}
function isValidMeasurements(measurements) {
const measurementsRegex = /(\d\d\w?\w?\w?\s?)(-\s?\d\d\s?)?(-\s?\d\d)?/;
const isValid = measurementsRegex.test(measurements);
if (!isValid) {
console.warn(
"Measurement format '" +
measurements +
"' is invalid and cannot be automatically added."
);
}
return measurementsRegex.test(measurements);
}
function addAliasInputContainer() {
const performerForm = document.querySelector(".PerformerForm");
const aliasContainer = document.createElement("div");
aliasContainer.innerHTML = '<button id="aliasButton">Add Aliases</button>';
aliasContainer.setAttribute("id", "aliasContainer");
performerForm.prepend(aliasContainer);
const aliasButton = document.createElement("input");
aliasButton.innerText = "Add Aliases";
aliasButton.setAttribute("id", "aliasButton");
aliasButton.setAttribute("style", "border-radius: 0.25rem;");
const aliasField = document.createElement("input");
aliasField.setAttribute("id", "aliasField");
aliasField.setAttribute("placeholder", " Comma separated aliases");
aliasField.setAttribute("size", "50px");
aliasField.setAttribute(
"style",
"border-radius: 0.25rem; margin-right: 0.5rem;"
);
document.getElementById("aliasContainer").prepend(aliasField);
const enteredAliases = document.getElementById("aliasField").value;
document
.getElementById("aliasButton")
.addEventListener("click", function handleClick(event) {
event.preventDefault();
const aliasField = document.getElementById("aliasField");
if (aliasField.value != "") {
aliasField.value.split(/,|\/|\sor\s/).forEach(addAlias);
aliasField.value = "";
}
});
}
function performerEditPage() {
const aliasValues = unmatchedTargetValue("Aliases");
if (aliasValues != null) {
const unmatchedAliases = aliasValues.split(/,|\/|\sor\s/);
const aliasElement = unmatchedTargetButton("Aliases");
createAliasButton(unmatchedAliases, aliasElement);
}
const urlsValues = unmatchedTargetValue("URLs");
if (urlsValues != null) {
const unmatchedUrls = urlsValues.split(", ");
if (unmatchedUrls) {
const umatchedUrlsElement = unmatchedTargetElement("URLs");
makeUrlLink(umatchedUrlsElement);
}
const urlsElement = unmatchedTargetButton("URLs");
createUrlsButton(unmatchedUrls, urlsElement);
}
const unmatchedMeasurements = unmatchedTargetValue("Measurements");
if (unmatchedMeasurements != null) {
if (isValidMeasurements(unmatchedMeasurements)) {
const measurementsElement = unmatchedTargetButton("Measurements");
createMeasurementsButton(unmatchedMeasurements, measurementsElement);
}
}
addAliasInputContainer();
}
function sceneEditPage() {
return;
}
function pageType() {
return document
.querySelector(".NarrowPage form")
.className.replace("Form", "");
}
waitForElm(aliasInputSelector).then(() => {
if (pageType() == "Performer") {
performerEditPage();
} else if (pageType() == "Scene") {
sceneEditPage();
} else {
return;
}
});