[Konachan / yande.re] Thumbnails: Fix Highres Link

*Does not work on wiki pages* (1) Changes the links below thumbnails to link to the original PNG instead of the highres JPEG. • (2) Changes the image size shown below thumbnails to the size of the original PNG which can be different for large images.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name		[Konachan / yande.re] Thumbnails: Fix Highres Link
// @namespace	Zolxys
// @description	*Does not work on wiki pages* (1) Changes the links below thumbnails to link to the original PNG instead of the highres JPEG. • (2) Changes the image size shown below thumbnails to the size of the original PNG which can be different for large images.
// @include		/^https?://konachan\.com/(post(/similar(/\d+)?)?|user/show/\d+)/?($|\?|#)/
// @include		/^https?://konachan\.net/(post(/similar(/\d+)?)?|user/show/\d+)/?($|\?|#)/
// @include		/^https?://yande\.re/(post(/similar(/\d+)?)?|user/show/\d+)/?($|\?|#)/
// @version		1.3
// ==/UserScript==
if (document.getElementById('post-list-posts') == null)
	return;
var a = document.getElementsByTagName('li'); // Searches from document instead of id 'post-list-posts' because that id occurs multiple times on the profile page.
for (var i = 0; i < a.length; ++i) {
	if (!/^p\d+$/.test(a[i].id))
		continue;
	if (!/(^|\s)creator-id-\d+(\s|$)/.test(a[i].className))
		continue;
	var n = parseInt(a[i].id.substr(1));
	var s = a[i].getElementsByTagName('span');
	for (var p = 0; p < s.length; ++p) 
	  if (s[p].childElementCount == 0 && /(^|\s)directlink-res(\s|$)/.test(s[p].className)) {
		s[p].textContent = window.Post.posts._object[n].width +' × '+ window.Post.posts._object[n].height;
		if (s[p].parentNode.nodeName != 'A')
			continue;
		s[p].parentNode.href = window.Post.posts._object[n].file_url;
	}
}