Last active
August 15, 2022 01:49
-
-
Save xatier/ae745bcededfb5bc6c086e085446f75b to your computer and use it in GitHub Desktop.
PTT imgur 展開
This file contains hidden or 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 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