Last active
August 31, 2019 03:00
-
-
Save dk00/8da9f010f7a394550b1d368ac1eea6f6 to your computer and use it in GitHub Desktop.
移除 ptt 網頁版的 imgur 圖片的外框
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 imgur embed | |
// @namespace gist.github.com/dk00 | |
// @include https://www.ptt.cc/bbs/*.html | |
// @include https://www.ptt.cc/man/*.html | |
// @version 0.0.3 | |
// @license Unlicense | |
// @compatible firefox | |
// @compatible chrome | |
// @run-at document-start | |
// ==/UserScript== | |
const h = (tag, props) => Object.assign(document.createElement(tag), props) | |
const preventScript = test => event => | |
test(event.target.src) && event.preventDefault() | |
const isImgurScript = name => /imgur.com/.test(name) | |
document.addEventListener('beforescriptexecute', preventScript(isImgurScript)) | |
try { //if no beforescriptexecute | |
unsafeWindow.imgurEmbed = {createIframe: () => void 8} | |
} catch(e) {} | |
document.addEventListener('DOMContentLoaded', main) | |
const entry = '.imgur-embed-pub' | |
const imgurURL = node => { | |
const link = node.parentElement.previousElementSibling | |
return (link.href || link.querySelector('a').href).replace('http:', 'https://') | |
} | |
const ensureSuffix = url => /\.(jpe?g|png)$/.test(url)? url: url + '.jpg' | |
function repaste(node) { | |
node.parentElement.appendChild(h('img', { | |
src: ensureSuffix(imgurURL(node)), | |
referrerPolicy: 'no-referrer' | |
})) | |
} | |
function main() { | |
Array.from(document.querySelectorAll(entry)).forEach(repaste) | |
} |
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
.bbs-content { | |
font-family: monospace; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment