LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Saturday, May 5, 2018

RawGitでgithubに置いた.jsを読み込む


RawGitでgithubに置いた.jsを読み込んでみたときの備忘録

https://rawgit.com/
で対象のファイルのURLを貼り付けると

production と developmentの欄にURLが表示される


試してみたこと

テストで何度もコードを更新する場合はdevelopmentのURLを使うと更新されたコードが読み込まれる
→トラフィックが多すぎると制限される


productionはトラフィックの制限はないが、コードを更新しても更新されたコードは読み込まれない
→更新されたコードを読み込む場合は更新後に再度対象のgithubのURLを貼り付けると新しいURLが表示される(URL内にあるcommit hashが更新される)







コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="https://cdn.rawgit.com/prepractice/javascript/a2763ed6/library/array_unique_count.js"></script>
</head>
<body>
  <script>
    unique_count();
    function unique_count() {
      var values = ["hello", "hi", "hey", "hey", "hey", "hello"];
      var obj = arrayUniqueCount(values);
      alert(JSON.stringify(obj));
    }
  </script>
</body>
</html>
意訳
 


RawGitサイトで作られたproductionURLをスクリプトで読み込む



unique_count()を実行する
この機能がやること
配列を用意する
arrayUniqueCountに渡して結果を取得して
アラートに出す






実行結果



今回試した自作のコード

配列を渡すと要素の値をユニークにしてその数をカウントしてオブジェクトで返す
https://github.com/prepractice/javascript/blob/master/library/array_unique_count.js


参考

RawGit
https://rawgit.com/

Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...