Skip to content

Instantly share code, notes, and snippets.

@KiKiKi-KiKi
Last active February 21, 2023 16:33
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 KiKiKi-KiKi/baf1c3d609925aa2f260371eb4edb569 to your computer and use it in GitHub Desktop.
Save KiKiKi-KiKi/baf1c3d609925aa2f260371eb4edb569 to your computer and use it in GitHub Desktop.
🐰 Generate participants CSV from twipla.jp. Open dev tool console and copy & paste this script 👍
const listElement = '.member_list';
const userElement = 'a.namelist';
const getDate = () => {
const d = new Date();
return `${d.getFullYear()}-${d.getMonth()}-${d.getDay()}-${d.getTime()}`;
}
const getUserData = (elm) => {
const twitterID = elm.getAttribute('title');
return [
elm.getAttribute('n'),
twitterID,
`https://twitter.com/${twitterID.replace('@', '')}`
];
};
const getUsersList = () => {
return [...document.querySelectorAll(listElement)].reduce((data, section) => {
return [
...data,
[section.firstChild?.data],
...[...section.querySelectorAll(userElement)].map(getUserData),
]
}, []);
};
const downloadCSV = (data) => {
const blob = new Blob([data.map(row => row.join(',')).join('\n')], {type: 'text/csv'});
const fileName = `${document.title}_${getDate()}.csv`;
const url = (window.URL || window.webkitURL).createObjectURL(blob);
const link = document.createElement('a');
link.download = fileName;
link.href = url;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
!(() => {
const header = ['userName', 'twitterId', 'twitterLink'];
downloadCSV([
header,
...getUsersList(),
])
})();
@KiKiKi-KiKi
Copy link
Author

KiKiKi-KiKi commented Apr 9, 2021

🎉 TwiPla (twipla.jp) のイベントページから 参加者, 興味あり, 不参加 のユーザーリストを CSV としてダウンロードできるスクリプトです。

🌟 How to use

  1. TwiPla のイベントページで dev tool を開きコンソールのタブを開きます。
  2. このスクリプトまたは下記のminifiされたコードをコピーしてコンソールのタブに貼り付けます。
const listElement=".member_list",userElement="a.namelist",getDate=()=>{let e=new Date;return`${e.getFullYear()}-${e.getMonth()}-${e.getDay()}-${e.getTime()}`},getUserData=e=>{let t=e.getAttribute("title");return[e.getAttribute("n"),t,`https://twitter.com/${t.replace("@","")}`]},getUsersList=()=>[...document.querySelectorAll(".member_list")].reduce((e,t)=>[...e,[t.firstChild?.data],...[...t.querySelectorAll("a.namelist")].map(getUserData),],[]),downloadCSV=e=>{let t=new Blob([e.map(e=>e.join(",")).join("\n")],{type:"text/csv"}),l=`${document.title}_${getDate()}.csv`,r=(window.URL||window.webkitURL).createObjectURL(t),a=document.createElement("a");a.download=l,a.href=r,document.body.appendChild(a),a.click(),document.body.removeChild(a)};(()=>{let e=["userName","twitterId","twitterLink"];downloadCSV([e,...getUsersList(),])})();
  1. おわり

ファイル名は TwiPla のタイトル_YYYY-M-D-timestamp.csv で出力されます。

⚠️

HTML からマッシュアップしているので TwiPla の DOM 構成やクラス名が変更になる動作しなくなります。

動作確認は Chrome v.88.0.4324.192 でしかしていません

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