Last active
August 6, 2023 08:18
-
-
Save NightFeather/1dbe1ee6deda0d85d0bcf59ffb0ac565 to your computer and use it in GitHub Desktop.
把內嵌圖片還原成原圖
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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