[
  {
    "path": ".gitignore",
    "content": "dist/*\nnode_modules/*"
  },
  {
    "path": "LICENSE.md",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2016 Zhongyi Tong\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# youdao-note-electron（有道云笔记Linux版）\n\nMac OS X 和 Linux 下更好用的有道云笔记客户端。使用Electron构建。<img src=\"assets/icon.png\" alt=\"logo\" height=\"64\" align=\"right\" />\n\n## 下载已经打包好的应用\n[有道云笔记-Electron Linux 64位版本](https://github.com/jamasBian/youdao-note-electron/releases/download/1.1.1/Youdao-Note-Electron-linux-x64.zip)\n\n[有道云笔记-Electron MacOSX 版本](https://github.com/jamasBian/youdao-note-electron/releases/download/1.1.1/Youdao-Note-Electron-darwin-x64.zip)\n\n## 如何使用：\n\n```bash\n# Clone this repository\ngit clone https://github.com/jamasBian/youdao-note-electron.git\n# Go into the repository\ncd youdao-note-electron\n# Install dependencies and run the app\nnpm install -g cnpm --registry=https://registry.npm.taobao.org\ncnpm install \ncp ./assets/icon.png ./node_modules/_electron@4.1.1@electron/dist/resources/\nnpm start\n```\n\n## 根据你的平台打包应用\n\n``` shell\nnpm run build:osx\nnpm run build:linux\nnpm run build:win\n```\n\n\n\n## 解决图标的问题。\ncp ./assets/icon.png ./node_modules/_electron@4.1.1@electron/dist/resources/\n#### License [CC0 (Public Domain)](LICENSE.md)\n"
  },
  {
    "path": "index.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <title>有道云笔记</title>\n  <link rel=\"stylesheet\" href=\"style.css\">\n</head>\n<body>\n  <webview id=\"webview\" src=\"https://note.youdao.com/web/\"/>\n</body>\n<script src=\"ynote.js\"></script>\n</html>\n"
  },
  {
    "path": "main.js",
    "content": "'use strict';\r\n\r\nconst electron = require('electron');\r\n// Module to control application life.\r\nconst app = electron.app;\r\n// Module to create native browser window.\r\nconst BrowserWindow = electron.BrowserWindow;\r\n\r\n// Keep a global reference of the window object, if you don't, the window will\r\n// be closed automatically when the JavaScript object is garbage collected.\r\nlet mainWindow;\r\n\r\nfunction createWindow () {\r\n  // Create the browser window.\r\n  const path = require('path');\r\n  const imgPath = path.join(process.resourcesPath, '/icon.png')\r\n  mainWindow = new BrowserWindow({icon: imgPath});\r\n\r\n  // and load the index.html of the app.\r\n  mainWindow.loadURL('file://' + __dirname + '/index.html');\r\n  mainWindow.setIcon(imgPath);\r\n  mainWindow.maximize();\r\n  //mainWindow.webContents.openDevTools()\r\n  \r\n\r\n  // Emitted when the window is closed.\r\n  mainWindow.on('closed', function() {\r\n    // Dereference the window object, usually you would store windows\r\n    // in an array if your app supports multi windows, this is the time\r\n    // when you should delete the corresponding element.\r\n    mainWindow = null;\r\n  });\r\n}\r\n\r\n// This method will be called when Electron has finished\r\n// initialization and is ready to create browser windows.\r\napp.on('ready', createWindow);\r\n\r\n// Quit when all windows are closed.\r\napp.on('window-all-closed', function () {\r\n  // On OS X it is common for applications and their menu bar\r\n  // to stay active until the user quits explicitly with Cmd + Q\r\n  if (process.platform !== 'darwin') {\r\n    app.quit();\r\n  }\r\n});\r\n\r\napp.on('activate', function () {\r\n  // On OS X it's common to re-create a window in the app when the\r\n  // dock icon is clicked and there are no other windows open.\r\n  if (mainWindow === null) {\r\n    createWindow();\r\n  }\r\n});\r\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"Youdao-Note-Electron\",\n  \"version\": \"1.0.0\",\n  \"description\": \"An Electron application for Youdao-Note\",\n  \"main\": \"main.js\",\n  \"scripts\": {\n    \"start\": \"electron main.js\",\n    \"build\": \"./scripts/build-all.sh\",\n    \"build:osx\": \"./scripts/build.sh darwin x64\",\n    \"build:osx64\": \"./scripts/build.sh darwin x64\",\n    \"build:linux32\": \"./scripts/build.sh linux ia32\",\n    \"build:linux\": \"./scripts/build.sh linux x64\",\n    \"build:linux64\": \"./scripts/build.sh linux x64\",\n    \"build:win\": \".\\\\scripts\\\\build-win32.bat win32 ia32\",\n    \"build:win32\": \".\\\\scripts\\\\build-win32.bat win32 ia32\",\n    \"build:win64\": \".\\\\scripts\\\\build-win32.bat win32 x64\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/jamasBian/youdao-note-electron.git\"\n  },\n  \"keywords\": [\n    \"Youdao\",\n    \"Note\",\n    \"有道云笔记\",\n    \"Web\"\n  ],\n  \"author\": \"Zhiqiang Bian\",\n  \"license\": \"MIT\",\n  \"bugs\": {\n    \"url\": \"https://github.com/jamasBian/youdao-note-electron/issues\"\n  },\n  \"homepage\": \"https://github.com/jamasBian/youdao-note-electron\",\n  \"dependencies\": {\n    \"electron\": \"4.1.1\",\n    \"electron-packager\": \"13.0.1\"\n  }\n}\n"
  },
  {
    "path": "scripts/build-all.sh",
    "content": "#!/bin/bash\n\nif ! hash electron-packager 2>/dev/null; then\n  RED='\\033[0;31m'\n  NC='\\033[0m'\n  echo \"${RED}Error${NC}: you need to npm install electron-packager. Aborting.\"\n  exit 1\nfi\n\nfunction build() {\n\t./scripts/build.sh $@\n}\n\nbuild darwin x64\nbuild linux ia32\nbuild linux x64\nbuild win32 ia32\nbuild win32 x64"
  },
  {
    "path": "scripts/build-win32.bat",
    "content": "set PLATFORM=%1%\nset ARCH=%2%\nset APP_NAME=\"Youdao-Note-Electron\"\n\nset ignore_list=\"dist|scripts|\\.idea|.*\\.md|.*\\.yml|node_modules/nodejieba\"\n\nelectron-packager . \"%APP_NAME%\" --platform=%PLATFORM% --arch=%ARCH% --electronVersion=1.4.15  --app-version=1.4.0 --asar --icon=assets\\icon.png --overwrite --out=.\\dist --ignore=%ignore_list%\n"
  },
  {
    "path": "scripts/build.sh",
    "content": "#!/bin/bash\n\nif ! hash electron-packager 2>/dev/null; then\n  RED='\\033[0;31m'\n  NC='\\033[0m'\n  echo \"${RED}Error${NC}: you need to npm install electron-packager. Aborting.\"\n  exit 1\nfi\n\nif [ \"$#\" -ne 2 ]; then\n  echo -e \"Usage: ./script/build.sh <platform> <arch>\"\n  echo -e \"\tplatform:\tdarwin, linux, win32\"\n  echo -e \"\tarch:\t\tia32, x64\"\n  exit 1\nfi\n\nPLATFORM=$1\nARCH=$2\n\necho \"Start packaging for $PLATFORM $ARCH.\"\n\nif [ $PLATFORM = \"linux\" ]; then\n    APP_NAME=\"Youdao-Note-Electron\"\nelse\n    APP_NAME=\"Youdao-Note-Electron\"\nfi\n\nif [ $PLATFORM = \"darwin\" ]; then\n    ICON=icon.icns\nelse\n    ICON=icon.png\nfi\n\nignore_list=\"dist|scripts|\\.idea|.*\\.md|.*\\.yml|node_modules/nodejieba\"\ncp assets/$ICON node_modules/electron/dist/resources/$ICON\nelectron-packager . \"${APP_NAME}\" --platform=$PLATFORM --arch=$ARCH --electronVersion=4.1.1 --app-version=1.1.0 --asar --icon=assets/$ICON --overwrite --out=./dist --ignore=${ignore_list}\n\nif [ $PLATFORM = \"darwin\" ]; then\n    cp assets/$ICON dist/${APP_NAME}-$PLATFORM-$ARCH/$APP_NAME.app/Contents/Resources/\nelse\n    cp assets/$ICON dist/${APP_NAME}-$PLATFORM-$ARCH/resources/\nfi\n\n\nif [ $? -eq 0 ]; then\n  echo -e \"$(tput setaf 2)Packaging for $PLATFORM $ARCH succeeded.$(tput sgr0)\\n\"\nfi"
  },
  {
    "path": "scripts/tar-all.sh",
    "content": "#!/bin/bash\n\nAPP_NAME=\"Youdao-Note-Electron\"\ncd dist\necho 'Start compressing for Linux x64.'\ntar zcf \"$APP_NAME-linux-x64.tar.gz\" \"$APP_NAME-linux-x64\"\necho 'Compressing for Linux x64 succeed.'\n\necho 'Start compressing for Linux ia32.'\ntar zcf $APP_NAME-linux-ia32.tar.gz $APP_NAME-linux-ia32\necho 'Compressing for Linux ia32 succeed.'\n\necho 'Start compressing for MAC OSX.'\nzip -r -q $APP_NAME-darwin-x64.zip $APP_NAME-darwin-x64\necho 'Compressing for MAC OSX succeed.'\n\necho 'Start compressing for Windows 64-bit.'\nzip -r -q $APP_NAME-win32-x64.zip $APP_NAME-win32-x64\necho 'Compressing for Windows 64-bit succeed.'\n\necho 'Start compressing for Windows 32-bit.'\nzip -r -q $APP_NAME-win32-ia32.zip $APP_NAME-win32-ia32\necho 'Compressing for Windows 32-bit succeed.'\ncd ..\n"
  },
  {
    "path": "style.css",
    "content": "html, body, #webview {\n  width: 100%;\n  height: 100%;\n  margin: 0;\n  padding: 0;\n  overflow-y: hidden;\n}\n\nhtml::-webkit-scrollbar {\n  width: 0 !important;\n}\n"
  },
  {
    "path": "ynote.js",
    "content": "const shell = require('electron').shell;\r\n\r\nconst injectCSS = `div#layout-main{width:100%;flex:0 1 auto;height:100%}\r\ndiv#layout-container{width:100%;height:100%}\r\ndiv#body{height:100%}`;\r\n\r\nfunction getParameterByName(url, name) {\r\n    name = name.replace(/[\\[]/, \"\\\\[\").replace(/[\\]]/, \"\\\\]\");\r\n    var regex = new RegExp(\"[\\\\?&]\" + name + \"=([^&#]*)\"),\r\n        results = regex.exec(url);\r\n    return results === null ? \"\" : decodeURIComponent(results[1].replace(/\\+/g, \" \"));\r\n}\r\n\r\nnewWindow =function (e) {\r\n  e.defaultPrevented = true;\r\n  var url = getParameterByName(e.url, 'requrl');\r\n  if (url.length > 1) {\r\n    //shell.openExternal(url);\r\n    if(url.indexOf(\"succ.html\")>=0)\r\n      webview.loadURL(\"https://note.youdao.com/web/\")\r\n    else\r\n      webview.loadURL(url);\r\n  } else {\r\n    //shell.openExternal(e.url);\r\n    if(e.url.indexOf(\"succ.html\")>=0)\r\n      webview.loadURL(\"https://note.youdao.com/web/\")\r\n    else\r\n      webview.loadURL(e.url);\r\n  }\r\n};\r\n\r\ncheckUrl =function (e) {\r\n  console.log(e.url)\r\n  if(e.url.indexOf(\"succ.html\")>=0)\r\n    webview.loadURL(\"https://note.youdao.com/web/\")\r\n};\r\n\r\nonload = function () {\r\n  var webview = document.getElementById(\"webview\");\r\n  webview.addEventListener('dom-ready', function () {\r\n    // overwrite css style. make it fullscreen.\r\n    console.log(webview);\r\n    const path = require('path');\r\n    const imgPath = path.join(process.resourcesPath, '/icon.png')\r\n    console.log(imgPath);\r\n    webview.insertCSS(injectCSS);\r\n    // inject js to trigger if there is new message in.\r\n    // webview.executeJavaScript('injectJS.getBadge()');\r\n    webview.addEventListener('new-window', newWindow);\r\n    webview.addEventListener('did-navigate', checkUrl);\r\n  });\r\n\r\n  \r\n};\r\n"
  }
]