Last active
March 9, 2018 15:11
-
-
Save neworld/242770b5efb1939b51842587d5f41b03 to your computer and use it in GitHub Desktop.
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 Markdown img to html converter | |
// @namespace neworld | |
// @version 0.2.0 | |
// @description Converts markdown img tag to html | |
// @author Neworld | |
// @match https://*.github.com/* | |
// @grant none | |
// @run-at context-menu | |
// ==/UserScript== | |
function convertMDtoHTML(textArea) { | |
var text = textArea.value; | |
var regex = /!\[.*?\]\((.*?)\)/g; | |
var subst = '<img src="\$1" width="250"/>'; | |
var result = text.replace(regex, subst); | |
textArea.value = result; | |
} | |
function arrayHasOwnIndex(array, prop) { | |
return array.hasOwnProperty(prop) && /^0$|^[1-9]\d*$/.test(prop) && prop <= 4294967294; // 2^32 - 2 | |
} | |
(function() { | |
'use strict'; | |
var areas = document.getElementsByTagName("textarea"); | |
for (var key in areas) { | |
if (arrayHasOwnIndex(areas, key)) { | |
convertMDtoHTML(areas[key]); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment