🐴
IRL 🎠 stallion
I can’t seem to get this to work with the FF Violentmonkey edition. The “tag edit” button is there, but it does nothing when I click it. Tried under both Mac and Debian.
Confirmed. Thanks :D
const booruDefault = {
...
forbiddenRedirPath: '/', //new
hasTagError: (str) => { //is this the best way to do this? I dunno, I'm barely a hobbyist
const dom = new DOMParser().parseFromString(str, 'text/html');
return {
errored: [...dom.getElementsByClassName('alert-danger')]
.some((ele) => ele.textContent.includes('Oops, something went wrong!')),
messages: [...dom.getElementsByClassName('help-block')]
.map((ele) => ele.textContent),
}; },
async function throttle(fn, ...args) {
...
try { //because we're throwing errors around
const result = await new Promise(resolve => {
window.setTimeout(() => {
resolve(fn(...args));
}, timeRemain);
});
GM_setValue(key, Date.now());
return result;
} finally {
GM_setValue(key, Date.now()); //still need to do this while throwing errors around
}
async function bulkApplyTags(tagsToAdd, tagsToRemove) {
...
await throttle(submitEdit, id, oldTags, newTags);
} catch (err) {
errors += 1;
// Also do stuff like styling thumbnails based on what the specific error is
} finally {
async function submitEdit(id, oldTags, newTags) {
...
const abort = new AbortController(); //new
const resp = await fetch(path, {
method: 'POST',
body: form,
signal: abort.signal, //new
});
if (resp.status !== 200) {
throw new Error('status code: ' + resp.status);
} else if (resp.redirected) { //all new
abort.abort();
if ((window.location.origin + getBooruParam('forbiddenRedirPath')) == (resp.url))
throw new Error('forbidden');
else
throw new Error('redirected');
}
const body = await resp.text();
const errors = getBooruParam('hasTagError')(body);
if (errors.errored) throw new Error('prevented', { cause: errors.messages });
fetch
will resolve it as a status 200 with .redirect
= true and .url
as location.origin + '/'
<div class=\"js-imageform hidden\"><p>You can't edit the tags on this image. </p></div>
.referer
window.location.origin + window.location.pathname + window.location.search
seems to be the default…but perhaps some other user extension would alter that, and I couldn’t find a way to get the actual referer
string that will be sent by fetch
’s Request
- it just returns about:client
verbatim.resp.redirected
and hope that no other philomena implementation uses redirects for successful API responses.safe
and suggestive
, philomena rejects the entire attempt and that should also be detected as an error.Oops, something went wrong! Please check the errors below.
which could be detected. const content = $('#content');
needs to be const content = $('#content>.layout--narrow');
(faster), orobserver.observe(content, {childList: true});
needs to be observer.observe(content, {childList: true, subtree: true});
(more future-proof)Help fund the $15 daily operational cost of Derpibooru - support us financially!