Marty McGuire

Posts Tagged javascript

2023
Tue May 23

A little "bookmarklets toolset"

Browser bookmarks can run little bits of javascript on the current page if you use a "javascript:" URL. Folks often refer to these as "bookmarklets". (I wish they worked well in mobile browsers like iOS Safari, but that's a rant...)

Constructing scripts in a URL-safe format can be super frustrating! But today I expanded my "dev tools" for building bookmarklets:

The Firefox dev tools console is a great way to try out your code in-place on the actual page where you want to run it. Press "Ctrl+b" (or "Cmd+b" if you are a Mac person) and the console editor goes into multiline mode! This makes it much easier to edit little scripts! In multiline mode, you "submit" by pressing "Ctrl+Enter" (or "Cmd+Enter" etc).

Duckduckgo has a built-in tool for Javascript beautifying and minifying! It pops up when you search duckduckgo for "javascript minifier". This makes it easy to go from a readable script with newlines and other formatting in your console, to a minimized compact scriptlet suitable for a bookmarklet. Even better, it lets you go back and forth between a minimized script and a readable one so you can tweak your bookmarklets in the future.

Finally, and in some ways most importantly, bookmarklets need to be properly URL-encoded. Enter Marek Gibney's Bookmarklet Editor, which uses a single textarea and lets you convert between a script and its encoded "javascript:..." version.

The minifier/beautifier and bookmarklet editor are web tools, so the usual caveats apply about data privacy. In theory they are running purely in your browser and not sending data anywhere. But they could! So keep that in your threat model.

2020
Mon Sep 14
🔖 Bookmarked Webster’s Dictionary Defines “View Source” As... - Jim Nielsen’s Weblog https://blog.jim-nielsen.com/2020/the-meaning-of-view-source/

“The “before” HTML I looked at was the raw HTML sent over the wire. The “after” HTML I looked at was a stringification of the DOM after a couple seconds of first requesting the URL. The string is a representation of what the browser decides to output if you click “Edit as HTML” on the root DOM node and then copy it. In other words, it’s the browser’s version of saying “you input HTML, I parsed it, executed relevant JavaScript, and now have this HTML representation.””

2018
Fri Jan 12
🔖 Bookmarked Object models / fuzzy notepad https://eev.ee/blog/2017/11/28/object-models/

“We could do with more experimentation around how objects work, but that’s impossible in the languages most commonly thought of as object-oriented.

Here, then, is a (very) brief run through the inner workings of objects in four very dynamic languages. I don’t think I really appreciated objects until I’d spent some time with Python, and I hope this can help someone else whet their own appetite.”

2011
Sat Feb 26

Thing-a-Day 2011 #26 - "Improved" scribbling in JavaScript

This post used to be on Posterous. I rescued my posts before Posterous shut down and am now sharing them here.

I played with the mouse coordinate handling a bit to try and compensate for the rotation, but it's still not great. For some reason, up-and-down movements seem to track well, but left-right movement causes the drawing point to move up and down relative to the cursor.

My guess is that I am just being bad at "the maths" and that I'll get it figured out later. :)

Rendering of a sticky note with rendered Hershey script font text and scribbling. The rendered text is 12 repetitions of the word 'derp' and the scribbles spell out 'Drawing is hard'.
Play here: http://schmarty.net/hershey_js_demo/
Fri Feb 25

Thing-a-Day 2011 #25 - Scribbling in SVG (+Hershey font typing)

This post used to be on Posterous. I rescued my posts before Posterous shut down and am now sharing them here.

Added some scribbling to my little JavaScript app, which also gets saved to the SVG.

It's not great (my insistence on making these things map to the sticky note image means they don't line up right with the mouse), but it works!

Screenshot of web interface with text area entry, rendered text in Hershey script font and a squiggly drawing, and a text area containing SVG code output. The text says: Type! (or draw).
As before, you can play with it here: http://schmarty.net/hershey_js_demo/
Wed Feb 23

Thing-a-Day 2011 #23 - SVG Output for Hershey fonts in JavaScript

This post used to be on Posterous. I rescued my posts before Posterous shut down and am now sharing them here.

I really wanted to get SVG manipulation going in this demo, so I have ported the rendering (once again), this time using the jQuery SVG lib, which is really nice and easy to use: http://keith-wood.name/svg.html

Screenshot of web interface with text area and rendered text in Hershey script font above a sticky note background. Text reads: Hello there, peeps. This looks okay! Woo! What is up? Check it out, it even still resizes correctly! Boosh!
You can play with it here: http://schmarty.net/hershey_js_demo/index.html
Tue Feb 22

Thing-a-Day 2011 #22 - Hershey Fonts in JS - on a Sticky Note!

This post used to be on Posterous. I rescued my posts before Posterous shut down and am now sharing them here.

Ok, this is more a kind of clever image arrangement than anything else, but it looks nice, I think.

Screenshot of web interface with a text area and rendered text in Hershey script font. The rendered text is at an angle and atop a background image as though it is written on a sticky note. There is a great deal of text, causing the font size to be reduced. It is filler text, so I won't repeat it here.

You can play with it here: http://schmarty.net/hershey_js_demo/index.html

Until I change it again!

Mon Feb 21

Thing-a-Day 2011 #21 - Auto-scaling Hershey fonts in JavaScript

This post used to be on Posterous. I rescued my posts before Posterous shut down and am now sharing them here.

Ok, this is kind of fun, even though the code is very naive.

I've added a height-check at the end of my line-breaking code. If there are too many lines of text to fit within the allowed space, the algorithm will rescale everything and try again:

Screenshot of web app with text area and rendered text in Hershey script font. There are many lines of text, and the font has been downsized to fit more text. It's a lot of filler text that I won't repeat here.
This isn't great for real-time text flow, but it is fine for fitting text, I think.
Sun Feb 20

Thing-a-Day 2011 #20 - Hershey fonts in JavaScript on the canvas

This post used to be on Posterous. I rescued my posts before Posterous shut down and am now sharing them here.

I haven't been making as much progress on my "draw things in the browser so a robot can draw them on the Unicorn" project, so I decided to take a stab at cleaning things up a little to make that easier.

Today I rewrote my little demo to use canvas 2D instead of Raphael.js.  It looks the same, for the most part:

Screenshot of web interface with text area and rendered text in Hershey script font. Text reads: Hmm. Oh, this is better. I wonder if it slows down all crazy? I guess not! That is awesome. Feeling pretty good about this whole canvas thing. It's almost good enough for real-time typing. Yeah!
But being in canvas land instead of Raphael land means I can do real stacked transforms easily, without having to keep track of them myself. For instance: ROTATION!

Screenshot of web interface with text area and rendered text in Hershey font. The text is tilted to the right at an angle. It reads: Woah! This is crazy!
Thu Feb 17

Thing-a-Day 2011 #17 - Simple line-wrapping for Hershey JS demo

This post used to be on Posterous. I rescued my posts before Posterous shut down and am now sharing them here.

I've decided to slowly expand this drawing-stuff-in-the-browser demo, and added some simple line-wrapping to the code on my demo page:

http://schmarty.net/hershey_js_demo/

Word wrapping is an interesting topic, and I hope to get this cleaned up a bit with features like breaking up words if they are too long, improving the algorithm to make nicer "squared" paragraphs, etc.

Screenshot of a web interface with text area and rendered text in Hershey script font. Text reads: Oh man, check it out, this line is gonna wrap at some point. Indeed, there it went.