Skip to content

Instantly share code, notes, and snippets.

@Earlopain
Created September 18, 2021 13:14
Show Gist options
  • Save Earlopain/41e4168de59a85d7bbc9efca08003adf to your computer and use it in GitHub Desktop.
Save Earlopain/41e4168de59a85d7bbc9efca08003adf to your computer and use it in GitHub Desktop.
A small userscript which will mark artists without artist pages when viewing posts. Also marks artists whose urls contain direct images. Those probably aren't correct.
// ==UserScript==
// @name e621 artists
// @namespace http://tampermonkey.net/
// @version 0.1
// @description notify if artist page is missing
// @author Earlopain
// @match https://e621.net/posts/*
// @icon https://www.google.com/s2/favicons?domain=e621.net
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(async function () {
'use strict';
const tags = document.querySelectorAll(".artist-tag-list .search-tag");
const alreadyCheckedOK = GM_getValue("alreadyCheckedOK", []);
let updateChecked = false;
for (const tag of tags) {
const tagSanitized = tag.innerText.replaceAll(" ", "_");
if (alreadyCheckedOK.includes(tagSanitized)) {
continue;
}
if (await shouldCheck(tagSanitized)) {
tag.style.color = "red";
} else {
alreadyCheckedOK.push(tagSanitized);
updateChecked = true;
}
}
if (updateChecked) {
GM_setValue("alreadyCheckedOK", alreadyCheckedOK);
}
async function shouldCheck(tag) {
const ignoreList = ["unknown_artist", "conditional_dnp", "anonymous_artist", "sound_warning", "avoid_posting", "unknown_artist_signature"];
if (ignoreList.includes(tag)) {
return false;
}
const url = "https://e621.net/artists.json?search[name]=" + tag;
const request = await fetch(url);
const json = await request.json();
if (json.length === 0) {
return true;
}
const artist = json[0];
if (artist.urls.length === 0) {
return true;
}
for (const entry of artist.urls) {
const url = entry.url;
if (url.endsWith(".png") || url.endsWith(".jpg") || url.endsWith(".jpeg")) {
return true;
}
}
return false;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment