Last active
November 27, 2024 04:05
-
-
Save syldrathecat/eb0332ae06f3a3f68c00420674c8e5a7 to your computer and use it in GitHub Desktop.
e621 Uncensored Tampermonkey script
This file contains hidden or 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 e621 Uncensored | |
// @version 1.2 | |
// @author SyldraTheCat | |
// @match https://e621.net/ | |
// @match https://e621.net/posts* | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let pathname = window.location.pathname; | |
let path_match_result = pathname.match(/^\/?(posts)?(\/?|\/([0-9]+))$/); | |
if (path_match_result == null) | |
{ | |
console.log("*** Unknown page"); | |
return; | |
} | |
let is_search_page = (path_match_result[2] == '' || path_match_result[2] == '/'); | |
if (is_search_page) | |
{ | |
console.log("*** Search page detected"); | |
let elem_hidden_posts_notice = $('.hidden-posts-notice'); | |
if (elem_hidden_posts_notice.length > 0) | |
{ | |
console.log("*** Censored posts detected, retrieving post information..."); | |
elem_hidden_posts_notice.text("Loading..."); | |
let elem_posts_container = $('#posts-container'); | |
if (elem_posts_container.length == 0) | |
{ | |
console.log("!!! elem_posts_container not found"); | |
elem_hidden_posts_notice.text("Error 104 :("); | |
return; | |
} | |
$.ajax('https://e621.net/posts.atom' + window.location.search, { | |
dataType: 'xml', | |
error: function(xhr, status, err) | |
{ | |
elem_hidden_posts_notice.text("Error 101 :("); | |
console.log("!!! Data request failed: ", status); | |
console.log("!!!", err); | |
}, | |
success: function(data, stratus, xhr) | |
{ | |
let jdata = $(data); | |
let entries = jdata.find('entry'); | |
if (entries.length == 0) | |
{ | |
console.log("!!! no entries found"); | |
elem_hidden_posts_notice.text("Error 102 :("); | |
return; | |
} | |
let present_posts = {}; | |
$.each(elem_posts_container.children(), function() | |
{ | |
let jthis = $(this); | |
let post_id = jthis.attr('data-id'); | |
present_posts[post_id] = jthis.detach(); | |
}); | |
$.each(entries, function() | |
{ | |
let jentry = $(this); | |
let atom_title = jentry.children('title'); | |
let atom_updated = jentry.children('updated'); | |
let atom_summary = jentry.children('summary'); | |
let atom_a = jentry.find('content a'); | |
let atom_img = jentry.find('content img'); | |
if (!atom_title || !atom_a || !atom_updated || !atom_summary || !atom_img) | |
{ | |
console.log("!!! Could not extract all atom elements"); | |
elem_hidden_posts_notice.text("Error 190 :("); | |
return; | |
} | |
let post_url = atom_a.attr('href'); | |
let preview_url = atom_img.attr('src'); | |
let post_url_match_result = post_url.match(/\/posts\/([0-9]+)/); | |
if (post_url_match_result === null) | |
{ | |
console.log("!!! Could not extract post ID from post URL"); | |
elem_hidden_posts_notice.text("Error 105 :("); | |
return; | |
} | |
let preview_url_match_result = preview_url.match(/([a-f0-9]{32})\.(.{1,9})$/); | |
if (preview_url_match_result === null) | |
{ | |
console.log("!!! Could not extract md5 from preview URL"); | |
elem_hidden_posts_notice.text("Error 103 :("); | |
return; | |
} | |
let post_id = post_url_match_result[1]; | |
let md5 = preview_url_match_result[1]; | |
let ext = preview_url_match_result[2]; | |
let aa = md5[0] + md5[1]; | |
let bb = md5[2] + md5[3]; | |
// image_url is mostly incorrect here because the file extension differs | |
//let image_url = 'https://static1.e621.net/data/' + aa + '/' + bb + '/' + md5 + '.' + XXX; | |
let sample_url = 'https://static1.e621.net/data/sample/' + aa + '/' + bb + '/' + md5 + '.' + ext; | |
let image_url = sample_url; | |
if (post_id in present_posts) | |
{ | |
elem_posts_container.append(present_posts[post_id]); | |
return; | |
} | |
let post_url_with_query = post_url; | |
let query_match_result = window.location.search.match(/(\?|&)tags=([^&]*)&?/); | |
if (query_match_result !== null) | |
{ | |
post_url_with_query += '?q=' + query_match_result[2]; | |
} | |
let title_text = | |
"ID: " + post_id + | |
"\nDate: " + atom_updated.text() + | |
"\nStatus: unknown" + | |
"\nScore: unknown" + | |
"\n\n" + atom_summary.text(); | |
// its so big uwu | |
let elem_article = $('<article>').attr('id', 'post_' + post_id).attr('class', 'post-preview captioned').append( | |
$('<a>').attr('href', post_url_with_query).append( | |
$('<picture>').append( | |
$('<source>').attr('media', '(max-width: 800px)').attr('srcset', preview_url), | |
$('<source>').attr('media', '(min-width: 800px)').attr('srcset', preview_url), | |
$('<img>').attr('class', 'has-cropped-false').attr('src', preview_url).attr('title', title_text), | |
) | |
) | |
); | |
elem_posts_container.append(elem_article); | |
}); | |
elem_hidden_posts_notice.remove(); | |
} | |
}); | |
} | |
else | |
{ | |
console.log("*** No search page censorship detected!"); | |
} | |
} | |
else | |
{ | |
let post_id = +path_match_result[3]; | |
let elem_image_container = $('#image-container'); | |
// Uploader data is right there so why not... | |
if (elem_image_container.length > 0) | |
{ | |
console.log("*** Attempting to insert uploader info..."); | |
let uploader_name = elem_image_container.attr('data-uploader'); | |
let uploader_id = elem_image_container.attr('data-uploader-id'); | |
let uploader_url = "/users/" + uploader_id; | |
let elem_post_information = $('#post-information ul'); | |
if (elem_post_information.length > 0) | |
{ | |
let elem_approver_li = elem_post_information.children('li:nth-child(3)'); | |
if (elem_approver_li.length > 0) | |
{ | |
let elem_li = $('<li>'); | |
let elem_a = $('<a>'); | |
elem_a.attr('href', uploader_url); | |
elem_a.text(uploader_name); | |
elem_li.text("Uploader: "); | |
elem_li.append(elem_a); | |
elem_li.insertBefore(elem_approver_li); | |
} | |
else | |
{ | |
console.log("!!! elem_approver_li not found"); | |
} | |
} | |
else | |
{ | |
console.log("!!! elem_post_information not found"); | |
} | |
} | |
else | |
{ | |
console.log("*** No uploader info found"); | |
} | |
let censorship_text = $('#note-preview + p'); | |
if (censorship_text.length > 0) | |
{ | |
console.log("*** Censorship message detected, retrieving post information..."); | |
censorship_text.text("Loading..."); | |
$.ajax('https://e621.net/posts.atom?tags=id:' + post_id, { | |
dataType: 'xml', | |
error: function(xhr, status, err) | |
{ | |
censorship_text.text("Error 201 :("); | |
console.log("!!! Data request failed: ", status); | |
console.log("!!!", err); | |
}, | |
success: function(data, stratus, xhr) | |
{ | |
let jdata = $(data); | |
let atom_img = jdata.find('content img'); | |
if (atom_img.length == 0) | |
{ | |
console.log("!!! atom_img not found"); | |
censorship_text.text("Error 202 :("); | |
return; | |
} | |
let preview_url = atom_img.attr('src'); | |
let preview_url_match_result = preview_url.match(/([a-f0-9]{32})\.(.{1,9})$/); | |
if (preview_url_match_result === null) | |
{ | |
console.log("!!! Could not extract md5 from preview URL"); | |
censorship_text.text("Error 203 :("); | |
return; | |
} | |
let md5 = preview_url_match_result[1]; | |
let ext = preview_url_match_result[2]; | |
let file_ext = elem_image_container.attr('data-file-ext'); | |
// This conflicts with the way we set the image src, I guess | |
elem_image_container.removeClass('blacklisted-active'); | |
let aa = md5[0] + md5[1]; | |
let bb = md5[2] + md5[3]; | |
let image_url = 'https://static1.e621.net/data/' + aa + '/' + bb + '/' + md5 + '.' + file_ext; | |
let sample_url = 'https://static1.e621.net/data/sample/' + aa + '/' + bb + '/' + md5 + '.' + ext; | |
let new_img_elem = $('<img>'); | |
new_img_elem.attr('id', 'image'); | |
new_img_elem.attr('class', 'fit-window'); | |
new_img_elem.attr('src', sample_url); | |
// If sample_url 404s, try the main URL | |
new_img_elem.on('error', function() | |
{ | |
let jthis = $(this); | |
jthis.attr('src', image_url); | |
jthis.attr('data-file-url', image_url); | |
}); | |
if (elem_image_container.length > 0) | |
{ | |
$.each(elem_image_container.prop("attributes"), function() | |
{ | |
if (this.name.substr(0, 5) == 'data-') | |
new_img_elem.attr(this.name, this.value); | |
}); | |
} | |
new_img_elem.attr('data-md5', md5); | |
new_img_elem.attr('data-file-url', sample_url); | |
new_img_elem.attr('data-large-file-url', image_url); | |
new_img_elem.attr('data-preview-file-url', preview_url); | |
elem_image_container.attr('data-md5', md5); | |
elem_image_container.attr('data-file-url', image_url); | |
elem_image_container.attr('data-large-file-url', sample_url); | |
elem_image_container.attr('data-preview-file-url', preview_url); | |
new_img_elem.replaceAll(censorship_text); | |
// More stuff to fix up :( | |
let elem_extra_controls = $('#image-extra-controls'); | |
if (elem_extra_controls.length == 0) | |
{ | |
console.log("!!! elem_extra_controls not found"); | |
return; | |
} | |
let elem_dl_link_div = $('<div>'); | |
elem_dl_link_div.attr('id', 'image-download-link'); | |
let elem_dl_link_a = $('<a>'); | |
elem_dl_link_a.text('Download'); | |
elem_dl_link_a.attr('target', '_blank'); | |
elem_dl_link_a.attr('href', image_url); | |
elem_dl_link_div.append(elem_dl_link_a); | |
elem_extra_controls.prepend(elem_dl_link_div); | |
} | |
}); | |
} | |
else | |
{ | |
console.log("*** No censorship detected!"); | |
} | |
} | |
})(); |
tbh i dont even remember what this script is for
You wrote an explanation for it here: https://e621.net/forum_topics/25850. Surprised you replied that quickly. Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script stopped working the other day. Now images/videos affected by the global blacklist don't appear when searching.