<style> .reveal section img { border-width: 0px; background-color: transparent; } </style> ### HackMD-it ### enhance GitHub with ### open collaborative editor Yukai Huang @TypeScript Switzerland slide: hackmd.io/p/ts-swiss --- We have a collaborative session please prepare laptop or smartphone to join! --- ## Who am I? :construction_worker: - Yukai Huang - Full Stack Developer @HackMD :books: - VSCode :heart: - I use tabs. :cat: --- ## What's <i class="fa fa-file-text" aria-hidden="true"></i> HackMD? <small>Shamelss plug here :laughing:</small> --- ### Let's play with it! :egg: ### hackmd.io/ts-swiss-demo --- ![](https://i.imgur.com/R8GsXZf.jpg) --- ### 70% of our users are developers. Developers :heart: GitHub. --- :tada: --- {%youtube E8Nj7RwXf0s %} --- ### Usage flow --- ![](https://i.imgur.com/2ydKGnA.png) --- ![](https://i.imgur.com/t37uP6D.png) --- ![](https://i.imgur.com/tLAg0fZ.png) --- ![](https://i.imgur.com/svOHcAT.png) --- :pizza: --- ### Extension architecture :house: --- ![](https://i.imgur.com/ij69tPh.png) --- ![](https://i.imgur.com/XnWLsxL.png) --- ## Background script - Run after the extension start - Long run action, web request, heavy works, ... - Kinda backend --- ## Content script - Bind with each page - Manipulate DOM - Add event listeners - Isolated JavaScript environment - It doesn't break things --- ## Injected script - Injected with content script - Accessing global variable - Call global function - Acts as JavaScript inserted with HTML script tag `<script>` --- ### 3 environments --- ![](https://i.imgur.com/XnWLsxL.png) --- :checkered_flag: --- ## cross-environment communication --- ### Case: Sync HackMD with GitHub --- ![](https://i.imgur.com/qxtcCkk.png) --- - We can't send message between two injected scripts - We need to manage flow by ourself - Different set of API - `content <-> background` - `content <-> injected` --- # :fork_and_knife: --- <style> code.blue { color: #337AB7 !important; } code.orange { color: #F7A004 !important; } </style> - <code class="orange">onMessage('event')</code>: Register event listener - <code class="blue">sendMessage('event')</code>: Trigger event --- ### Register event listener --- ![](https://i.imgur.com/hAxj7Si.png) --- ![](https://i.imgur.com/uiJBSGH.png) --- ![](https://i.imgur.com/sRCoSQ0.png) --- ![](https://i.imgur.com/CcVXrVY.png) --- ### Trigger event --- ![](https://i.imgur.com/5WZOxda.png) --- ![](https://i.imgur.com/lhLb3QF.png) --- ![](https://i.imgur.com/tRYLgvZ.png) --- ![](https://i.imgur.com/cdzq6i2.png) --- ### What if we want the result back? --- # :dizzy_face: :expressionless: --- ### It's a pain to bridge events manually --- # :bulb: --- - Dead simple API - Only cares about application logic --- ```typescript import * as Channeru from 'channeru' // setup channel in different page environment, once const channel = Channeru.create() ``` --- ```typescript // in background script const fakeLogin = async () => true channel.answer('isLogin', async () => { return await fakeLogin() }) ``` <br> ```typescript // in inject script const isLogin = await channel.callBackground('isLogin') console.log(isLogin) //-> true ``` --- # :100: :muscle: :tada: --- Our extension is not open sourced for now :sweat_smile: --- Use `crx-bridge` as alternative https://github.com/NeekSandhu/crx-bridge --- ### We :heart: typescript! --- - Strongly Typed: Manage different protocol with ease - IDE Features (I :heart: VSCode) --- ### One more thing --- ### HackDF ##### HackDF keeps Documentation Fresh <small>(`recursive acronym`)</small> hackmd.io/hackdf --- - an GitHub App - Integrate GitHub With HackMD - Remind you when should update documentation - Commit and push documentation changes right on HackMD --- ### Wrap up - Cross envornment commnication - A small library to solve messaging pain - TypeScript Rocks :tada: --- Wishlist --- ### Thank you! :sheep: You can find me on - GitHub ([@Yukaii](https://github.com)) - Twitter ([@yukaii_h](https://twitter.com/yukaii_h)) - or send an email to yukai@hackmd.io
{"metaMigratedAt":"2023-06-14T19:24:00.815Z","metaMigratedFrom":"YAML","title":"TypeScript Switzerland Winter Meetup","breaks":true,"contributors":"[{\"id\":\"6d3b4625-23c8-4275-a28e-cdc2cb546eda\",\"add\":4378,\"del\":114}]"}
    443 views
   owned this note