Meetup Better Event Exporter

Export full Meetup event description to Google Calendar

  1. // ==UserScript==
  2. // @name Meetup Better Event Exporter
  3. // @namespace http://boris.joff3.com
  4. // @version 1.2.7
  5. // @description Export full Meetup event description to Google Calendar
  6. // @author Boris Joffe
  7. // @match http://*.meetup.com/*
  8. // @match https://*.meetup.com/*
  9. // @grant none
  10. // ==/UserScript==
  11. /* jshint -W097, -W041 */
  12. /* eslint-disable no-console, no-unused-vars */
  13. 'use strict';
  14.  
  15. /*
  16. The MIT License (MIT)
  17.  
  18. Copyright (c) 2015 Boris Joffe
  19.  
  20. Permission is hereby granted, free of charge, to any person obtaining a copy
  21. of this software and associated documentation files (the "Software"), to deal
  22. in the Software without restriction, including without limitation the rights
  23. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  24. copies of the Software, and to permit persons to whom the Software is
  25. furnished to do so, subject to the following conditions:
  26.  
  27. The above copyright notice and this permission notice shall be included in
  28. all copies or substantial portions of the Software.
  29.  
  30. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  31. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  32. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  33. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  34. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  35. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  36. THE SOFTWARE.
  37. */
  38.  
  39.  
  40. // Util
  41. var DEBUG = false;
  42. function dbg() {
  43. if (DEBUG)
  44. console.log.apply(console, arguments);
  45.  
  46. return arguments[0];
  47. }
  48.  
  49.  
  50. var
  51. qs = document.querySelector.bind(document),
  52. err = console.error.bind(console),
  53. log = console.log.bind(console),
  54. euc = encodeURIComponent;
  55.  
  56. function qsv(elmStr, parent) {
  57. var elm = parent ? parent.querySelector(elmStr) : qs(elmStr);
  58. if (!elm) err('(qs) Could not get element -', elmStr);
  59. return elm;
  60. }
  61.  
  62. function getProp(obj, path, defaultValue) {
  63. path = Array.isArray(path) ? Array.from(path) : path.split('.');
  64. var prop = obj;
  65.  
  66. while (path.length && obj) {
  67. prop = obj[path.shift()];
  68. }
  69.  
  70. return prop != null ? prop : defaultValue;
  71. }
  72.  
  73. function updateExportLink() {
  74. log('Event Exporter running');
  75.  
  76. var
  77. calLink = qsv('a[href*="google.com/calendar"]'),
  78. descElm = qsv('#event-description-wrap'),
  79. desc;
  80.  
  81. if (descElm.innerText) {
  82. desc = descElm.innerText;
  83. } else {
  84. // fallback, HTML encoded entities will appear broken
  85. desc = descElm.innerHTML
  86. .replace(/<br>\s*/g, '\n') // fix newlines
  87. .replace(/&nbsp;/g, ' ')
  88. .replace(/&amp;/g, '&')
  89. .replace(/<a href="([^"]*)"[^>]*>/g, '[$1] ') // show link urls
  90. .replace(/<[^>]*>/g, ''); // strip html tags
  91. }
  92.  
  93. var meetupGroupName = qsv('meta[property="og:title"]').getAttribute('content');
  94.  
  95. var indexOfQuestionMark = location.href.indexOf('?');
  96. var hasExtraUrlJunk = indexOfQuestionMark !== -1; // trim analytics stuff at end
  97. var eventUrl = hasExtraUrlJunk ? location.href.substring(0, indexOfQuestionMark) : location.href;
  98.  
  99. var leadingText = meetupGroupName + '\n' + eventUrl + '\n\n';
  100. var oldUrl = calLink.href;
  101. dbg('old url is:', oldUrl);
  102. var notEmpty = function (s) { return s !== ''; };
  103.  
  104. var meetupTitle = getProp(oldUrl.match(/text=[^&]*/), '0', '');
  105. // Add Meetup group name if it's not already part of the title
  106. if (meetupTitle.indexOf(euc(meetupGroupName)) === -1)
  107. meetupTitle += euc(' (' + meetupGroupName + ')');
  108.  
  109. var exportUrl = 'https://calendar.google.com/calendar/render?action=TEMPLATE&' + [
  110. meetupTitle,
  111. getProp(oldUrl.match(/dates=[^&]*/), '0', ''),
  112. getProp(oldUrl.match(/location=[^&]*/), '0', ''),
  113. 'details=' + euc(leadingText + desc)
  114. ].filter(notEmpty).join('&');
  115.  
  116. dbg('export url len = ', exportUrl.length);
  117.  
  118. calLink.href = exportUrl;
  119. calLink.target = '_blank';
  120.  
  121. // show color change to notify user that link changed
  122. var linkColor = 'rgba(0, 255, 255, 0.1)';
  123. calLink.parentNode.style.backgroundColor = linkColor;
  124.  
  125. var exportBtn = qsv('#addToCalAction');
  126. exportBtn.style.backgroundColor = linkColor;
  127.  
  128. // Add Google Export link at top level
  129. var calLinkClone = calLink.cloneNode();
  130. calLinkClone.innerHTML = '<span class="calOpt google"></span> Google Export';
  131. var li = document.createElement('li');
  132. li.className += 'D_dropdown';
  133. li.appendChild(calLinkClone);
  134. li.style.backgroundColor = linkColor;
  135. exportBtn.parentNode.appendChild(li);
  136. }
  137.  
  138. window.addEventListener('load', updateExportLink, true);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址