Skip to content

Instantly share code, notes, and snippets.

@kits
Created June 8, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kits/f8f5b10def55e5ade2e0ef52f0bfe484 to your computer and use it in GitHub Desktop.
Save kits/f8f5b10def55e5ade2e0ef52f0bfe484 to your computer and use it in GitHub Desktop.
cstimer->tweet bookmarklet
(function(){
var twurl = 'https://twitter.com/intent/tweet?text=';
var ta = document.getElementsByClassName('sumtable')[0];
var ths = ta.querySelectorAll('tr th:nth-child(1)');
var i, str, num, headstr, timestr, tweet;
headstr = '';
for (i in ths) {
str = ths[i].textContent || '';
num = str.match(/[0-9]+/);
if (str == 'time') {
headstr += '1/';
}
else if (str == 'DNF') {
headstr += 'DNF/';
}
else if (num) {
headstr += (num + '/');
}
}
headstr = headstr.replace(/\/$/, '');
var tds = ta.querySelectorAll('tr td:nth-child(3)');
timestr = '';
for (i in tds) {
str = tds[i].textContent || '';
if ( str.match(/^[0-9:.]+$/) ) {
timestr += (str + '/');
}
else if (str == 'DNF') {
timestr += 'DNF/';
}
}
timestr = timestr.replace(/\/$/, '');
tweet = headstr + ' = ' + timestr;
window.open(twurl + encodeURIComponent(tweet));
})();
@kits
Copy link
Author

kits commented Jun 8, 2020

bookmarklet URL:
javascript:(function(){%0A%09var twurl = 'https://twitter.com/intent/tweet?text=';%0A%09var ta = document.getElementsByClassName('sumtable')[0];%0A%09var ths = ta.querySelectorAll('tr th:nth-child(1)');%0A%09var i, str, num, headstr, timestr, tweet;%0A%09headstr = '';%0A%09for (i in ths) {%0A%09%09str = ths[i].textContent || '';%0A%09%09num = str.match(/[0-9]+/);%0A%09%09if (str == 'time') {%0A%09%09%09headstr += '1/';%0A%09%09}%0A%09%09else if (str == 'DNF') {%0A%09%09%09headstr += 'DNF/';%0A%09%09}%0A%09%09else if (num) {%0A%09%09%09headstr += (num + '/');%0A%09%09}%0A%09}%0A%09headstr = headstr.replace(/\/$/, '');%0A%0A%09var tds = ta.querySelectorAll('tr td:nth-child(3)');%0A%09timestr = '';%0A%09for (i in tds) {%0A%09%09str = tds[i].textContent || '';%0A%09%09if ( str.match(/^[0-9:.]+$/) ) {%0A%09%09%09timestr += (str + '/');%0A%09%09}%0A%09%09else if (str == 'DNF') {%0A%09%09%09timestr += 'DNF/';%0A%09%09}%0A%09}%0A%09timestr = timestr.replace(/\/$/, '');%0A%09tweet = headstr + ' = ' + timestr;%0A%09window.open(twurl + encodeURIComponent(tweet));%0A})();

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