<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cat Chen</title>
    <description>The latest articles on DEV Community by Cat Chen (@catchen).</description>
    <link>https://dev.to/catchen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F112822%2F027e15a1-fd6f-4dd1-b770-0e0561277725.jpeg</url>
      <title>DEV Community: Cat Chen</title>
      <link>https://dev.to/catchen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/catchen"/>
    <language>en</language>
    <item>
      <title>Progressive Web App as Share Target on Android</title>
      <dc:creator>Cat Chen</dc:creator>
      <pubDate>Wed, 13 Nov 2019 06:35:00 +0000</pubDate>
      <link>https://dev.to/catchen/progressive-web-app-as-share-target-on-android-775</link>
      <guid>https://dev.to/catchen/progressive-web-app-as-share-target-on-android-775</guid>
      <description>&lt;p&gt;I built a PWA (Progressive Web App) to trace shortened URL back to its original URL. (You can find it &lt;a href="https://traceurl.catchen.app/"&gt;here&lt;/a&gt;.) I don’t want to copy a URL and paste it into my app. I want to use the Android’s &lt;a href="https://developer.android.com/training/sharing/send"&gt;sharesheet&lt;/a&gt; to send any link in Chrome straight to my app. How do I do that?&lt;/p&gt;

&lt;p&gt;Google provides &lt;a href="https://developers.google.com/web/updates/2018/12/web-share-target"&gt;good documentation&lt;/a&gt; on this. We need to add a &lt;code&gt;share_target&lt;/code&gt; section in &lt;code&gt;manifest.json&lt;/code&gt; and then declare that our PWA can act as a share target. Most of the properties in this section can be thought of as attributes on a &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; element with the same name. For example, &lt;code&gt;{ "action": "/share", "method": "POST" }&lt;/code&gt; is like &lt;code&gt;&amp;lt;form action="/share" method="POST"&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;params&lt;/code&gt; subsection let us change parameter names if we already have a convension of naming search parameters in GET requests or form fields in POST requests. Otherwise, we can keep them in their original names. One caveat is Android doesn’t use &lt;code&gt;url&lt;/code&gt; parameter so when sharing a URL it comes through the &lt;code&gt;text&lt;/code&gt; parameter. In my app I need to coalesce these two parameters to get the input from the user.&lt;/p&gt;

&lt;p&gt;Is there more? Yes! Twitter makes a great PWA and we can check their &lt;a href="https://twitter.com/manifest.json"&gt;&lt;code&gt;manifest.json&lt;/code&gt;&lt;/a&gt;. Here’s the beautified version of the &lt;code&gt;share_target&lt;/code&gt; section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"share_target": { "action": "compose/tweet", "enctype": "multipart/form-data", "method": "POST", "params": { "title": "title", "text": "text", "url": "url", "files": [{ "name": "externalMedia", "accept": [ "image/jpeg", "image/png", "image/gif", "video/quicktime", "video/mp4"] } ] }}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It has a &lt;code&gt;files&lt;/code&gt; subsection under the &lt;code&gt;params&lt;/code&gt; section. This is part of the &lt;a href="https://wicg.github.io/web-share-target/level-2/#sharetargetfiles-and-its-members"&gt;Web Share Target Level 2&lt;/a&gt;. We can accept files from sharesheet and we can assign a file to different parameter name based on MIME type or file extension. My app doesn’t need this capability but it’s good to know what’s possible.&lt;/p&gt;

&lt;p&gt;If you like my post, you can subscribe through &lt;a href="https://chen.cat/subscribe-to-blogs"&gt;email&lt;/a&gt; or &lt;a href="http://feedproxy.google.com/CatChen/English"&gt;RSS/Atom&lt;/a&gt;. That makes sure you won’t miss my future posts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UuBN2wr3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://feeds.feedburner.com/%257Er/CatChen/English/%257E4/1vs6yymgdnQ" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UuBN2wr3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://feeds.feedburner.com/%257Er/CatChen/English/%257E4/1vs6yymgdnQ" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>progressivewebapp</category>
      <category>sharetarget</category>
      <category>sharesheet</category>
    </item>
    <item>
      <title>Batch Sending Email with Attachments through AppleScript</title>
      <dc:creator>Cat Chen</dc:creator>
      <pubDate>Wed, 06 Nov 2019 17:46:00 +0000</pubDate>
      <link>https://dev.to/catchen/batch-sending-email-with-attachments-through-applescript-4lke</link>
      <guid>https://dev.to/catchen/batch-sending-email-with-attachments-through-applescript-4lke</guid>
      <description>&lt;p&gt;I want to learn a little bit of AppleScript. I need to help a friend send out emails to welcome new students to the school. The requirements are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;addressing each recipient by their name in email content;&lt;/li&gt;
&lt;li&gt;attaching the same file in all emails.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After some research and tinkering I have a script to send emails:&lt;/p&gt;



&lt;p&gt;&lt;code&gt;theRecipients&lt;/code&gt; is the list of recipient names and email addresses. This is for requirement #1. &lt;code&gt;theAttachment&lt;/code&gt; isn’t hardcoded to any file path. It will prompt and let me choose a file when I run the AppleScript.&lt;/p&gt;

&lt;p&gt;The trickiest part is the &lt;code&gt;delay 1&lt;/code&gt;. Without this line, emails will be sent without the attachment. It’s a hack to make sure each email has the attachment. I don’t know why it works and I can’t find an explanation online.&lt;/p&gt;

&lt;p&gt;After building this AppleScript, I learn that Google App Script is another great way to automate sending emails through Gmail (or GSuite). I will learn App Script and write a post about that next time. If you like this kind of posts, you can subscribe through &lt;a href="https://chen.cat/subscribe-to-blogs"&gt;email&lt;/a&gt; or &lt;a href="http://feedproxy.google.com/CatChen/English"&gt;RSS/Atom&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VJv7Wc_4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://feeds.feedburner.com/%257Er/CatChen/English/%257E4/hfpinDLIMjY" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VJv7Wc_4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://feeds.feedburner.com/%257Er/CatChen/English/%257E4/hfpinDLIMjY" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>applescript</category>
      <category>automation</category>
      <category>email</category>
      <category>mail</category>
    </item>
    <item>
      <title>MailChimp Popup Dialog on Click</title>
      <dc:creator>Cat Chen</dc:creator>
      <pubDate>Tue, 24 Sep 2019 17:42:00 +0000</pubDate>
      <link>https://dev.to/catchen/mailchimp-popup-dialog-on-click-4h08</link>
      <guid>https://dev.to/catchen/mailchimp-popup-dialog-on-click-4h08</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;MailChimp provides sign-up form as pop-up dialog, but has limited options for when to trigger it. Available triggers are like “immediately after the page is open”, “when the user scrolls to the bottom of the page”, etc. &lt;strong&gt;I want to trigger the dialog when a reader clicks the sign-up link on my blog.&lt;/strong&gt; Instead of navigating to the sign-up page, I want to open the dialog and speed up the experience. I hope this can improve subscription rate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;MailChimp provides an HTML snippet for the pop-up dialog. It contains two &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags. I left the first one untouched and modified the second one. Read the code below for reference:&lt;/p&gt;



&lt;p&gt;In the first &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag, I did nothing. In the second &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag, I wrapped the original JavaScript in a function called &lt;code&gt;displayDialog&lt;/code&gt;, which will be called in the sign-up link’s click event. I added a third &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag to search for sign-up links in the page and add the click event handler.&lt;/p&gt;

&lt;p&gt;Within &lt;code&gt;displayDialog&lt;/code&gt; function, I not only call the original code in the second &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag but also delete two cookies before that. That’s because MailChimp set one of these cookies when a user dismisses the dialog or subscribes through the dialog. The presence of one of the cookies will prevent the dialog from opening again. This behavior makes sense when using MailChimp’s automatic triggers – a user shouldn’t see a dialog again after either dismissing or subscribing. It doesn’t make sense when the trigger is user clicking a link because it’s a clear intention to open the dialog. &lt;strong&gt;(If you want to reuse my code, remember to replace &lt;code&gt;window.dojoRequire(...)&lt;/code&gt; with the code from your own MailChimp campaign.)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The third &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag is customized for my own blog. It looks for any link that points to the sign-up page and add the click event handler. The event handler calls &lt;code&gt;displayDialog&lt;/code&gt; to trigger the dialog and then cancels the browser’s navigation to the sign-up page.&lt;/p&gt;

&lt;p&gt;If you want to test this feature, make sure you open this post from my blog and &lt;a href="https://chen.cat/subscribe-to-blogs"&gt;click this link to subscribe&lt;/a&gt;. It should open the sign-up dialog instead of the sign-up page. If you like this post, remember to put in your email and subscribe!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PzXxuNG8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://feeds.feedburner.com/%257Er/CatChen/English/%257E4/w6zmPW0iFsQ" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PzXxuNG8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://feeds.feedburner.com/%257Er/CatChen/English/%257E4/w6zmPW0iFsQ" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>mail</category>
      <category>mailchimp</category>
      <category>popup</category>
    </item>
    <item>
      <title>Harp/Jade Debug Snippet</title>
      <dc:creator>Cat Chen</dc:creator>
      <pubDate>Fri, 31 Aug 2018 14:59:00 +0000</pubDate>
      <link>https://dev.to/catchen/harp-jade-debug-snippet-1i1e</link>
      <guid>https://dev.to/catchen/harp-jade-debug-snippet-1i1e</guid>
      <description>&lt;p&gt;I’m using &lt;a href="http://harpjs.com/"&gt;Harp&lt;/a&gt; with &lt;a href="http://jade-lang.com/"&gt;Jade&lt;/a&gt; recently. At the beginning, it was hard for me to figure out the JSON data structure used by Harp at build time. It was also hard to debug JavaScript function written in Jade and executed at Harp compile time. In the end, I figured out that I could dump that JSON as a string to &lt;code&gt;console.log&lt;/code&gt; in browser. Everything is so much easier now.&lt;/p&gt;



&lt;p&gt;Now I have that &lt;a href="https://github.com/CatChen/catchen.me/blob/master/public/_partials/debug.jade"&gt;&lt;code&gt;debug.jade&lt;/code&gt;&lt;/a&gt; file in &lt;a href="https://github.com/CatChen/catchen.me"&gt;my project&lt;/a&gt;. Whenever I want to examine some JSON data in Harp, I just call &lt;code&gt;!= partial('debug', { data: anything })&lt;/code&gt; and pass the right &lt;code&gt;data&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tcX_JzaN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://feeds.feedburner.com/%257Er/CatChen/English/%257E4/4ZBj4VXAuwU" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tcX_JzaN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://feeds.feedburner.com/%257Er/CatChen/English/%257E4/4ZBj4VXAuwU" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>debug</category>
      <category>harp</category>
      <category>jade</category>
    </item>
  </channel>
</rss>
