e621 Thumbnail Enhancer 2

Resizes thumbnails on e621.net and replaces them with hi-rez version. Modified for the new site design sometime around 2020-03-06

2020-03-08 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         e621 Thumbnail Enhancer 2
// @version      1.04
// @description  Resizes thumbnails on e621.net and replaces them with hi-rez version. Modified for the new site design sometime around 2020-03-06
// @author       justrunmyscripts
// @include      *://*e621.net*
// @grant        GM.xmlHttpRequest
// @namespace    https://sleazyfork.org/en/users/96703-justrunmyscripts
// @run-at       document-end
// ==/UserScript==


// original script creator https://greasyfork.org/de/users/398891
// to edit the size of the thumbnails, change the 25vw values below (the ones marked with !important... ;D )

try {
  
  let isMyAbsoluteFavoritePath = window.location.toString().endsWith('/favorites');
  let postContainerHash = isMyAbsoluteFavoritePath ? '#posts' : '#posts-container';

  let sty =document.createElement("style");
  sty.innerHTML=[
       ""
      ,".thumbEnh_cont {"
      ,"    display: flex;"
      ,"    flex-flow: row wrap;"
      ,"}"
      ,".thumbEnh_cont img.thumbEnh_img {"
      ,"    max-height: 100%;"
      ,"    max-width: 100%;"
      ,"}"
      ,"article.post-preview {"
      ,"    height: 25vw !important;"
      ,"    width: 25vw !important;"
      ,"}"
      ,"article.post-preview > a, article.post-preview > a > picture {"
      ,"    height: 94%;"
      ,"    width: 100%;"
      ,"}"
  ].join("");
  document.head.appendChild(sty);


  /* Replace image thumbnails with higher resolution */
  const imageThumb = (thumb) => {
      let newThumb = document.createElement('img');
      let replace = function (thumb) {
        thumb.src = this.src;
      };
      let trynoSample = function (thumb) {
        this.onerror = tryGif.bind(this, thumb);
        this.src = thumb.src.replace('/preview/', '/');
      };
      let tryGif = function (thumb) {
        this.onerror = null;
        this.src = thumb.src.replace('/preview/', '/').replace('.jpg', '.gif');
      };
      newThumb.onload = replace.bind(newThumb, thumb);
      newThumb.onerror = trynoSample.bind(newThumb, thumb);
      newThumb.src = thumb.src.replace('/preview/', '/sample/');
  }

  const main = () => {
      let contDiv = document.querySelector(postContainerHash);
      contDiv.className = "thumbEnh_cont";

      let imgs = document.querySelectorAll('article.post-preview img');
      for (img of imgs) {
        img.className = "thumbEnh_img";
        imageThumb(img);
      }

      // remove extra sources, since we're just using the "high rez" version anyways!
      let sources = document.querySelectorAll('article.post-preview source');
      for (source of sources) {  
        let parent = source.parentNode;
        parent.removeChild(source);
      }
  };

  main();

} catch (e) {
  // due to the way greasemonkey 'traps' errors, it kinda hides where the problem is!
  // this is an attempt at "fixing" that
	console.error(e);
}