🏠 Home 

ニコ生の予定をGoogleカレンダーに追加するリンクを追加

ニコ生の予定をGoogleカレンダーに追加するリンクを追加する


Install this script?
  1. // ==UserScript==
  2. // @name ニコ生の予定をGoogleカレンダーに追加するリンクを追加
  3. // @namespace http://deflis.net/
  4. // @version 0.1
  5. // @description ニコ生の予定をGoogleカレンダーに追加するリンクを追加する
  6. // @author deflis
  7. // @match http://live.nicovideo.jp/gate/*
  8. // @grant none
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12. function zerofill(num){
  13. return ('0'+num).slice(-2);
  14. }
  15. function getTime(date){
  16. return date.getUTCFullYear() +
  17. zerofill(date.getUTCMonth()+1) +
  18. zerofill(date.getUTCDate()) +
  19. 'T' +
  20. zerofill(date.getUTCHours()) +
  21. zerofill(date.getUTCMinutes()) +
  22. zerofill(date.getUTCSeconds()) +
  23. 'Z';
  24. }
  25. const startDate = new Date(document.querySelector("div.kaijo meta").getAttribute("content"));
  26. const title = document.querySelector(".program-title").textContent;
  27. const endDate = new Date(startDate);
  28. endDate.setMinutes(endDate.getMinutes() + 3 + 30);
  29. const url = 'http://www.google.com/calendar/event?' +
  30. 'action=' + 'TEMPLATE' +
  31. '&text=' + encodeURIComponent(title) +
  32. '&details=' + encodeURIComponent('ニコニコ生放送\n' + location.href) +
  33. '&location='+ encodeURIComponent(location.href) +
  34. '&dates=' + getTime(startDate) + '/' + getTime(endDate);
  35. const tr = document.createElement("tr");
  36. const td = document.createElement("td");
  37. const a = document.createElement("a");
  38. a.setAttribute("href", url);
  39. a.textContent = "Googleカレンダーに追加";
  40. td.appendChild(a);
  41. tr.appendChild(td);
  42. document.querySelector("#bn_gbox table").appendChild(tr);
  43. console.log(url);
  44. })();