Display Original Image

This script will replace thumbnail with full size image if available.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Display Original Image
// @version     0.1.2
// @namespace   eight04.blogspot.com
// @description This script will replace thumbnail with full size image if available.
// @include     http*
// @grant       none
// ==/UserScript==

"use strict";

function observeDocument(callback) {

	callback(document.body);

	new MutationObserver(function(mutations){
		var i;
		for (i = 0; i < mutations.length; i++) {
			if (!mutations[i].addedNodes.length) {
				continue;
			}
			callback(mutations[i].target);
		}
	}).observe(document.body, {
		childList: true,
		subtree: true
	});
}

function displayOriginalImage(node) {
	var imgs = node.querySelectorAll("a[href]>img[src]");
	var i;

	for (i = 0; i < imgs.length; i++) {
		replace(imgs[i], imgs[i].parentNode);
	}
}

function handleError() {
	this.src = this.oldSrc;
	this.removeEventListener(handleError);
	this.classList.add("display-original-image-failed");
}

function replace(img, anchor) {
	if (anchor.classList.contains("display-original-image")) {
		return;
	}
	if (!/\.(jpg|png|gif)($|\?)/i.test(anchor.href)) {
		return;
	}
	img.addEventListener("error", handleError);
	img.oldSrc = img.src;
	img.src = anchor.href;
	anchor.classList.add("display-original-image");
}

observeDocument(displayOriginalImage);