Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Wizmann
Last active June 14, 2023 13:29
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save Wizmann/605ff2a609348b6ec3a3 to your computer and use it in GitHub Desktop.
Save Wizmann/605ff2a609348b6ec3a3 to your computer and use it in GitHub Desktop.
workflowy-with-image.js
// ==UserScript==
// @name New Userscript
// @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';
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"><img src="' + img[1] + '"/></div>')
}
}
function parseImg() {
$("div.notes div.content").live("click keyup", do_parseImg);
$("div.notes div.content").each(do_parseImg);
$("#expandButton").live("click", function() {
$("div.notes div.content").each(do_parseImg);
});
};
$(window).bind("load hashchange", parseImg);
@SplitZadar
Copy link

SplitZadar commented Jun 26, 2017

@incace works like a charm

My improvement:
![75](http://i.imgur.com/R72rW81.jpg) will resize image to 75%

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]);
        console.log(i, img[2]);
        
        if (img[1] === "") {
            img[1] = 100;
        }
        
        $(this).after('<div class="content-img"><img width="' + img[1] + '%" height="'+ img[1] +'%" src="' + img[2] + '"/></div>')
    }
}

@abbood
Copy link

abbood commented Sep 22, 2017

this code is outdated.. it simply doens't work with me

  • first i added this line
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js

then i'm getting this error:
screen shot 2017-09-22 at 10 04 09 am

@Wizmann
Copy link
Author

Wizmann commented Dec 27, 2017

@abbood

working on that

sorry for the inconvenience

@lasares
Copy link

lasares commented Mar 19, 2018

Hi Wizmann! Thanks for your work. Any hope for an upgrade on this one sometime in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment