-
-
Save leo424y/d1dc4cdb5189c25ede65 to your computer and use it in GitHub Desktop.
workflowy-with-image.js
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 Workflowy markdown tags with images -> images | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://workflowy.com/* | |
// @grant none | |
// ==/UserScript== | |
/* jshint -W097 */ | |
'use strict'; | |
// you can just use markdown images like | |
// ![what](http://i.imgur.com/R72rW81.jpg) | |
function do_parseImg() { | |
$(this).nextAll(".content-img").remove(); | |
var lines = $(this).text().split("\n"); | |
var img_re = /^\!\[(.*)\]\((.+)\)$/; | |
for (var i = 0; i < lines.length; i++) { | |
var line = lines[i].trim(); | |
var img = line.match(img_re); | |
if (img === null) { | |
continue; | |
} | |
console.log(i, img[1]); | |
$(this).after('<div class="content-img" style="text-align: center"><img src="' + img[2] + '" alt="' + img[1] + '" title="' + img[1] + '" width="400"/></div>') | |
} | |
} | |
function parseImg() { | |
$("div.notes div.content").live("click keyup", do_parseImg); | |
$("div.notes div.content").each(do_parseImg); | |
}; | |
$(window).bind("load hashchange", parseImg); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment