{"id":289,"date":"2007-03-08T10:31:58","date_gmt":"2007-03-08T17:31:58","guid":{"rendered":"http:\/\/www.red-sweater.com\/blog\/289\/an-even-better-bookmarklet"},"modified":"2007-03-08T10:31:59","modified_gmt":"2007-03-08T17:31:59","slug":"an-even-better-bookmarklet","status":"publish","type":"post","link":"https:\/\/redsweater.com\/blog\/289\/an-even-better-bookmarklet","title":{"rendered":"An Even Better Bookmarklet"},"content":{"rendered":"<p>I&#8217;ve recently seen <a href=\"http:\/\/samuraicoder.net\/double_byte_characters_and_marsedit_bookmarklet\">two<\/a> bug <a href=\"http:\/\/www.red-sweater.com\/forums\/viewtopic.php?pid=477#477\">reports<\/a> about the behavior of the MarsEdit &#8220;Bookmarklet,&#8221; the little link that you can stick in your browser&#8217;s toolbar to easily &#8220;reblog&#8221; stuff that you find on the web. The gist of the problem is that special characters end up getting junked in transition so that they show up as useless parts of escape codes in MarsEdit. That&#8217;s no fun for anybody.<\/p>\n<p>\nFollowing a lead from <a href=\"http:\/\/samuraicoder.net\/\">Takaaki<\/a>, who reported one of the issues, I found what appears to be a sane workaround. The bookmarklet needs to use &#8220;encodeURIComponent&#8221; instead of &#8220;escape&#8221; to sanitize the input strings for the &#8220;magic URL&#8221; that sends the page to MarsEdit. (<a href=\"http:\/\/xkr.us\/articles\/javascript\/encode-compare\/\">Read more<\/a> about the various escaping mechanisms and when to use them).\n<\/p>\n<p>\nThe best part about these bugs is I can release a fix without updating MarsEdit itself. The behavior of MarsEdit seems to be perfect when the bookmarklet is altered to use the proper escaping function. So if you&#8217;ve run into this problem, please give the new bookmarklet a try:\n<\/p>\n<p>\n<a href=\"javascript:var%20baseUrl%20=%20'marsedit:';%20var%20url%20=%20baseUrl;var%20title%20=%20document.title;%20url%20=%20url%20+%20'title='%20+%20encodeURIComponent%20(title);%20var%20currentUrl%20=%20document.location.href;%20url%20=%20url%20+%20'&#038;url='%20+%20encodeURIComponent%20(currentUrl);%20var%20selectedText;%20selectedText%20=%20getSelection%20();%20if%20(selectedText%20!=%20'')%20url%20=%20url%20+%20'&#038;text='%20+%20encodeURIComponent%20(selectedText);document.location.href=url;\">Post with MarsEdit<\/a> (drag link to bookmark bar)\n<\/p>\n<p>\nAnd be sure to let me know if there are other issues which should be addressed in the bookmarklet for the next MarsEdit release.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve recently seen two bug reports about the behavior of the MarsEdit &#8220;Bookmarklet,&#8221; the little link that you can stick in your browser&#8217;s toolbar to easily &#8220;reblog&#8221; stuff that you find on the web. The gist of the problem is that special characters end up getting junked in transition so that they show up as [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40,4],"tags":[],"class_list":["post-289","post","type-post","status-publish","format-standard","hentry","category-marsedit","category-web"],"_links":{"self":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/comments?post=289"}],"version-history":[{"count":0,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/289\/revisions"}],"wp:attachment":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/media?parent=289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/categories?post=289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/tags?post=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}