ã¢ã€ãã¢ã¯ãåžžã«æå ã«ããéçºè çšã®ã¿ã¹ã¯ãããŒãžã£ãŒãäœæããããšã§ããïŒããã ãã§ã¯ãããŸããïŒã çŸåšã®trelloããã³jiraãã±ãã ã gitlabãžã®ãªã¯ãšã¹ããªã©ã衚瀺ãããŠããã¯ãã§ãã ãããã¯ããã©ãŠã¶ã®ã¢ãã¬ã¹ããŒã«ãjira PM-20ããªã©ã®ããŒã¯ãŒããå ¥åããããšã§éåžžæ¢ããŠãããã®ã§ãã
Chromeæ¡åŒµæ©èœ
ãã©ãŠã¶ãŒã®æ¡åŒµæ©èœã¯ãjsã¹ã¯ãªããã䜿çšããéåžžã®htmlããŒãžã§ããããšã¯ç¢ºãã§ãã ãããã圌ã¯ããããäœæããæ¹æ³ãç¥ããŸããã§ããã Googleããã®åé¡ã«é¢ããŠæåã«ç§ã«ãããã®ã¯ãå ¬åŒã®ææžã§ã¯ãªããäžçšåºŠã®èšäºã§ãã ã ããã¯ããã«è¯ãã£ãããªããªã ã¢ã€ãã¢ããåºçãŸã§ã®æãåçŽãªãŠã£ãžã§ããã®ã¬ãã¥ãŒèšäºã§ããã
ãã®èšäºã¯ãããŠã£ãžã§ãããã®éçºã¯ããã»ã©ããªãããŒã§ã¯ãªããšããèããäžããŠãããŸããã ç§ã¯ããã«ãhello worldïŒãã®äœæãéå§ããŸããã
æ§é
ãããžã§ã¯ãã®ã«ãŒãã«mainfest.jsonãäœæããå¿ èŠãããããšãããããŸããã ååã説æãäœæè ãã¢ã€ã³ã³ãèš±å¯ãªã©ãæ¡åŒµåã«ã€ããŠèª¬æããŸãã ããã¥ã¡ã³ããå匷ããã«æåã®ããŒãžã§ã³ãäœæããŸããã
æåã®manifest.json
æ¡åŒµæ©èœã䜿çšãããšãjsã¹ã¯ãªãããããã¯ã°ã©ãŠã³ãã§å®è¡ã§ããŸããããã«ããããŠãŒã¶ãŒã䜿çšããŠããªãå Žåã§ãäœããå®è¡ã§ããŸãã ãã®æ©èœãéåžžã«è¡šé¢çã«æããããã®ã¯ããããã©ã®ããã«æ©èœããããç解ããããã ãã§ãã 圌ã¯<h1>ãŠã£ãžã§ããã®ã¿ã€ãã«ãå€æŽããŸããã
ç§ãèå³ãæã£ãŠããã®ã¯ããã©ãŠã¶ã§ã¢ã€ã³ã³ãã¯ãªãã¯ãããšè¡šç€ºãããhtmlããŒãžèªäœã§ããããã§ã¹ãã§ã¯popup.htmlãšåŒã°ããŸãã
ã¡ãªã¿ã«ããã®ããŒãžã¯ä»ã®ãµã€ããšåæ§ã«ãã©ãŠã¶ã§éãããšãã§ããŸããããããã³ã«ããšããŠã®ã¿chrome-extensionããããŸããããšãã°ã chrome-extensionïŒ// id- widget-in-webstore / popup.htmlã§ãã ãããã£ãŠãã€ã³ã¹ããŒã«ããæ¡åŒµæ©èœã®ãœãŒã¹ã衚瀺ã§ããŸãã
ããã€ãã®æ©èœãé€ããŠãä»ã®Webãµã€ããšåãããã«æ©èœããŸããããšãã°ãã¯ãªãã¯ãªã³ã¯ã¯target = "_ blank"ã§ã®ã¿æ©èœããŸãã éçºè ã«ãã£ãŠå¶åŸ¡ãããæè¡çãªå¶éããããŸããããšãã°ããŠãŒã¶ãŒããèŠæ±ãããã³ã³ãã³ãã»ãã¥ãªãã£ããªã·ãŒããã©ãŠã¶æ©èœãžã®ã¢ã¯ã»ã¹èš±å¯ãªã©ã§ãã
å®è¡æ¡åŒµæ©èœ
manifest.jsonãšpopup.htmlãå éšã«å«ããã©ã«ããŒãäœæããããããããŠã£ãžã§ãããšããŠæ¢ã«èµ·åã§ããŸãã chromeïŒ//æ¡åŒµæ©èœchromeïŒ//æ¡åŒµæ©èœãµãŒãã¹ããŒãžã«ã¯ã 解åãããæ¡åŒµæ©èœã®ããŠã³ããŒããã¿ã³ããããŸãã ããã䜿çšããŠããã©ã«ããéžæããŸã
æ¡åŒµæ©èœã¯ã¢ãã¬ã¹ããŒã®æšªã«ããããŠã£ãžã§ãããã®ãªã¹ãã«ããã«è¡šç€ºãããŸãã
ãã®æç¹ãããæ¡åŒµæ©èœã¯ãã§ã«ãã¹ãã§ããŸãïŒ popup.htmlãå€æŽããã¢ã€ã³ã³ãã¯ãªãã¯ã㊠ããŠã£ãžã§ããããå床éããŠå€æŽã確èªããŸãã
ãŠã§ãã¹ãã¢ã«å ¬éãã
ãããããæåã®20åã®æ¡åŒµæ©èœãå ¬éããã«ã¯5ãã«ããããŸãã ããã¯ããŠã§ãã¹ãã¢ã®ããã·ã¥ããŒãã§è¡ãããŸãããã®ããã«ã¯ãæ¡åŒµãã©ã«ããŒã®ã³ã³ãã³ãã®zipã¢ãŒã«ã€ãã«èšå ¥ããããã¹ããšåçã®åºåã§äœæ¥ããå¿ èŠããããŸãã
æ¡åŒµæ©èœã®å ¬éã®æºå
æ¡åŒµæ©èœã®èª¬æã®æåã®éšåã¯æ¡åŒµæ©èœãããã§ã¹ãã®descriptionããããã£ãã衚瀺ãããæ®ãã¯Webã¹ãã¢ã®æ¡åŒµæ©èœç®¡çã®è©³çŽ°ãªèª¬æã«è¿œå ãããŸãã
æ¡åŒµæ©èœã«ã¯æè»ãªå ¬éèšå®ããããŸããå ¬éããäžçã®å°åãšæ¡åŒµæ©èœã®å¯èŠæ§ãéžæã§ããŸãã
ãã·ã¢é£éŠã®ã¿ãå ¬éããããšãéžæããå Žåãä»ã®åœã§ã¯æ¡åŒµåã¯è¡šç€ºãããªãããšã«æ³šæããŠãã ããã ã¿ã€ã«ããéã«ç§ã¯ããã«åºããããŸããã2æ¥åŸã«ãæ¡åŒµåãçŽæ¥ã®ååã§ãã¹ãã¢ã§æ€çŽ¢ãããªãçç±ãç解ã§ããŸããã§ããã
é«åºŠãªãªãã·ã§ã³
ããã»ã¹ãæ確ã«ãªãããã«ãæãåçŽãªæ¡åŒµæ©èœãå ¬éããããã«å¿ èŠãªæé ã説æããŸããã 次ã«ãããè€éãªããŠã£ãžã§ããããäœæããããã®è©³çŽ°ã匷調ããŸãã
ç§ã®æ¡åŒµæ©èœã®æ¬è³ªã¯ãä»ã®äººã®APIã䜿çšããŠæ å ±ãååŸããããšã§ãã ãããè¡ãã«ã¯ãå°ãªããšãlocalStorageã§èªèšŒããŒã¯ã³ãèšæ¶ããå¿ èŠããããŸãã
ç§ã¯ãããã§ã¹ãã§ãèš±å¯ãïŒ[ãã¹ãã¬ãŒãžã]ã䜿çšããŸããã
OAuth2
ã»ãšãã©ã®å ŽåãAPIéçºè ã¯æ¿èªã®ããã«OAuth2ãããã³ã«ãæäŸããŸãã
ãã®ãããã³ã«ã«ç²ŸéããŠããªãå ŽåïŒãã®ã¢ããªã±ãŒã·ã§ã³ãããã°ã€ã³/ãã¹ã¯ãŒãã«ã¢ã¯ã»ã¹ããããšãªãããŠãŒã¶ãŒã«ä»£ãã£ãŠã¢ããªã±ãŒã·ã§ã³ã«å®å šãªèªèšŒããã³æ¿èªããã»ã¹ãæäŸããŸãã
ãããã³ã«ã¯æ¿èªã®ããã®ããã€ãã®ã¡ãœããã«ã€ããŠèª¬æããŸã ã çæ³çã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã«ããã¯ãšã³ããããããšãåæãšããèªèšŒã³ãŒããããŒã䜿çšããå¿ èŠããããŸã ã APIã¯ãAuthã³ãŒãã䜿çšããŠãŠãŒã¶ãŒãã¢ããªã±ãŒã·ã§ã³ã«ãªãã€ã¬ã¯ãããããã¯ãšã³ãã®ã¢ããªã±ãŒã·ã§ã³ã¯ãããããŒã¯ã³ãšäº€æããŸãã
ããã¯ãšã³ããªãã§ãã°ã€ã³ã§ããåçŽåãããæé»çãªãããŒããããŸããæ¿èªåŸãAPIã¯URLã®ããŒã¯ã³ã䜿çšããŠãŠãŒã¶ãŒãã¢ããªã±ãŒã·ã§ã³ã«ãªãã€ã¬ã¯ãããŸãã
Chromeã®æ¡åŒµæ©èœã§ãã®ããªãã€ã¬ã¯ããèªèšŒã䜿çšããæ¹æ³ã¯ïŒ ãŠã§ããµã€ããéå§ããŸããïŒ ããã¯å¿ èŠã§ã¯ãªãããšãå€æããŸããã
æŸèæ
æåã¯ãGitralbãšTrelloãšã®çµ±åãéå§ããŸããã Gitlabã§ã¯ããã¹ãŠããã·ã³ãã«ãã§ããããšãå€æããŸããããŠãŒã¶ãŒãGitlabã®ç®¡çããã«ã«éããããŒã¯ã³ãäœæããŠãŠãŒã¶ãŒã«æž¡ãããã«ããŸãã ç§ã¯é·ãéãã®ã¢ãããŒãã«ç ©ããããå¿ èŠã¯ãããŸããã§ãããããŒã¯ã³ãå ¥åããããã®ãã£ãŒã«ããäœæãããããååŸããæ¹æ³ã説æããŸããã
Trelloã¯OAuth2ãæäŸããŸãããã æé»ã®ãããŒãããããšã«ããã«æ°ä»ããŸããããå°ãå¥åŠã§ããããŒã¯ã³ã¯ããã®ãã©ãŒã ã®/æ¿èªããŒãžã«è¡šç€ºãããŸã
ããã«æ·±ãããããšãªããæ¡åŒµæ©èœã«ããŒã¯ã³å ¥åãã£ãŒã«ããäœæãããã®æ¹æ³ããŠãŒã¶ãŒã«èª¬æããŸããã
æ£ããæ¹æ³
ãã€ãã®ããã«ãè¯ã決å®ã¯ããã«ã¯æ¥ãŸããã æ¿èªã³ãŒããããŒã®ã¿ãåããJiraãšã®çµ±åãéå§ãããšãã«ããã®åé¡ã«åºäŒããŸããã
ã©ãããããããç§ã¯chrome.identityã«åºããããŸãã ãããã¯ãæ¿èªã®ããã®ãã¹ãŠã®ã ã¯ã©ã³ã ãããã§ã«å®è£ ããŠãããã©ãŠã¶ãŒæ©èœã§ãã ãã®æ©èœã«ã¯ããããã§ã¹ãã®ã¢ã¯ã»ã¹èš±å¯ã«IDãå«ããå¿ èŠããããŸãã ãããã§ã¹ããè£è¶³ããŸããïŒ "permissions"ïŒ["storage"ã "identity"] ã
åè¿°ã®ãšãããåæ¡åŒµæ©èœã«ã¯chrome-extensionã®ãããªURLããããŸãïŒ// <id> / ã ãã®ãããªã¢ãã¬ã¹ã¯äœã«ãäžåãã§ããã chrome.identityã¯å®éã®URL httpsïŒ// <app-id> .chromiumapp.org / *ãæäŸããŸããããã¯ãOAuth2ãredirectUrlãšããŠAPIã«æž¡ãããšãã§ããŸãã æ¿èªåŸãAPIã¯ãŠãŒã¶ãŒã«è¿œå ã®ãã©ã¡ãŒã¿ãŒïŒauthCodeãŸãã¯ããŒã¯ã³ïŒãéä¿¡ããchromeã¯ããããååŸããŠãæ¡åŒµæ©èœãjs-callbackã«æž¡ããŸãã
ãããè¡ãã«ã¯ãchrome.identity.launchWebAuthFlowïŒïŒã䜿çšããŸããããã«ãããæ°ãããŠã£ã³ããŠã§APIèªèšŒããŒãžãéããŸãã
chrome.identity.launchWebAuthFlow( { 'url': JiraApi.url(), 'interactive': true }, jira.callback() );
ããã«èšããŸãããã®ãŠã£ã³ããŠã¯ã¡ã€ã³ã®ãã©ãŠã¶ãŠã£ã³ããŠãšãŸã£ããåãã§ã¯ãããŸãããéåžžã®ãŠãŒã¶ãŒã®å Žåã¯ã ãŠã£ã³ããŠã§ã¯ãªãããã£ãã·ã³ã°ãããã¯ã®ãããªãã®ã§ãã ãã¶ãããã¯ç§ã®èªèã§ãããå€åããã¯ç§ã®OSã§ã®ã¿ã§ãã
èªèšŒãŠã£ã³ããŠchrome.identity.launchWebAuthFlow
ãã®ä»ã®ãªãã·ã§ã³
æ©èœãå®è£ ãããšããã¢ã€ãã¢ãçŸããããGoogle Chrome APIããå§ãããŸãã äœæ¥ã容æã«ããåæ§ã®æ©èœãæ¢ã«å€æ°ãããŸãã ããšãã°ãå®å šãªmanifest.jsonã¯å°è±¡çã§ãã
{ // Required "app": { "background": { // Optional "scripts": ["background.js"] } }, "manifest_version": 2, "name": "My App", "version": "versionString", // Recommended "default_locale": "en", "description": "A plain text description", "icons": {...}, // Optional "action_handlers": ["new_note"], "author": ..., "automation": ..., "bluetooth": { "uuids": ["1105", "1006"] }, "commands": {...}, "current_locale": ..., "event_rules": [{...}], "externally_connectable": { "matches": ["*://*.example.com/*"] }, "file_handlers": {...}, "file_system_provider_capabilities": { "configurable": true, "multiple_mounts": true, "source": "network" }, "import": [{"id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}], "key": "publicKey", "kiosk": { "always_update": ..., "required_platform_version": ... }, "kiosk_enabled": true, "kiosk_only": true, "kiosk_secondary_apps": ..., "minimum_chrome_version": "versionString", "nacl_modules": [...], "oauth2": ..., "offline_enabled": true, "optional_permissions": ["tabs"], "permissions": ["tabs"], "platforms": ..., "requirements": {...}, "sandbox": [...], "short_name": "Short Name", "signature": ..., "sockets": { "tcp": { "connect": "*" }, "udp": { "send": "*" } }, "storage": { "managed_schema": "schema.json" }, "system_indicator": ..., "update_url": "http://path/to/updateInfo.xml", "url_handlers": {...}, "usb_printers": { "filters": [...] }, "version_name": "aString", "webview": {...} }
ãã¹ãŠã®æ©èœãäºåã«åŠçããã®ã¯ç¡é§ã§ãã 圌ãã®èšå€§ãªæ°ã
ããã«ãæ¡åŒµèªäœã®jsåŽã®ã¿ã倧ããªãµã€ãºã«æé·ã§ããŸãã
ç§ã®çŸåšã®ã¹ããŒã
ããã¢ãŒã·ã§ã³
èšåãã䟡å€ã¯ã»ãšãã©ãããŸãããããã®æ¡åŒµã®ä¿é²ã§ãã ããŠã£ãžã§ãããã®æ©èœã¯ããã¹ã¯ããããŠãŒã¶ãŒã察象ãšããŠããããšã§ãããã¹ã¯ããããŠãŒã¶ãŒã¯è¿å¹Žãå°æ°æŽŸã«ãªããŸããã
ã³ã³ããã¹ãåºåãšãœãŒã·ã£ã«ã¡ãã£ã¢åºåãè©ŠããŸããã çµéšã¯ã»ãšãã©ãªããã³ã³ããŒãžã§ã³ã¯ãŒãã§ãã
ã³ã³ãã³ãåºå
ãããŸã§ã®ãšãããç§ã®çµéšã¯1ã€ã®ãã©ãããã©ãŒã ã«éå®ãããŠãããä»ã®ãã©ãããã©ãŒã ã«ã€ããŠè©±ãããšã¯ã§ããŸããããåãããšããããšæããŸãã
Yandexã®ã³ã³ãã³ãåºåã§ã¯ãããã€ã¹ãšãã©ãŠã¶ãŒãã¿ãŒã²ããã«ã§ããªãããšãããããŸããã ãããã£ãŠãæ¡åŒµæ©èœãChromeå°çšã§ããå Žåã移è¡ã«ãã£ãŠäœåãªæ倱ããããããããªãä»ã®ãã©ãŠã¶ãŒã䜿çšããŠãããŠãŒã¶ãŒã¯åºåã衚瀺ããå¿ èŠããããŸãã
æ¡åŒµæ©èœçšã«å¥ã®ãµã€ããäœããããªãã£ãã®ã§ããŠã§ãã¹ãã¢ã§ãã®ããŒãžã宣äŒããŸããã ãã®ã¢ãããŒãã®æ¬ ç¹ã¯ãåºåã¢ã«ãŠã³ãã®çµ±èšã®ã¿ãä¿¡é Œã§ããåºåããŒãžã§ã®ãŠãŒã¶ãŒã®åäœã確èªã§ããªãããšã§ãã
ãœãŒã·ã£ã«ãããã¯ãŒã¯
ãããã¯ããã¹ã¯ããããæ»ã«ãããŠããå°æ°æŽŸã§ãããµã€ãã®ã«ããŽãªãŒã«å±ããŠããã ãã§ãã
Vkontakteã¯ãã¢ãã€ã«ããã³ãã«ããŒãžã§ã³ã®Webãµã€ãã®ã¿ãŒã²ãã£ã³ã°ãæäŸããŸãã ãããããã®ãã§ãã¯ããŒã¯ã¯èšå®ã®æåŸã«é ããŠããŸããäºç®ãæŒãããçµ±èšã§æ²ããå ±éãèŠãåã«ç§ã¯å人çã«ããã«æ°ã¥ããŸããã§ãã
å®éãã¢ãã€ã«ãã¥ãŒã¯ãã®æ¥ãããã¯ããã«å€§ããã£ã
æåŸã«èã
æ¡åŒµæ©èœã¯ãã€ã³ã¿ãŒãããã§äœæ¥ãã人ã ã«ãšã£ãŠåŒ·åãªããŒã«ã ãšæããŸãã ãã©ãŠã¶ã§ã¯å€ãã®æéãè²»ãããŸããããããæé©åããããšããããŸãã ããšãã°ã匷調衚瀺æã«ããã¹ãã翻蚳ããGoogle翻蚳ãŠã£ãžã§ããã¯ãæé©åã®è¯ãäŸã§ãã èšå€§ãªæ°ã®éããŠããã¿ãã®åé¡ã«å¯Ÿãã解決çããåŸã§ããŠã£ãžã§ããã䜿çšããããšã決å®ããŸããã
æ¡åŒµæ©èœãäœæãããšããChromeãæ°·å±±ã®æ°ŽäžéšåãåŠç¿ãããããã³ããšã³ãããäœæããçµéšãåŸãããŸãïŒç¹ã«ããã¯ãšã³ãéçºè ã®å ŽåïŒã æ¡åŒµæ©èœã¯ãåãReact JSã§äœæã§ããŸãããã®React JSã䜿çšããŠãã¢ãã€ã«ããã€ã¹çšã®ã¢ããªã±ãŒã·ã§ã³ãäœæã§ããŸãã äž¡æ¹ãæžãããã»ã¹ã¯éåžžã«äŒŒãŠããŸãã