4chan better image server replace

Use this script if images in 4chan threads won't load/open.

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        4chan better image server replace
// @namespace   4chan-better-img-repl
// @include     http://boards.4chan.org/*/thread/*
// @version     1
// @grant       none
// @description Use this script if images in 4chan threads won't load/open.
// ==/UserScript==

var lastUpdated;
(function repl() {
  if (lastUpdated === undefined || ThreadUpdater.lastReply != null && lastUpdated != ThreadUpdater.lastUpdated) {
    lastUpdated = ThreadUpdater.lastUpdated;
    var els = document.getElementsByTagName("a");
    for(var i = els.length-1; i >= 0; i--) {
      var el = els[i], contains = el.outerHTML.indexOf('is2.4chan') > -1;
      if (el.className == 'fileThumb' && !contains) break;
      if (contains) el.outerHTML = el.outerHTML.replace(/s2\.4cha/, '.4cd');
    }
  }
  if (!ThreadUpdater.dead) setTimeout(repl, (ThreadUpdater.timeLeft || 1) * 1000);
})();