Skip to content

Instantly share code, notes, and snippets.

@NightFeather
Last active August 6, 2023 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NightFeather/1dbe1ee6deda0d85d0bcf59ffb0ac565 to your computer and use it in GitHub Desktop.
Save NightFeather/1dbe1ee6deda0d85d0bcf59ffb0ac565 to your computer and use it in GitHub Desktop.
把內嵌圖片還原成原圖
// ==UserScript==
// @name PTT 還原內嵌圖
// @namespace Violentmonkey Scripts
// @match https://www.ptt.cc/bbs/*
// @grant none
// @version 1.0
// @author Nightfeather
// @description 8/6/2023, 11:13:01 AM
// ==/UserScript==
(() => {
let els = document.querySelectorAll('.richcontent img[src^="https://cache.ptt.cc/"]');
if(els.length <= 0) { return; }
for(const el of els) {
let originalLinkElement = el.parentElement.previousElementSibling;
if(originalLinkElement && !(originalLinkElement instanceof HTMLAnchorElement)) {
originalLinkElement = originalLinkElement.querySelector('a')
}
if(originalLinkElement instanceof HTMLAnchorElement) {
el.src = originalLinkElement.href
continue;
}
console.warn(el, "has no matching link element.")
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment