Skip to content

Instantly share code, notes, and snippets.

@xatier
Last active August 15, 2022 01:49
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 xatier/ae745bcededfb5bc6c086e085446f75b to your computer and use it in GitHub Desktop.
Save xatier/ae745bcededfb5bc6c086e085446f75b to your computer and use it in GitHub Desktop.
PTT imgur 展開
// ==UserScript==
// @name PTT imgur 展開
// @namespace https://www.ptt.cc/bbs
// @version 0.0.1
// @description 展開 imgur 圖片連結
// @author xatier
// @match https://www.ptt.cc/bbs/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=ptt.cc
// @grant none
// ==/UserScript==
(function() {
'use strict';
if (!document.querySelector('#main-content')) {
return
}
document.querySelector('#main-content').querySelectorAll('a').forEach((a) => {
let imgURL = a.innerHTML
if (imgURL.match(/https:\/\/(imgur\.com\/\w{7,10})/)) {
a.innerHTML = imgURL.replace(/https:\/\/(imgur\.com\/\w{7,10})/, 'https://i.$1.png')
a.outerHTML = `${a.outerHTML}<br><img src=${a.innerHTML} referrerpolicy="no-referrer"><br>`
//a.outerHTML = `${a.outerHTML}<br><img src=${a.innerHTML} rel="noreferrer"><br>`
}
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment