Last active
June 24, 2025 16:41
-
-
Save fahdmekawy/2a1e33726a747b9a3caf4f462a848cbb to your computer and use it in GitHub Desktop.
Tampermonkey Script – Auto Image Conversion for GitHub
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 GitHub Auto Image Markdown to <img> | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Auto-convert uploaded GitHub image markdown to <img> with width=200 (for PRs, issues, comments) | |
// @match https://github.com/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
const imageMarkdownRegex = /!\[([^\]]*?)\]\((https:\/\/(?:user-images\.githubusercontent\.com|github\.com\/user-attachments\/assets)\/[^\)]+)\)/g; | |
function convertMarkdownToImg(textarea) { | |
if (!textarea || !textarea.value) return; | |
const original = textarea.value; | |
const converted = original.replace( | |
imageMarkdownRegex, | |
(_match, alt, url) => `<img src="${url}" alt="${alt}" width="200" />` | |
); | |
if (converted !== original) { | |
textarea.value = converted; | |
} | |
} | |
function checkAllTextareas() { | |
const textareas = document.querySelectorAll('textarea'); | |
textareas.forEach(convertMarkdownToImg); | |
} | |
// Check every second to catch uploads | |
setInterval(checkAllTextareas, 1000); | |
console.log("✅ GitHub image conversion script running."); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment