-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-replace.js
46 lines (43 loc) · 1.36 KB
/
github-replace.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// ==UserScript==
// @name GH Markdown to HTML Image
// @namespace https://tampermonkey.net/
// @match https://*.github.com/*
// @version 1.0.2
// @updateURL https://raw.githubusercontent.com/darkvillager2/Public-Userscripts/refs/heads/main/github-replace.js
// @downloadURL https://raw.githubusercontent.com/darkvillager2/Public-Userscripts/refs/heads/main/github-replace.js
// @author Dark_Ville
// @description replace markdown image with html
// @grant GM_addElement
// ==/UserScript==
function addScript() {
const script = `function replaceMD() {
let tb = document.querySelector('textarea[id*="issue"]')
if (tb) {
const reg = new RegExp(/!\[Screenshot_[0-9]*\][(]/gm);
tb['value'] = tb?.value
?.replace(reg, '<img src="')
.replace(/[)]/gm, '">');
}
}`;
GM_addElement('script', {
textContent: script,
});
setTimeout(addButton, 5000);
}
function addButton() {
const el = document.querySelector('[aria-label="Preview"]');
GM_addElement(el, 'button', {
class: 'customButton',
type: 'button',
textContent: 'Change images',
});
console.log('y');
document.querySelector('.customButton').addEventListener('click', replaceMD);
}
addScript();
let tb = document.querySelector('.CommentBox-container > textarea');
if (tb) {
tb['value'] = tb?.value
?.replace(/!\[Screenshot_([0-9]*)\]\(/gm, '<img src="')
.replace(/\)/gm, '">');
}