PTT reformat for Evernote

原始的 PTT 網頁用 Evernote Web Clipper 擷取,圖片會跑版,此為替換原本的自動開圖區塊

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

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

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         PTT reformat for Evernote
// @namespace    https://greasyfork.org/zh-TW/users/79288
// @version      1.8
// @description  原始的 PTT 網頁用 Evernote Web Clipper 擷取,圖片會跑版,此為替換原本的自動開圖區塊
// @author       jlhg
// @match        https://www.ptt.cc/bbs/*/*.html
// @match        https://www.ptt.cc/man/*.html
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  let imageStyle = "max-height:none;max-width:800px";

  ['.jpg', '.JPG', '.png', '.PNG', '.jpeg', '.JPEG', '.gif', '.GIF'].forEach(function(ext) {
    let images = document.querySelectorAll('a[href$="' + ext + '"]');
    for (let i = 0; i < images.length; i++) {
      let imageUrl = images[i].href;
      images[i].innerHTML += '<br><img src="' + imageUrl + '" style="'+ imageStyle + '" referrerpolicy="no-referrer"><br>';
      images[i].style.boxShadow = 'none';
    }
  });

  let images = document.querySelectorAll('a[href^="https://imgur.com/"]');
  for (let i = 0; i < images.length; i++) {
    if (images[i].href.indexOf("https://imgur.com/a/") >= 0 || /\.(jpg|png)$/i.test(images[i].href)) {
      continue;
    }

    images[i].innerHTML += '<br><img src="' + images[i].href + '.jpg" style="' + imageStyle + '" referrerpolicy="no-referrer"><br>';
    images[i].style.boxShadow = 'none';
  }

  let richcontents = document.querySelectorAll('.richcontent');
  for (let i = 0; i < richcontents.length; i++) {
    richcontents[i].remove();
  }
})();