Skip to content

Instantly share code, notes, and snippets.

@soudai
Created April 2, 2022 10:49
Show Gist options
  • Select an option

  • Save soudai/778b5df8450ee820413e20cc72989060 to your computer and use it in GitHub Desktop.

Select an option

Save soudai/778b5df8450ee820413e20cc72989060 to your computer and use it in GitHub Desktop.
tonamelカレンダー登録くん
javascript: (async function() {
if (!window.location.href.match(/tonamel\.com\/competition\/[a-zA-Z0-9]{5}$/)) {
alert('bookmarkletを起動したページには対応していません。大会トップを指定してください');
return;
}
var title = document.querySelector('#__layout>div.wrapper>div.competition-detail>div.competition-detail>div.main>div.detail>div.m-competition-card>div.linkable-area>div.m-link>div.name>span').textContent;
var org = document.querySelector('#__layout>div>div.competition-detail>div.competition-detail>div.main>div.detail>div.a-box.m-competition-card.a-box--no-radius.a-box--white>div.inner>div.a-flex.organization.a-flex--flex-start.a-flex--row>a>div>span').textContent;
var entryStartDate = document.querySelector('#__layout>div>div.competition-detail>div.competition-detail>div.main>div.entry>div>div>div>div>ol>li:nth-child(1)>dl>dd:nth-child(4)>span:nth-child(1)').textContent;
entryStartDate = entryStartDate.replace(/(\d{4})\/(\d{2})\/(\d{2})\(.\) (\d{2}:\d{2}) 〜/, '$1$2$3T$4:00+0900');
var entryEndDate = document.querySelector('#__layout>div>div.competition-detail>div.competition-detail>div.main>div.entry>div>div>div>div>ol>li:nth-child(1)>dl>dd:nth-child(4)>span:nth-child(2)').textContent;
entryEndDate = entryEndDate.replace(/(\d{4})\/(\d{2})\/(\d{2})\(.\) (\d{2}:\d{2})/, '$1$2$3T$4:00+0900');
var competitionStartDate = document.querySelector('#__layout>div>div.competition-detail>div.competition-detail>div.main>div.detail>div.a-box.competition-info.competition-detail-info.a-box--no-radius.a-box--white>dl:nth-child(1)>dd:nth-child(2)>span').textContent;
competitionStartDate = competitionStartDate.replace(/(\d{4})\/(\d{2})\/(\d{2})\(.\) (\d{2}:\d{2}) 〜/, '$1-$2-$3T$4:00');
var dt = new Date(competitionStartDate);
var dtString = dt.toISOString().replaceAll('-', '').replaceAll('.000Z', 'Z');
var end = new Date(Math.floor(dt.getTime() + (3600 * 2 * 1000)));
var endString = end.toISOString().replaceAll('-', '').replaceAll('.000Z', 'Z');
var url = 'https://www.google.com/calendar/event?' + 'action=TEMPLATE' + '&text=' + encodeURIComponent(title) + '&details=' + encodeURIComponent('主催団体: ' + org) + ' ' + window.location + '&dates=' + dtString + '/' + endString + '&trp=true' + '&sprop=website:' + window.location + '&sprop=name:tonamel';
window.location.href = url;
})();
@soudai

soudai commented Apr 2, 2022

Copy link
Copy Markdown
Author

bookmarkletとして登録し、tonamelの大会詳細ページで実行するとGoogle Calendarに登録される

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment