Last active
September 11, 2020 14:38
-
-
Save moyashipan/c92812e76179956f2696db5c6259cd98 to your computer and use it in GitHub Desktop.
Google Meetの終了時間2分前にGet Wildを自分の画面上に表示するやつ。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Meetに参加したら、以下すべてをChromeのConsole(Option + Command + i)にコピペしてEnterを押してください。 | |
// 起動が成功するとミーティングの詳細(左下のやつ)が一瞬開いて閉じます。 | |
// カレンダーと紐付いた(終了時刻のある)Meetなら、終了時刻の2分前にあなたの画面上にだけGet WildのYouTube動画が表示されます。 | |
// ただし毎回この操作をする必要があって面倒。 | |
// なのでChrome Extensionにしたり改変したりはご自由にどうぞ。 | |
(async () => { | |
function findButton(expanded) { | |
return document.querySelector(`[aria-haspopup="true"][aria-label$="の詳細"][aria-expanded=${expanded}]`); | |
} | |
// popupを開く | |
(await new Promise((resolve, _reject) => { | |
const i = setInterval(() => { | |
const el = findButton(false); | |
if (el) { | |
clearInterval(i); | |
resolve(el); | |
} | |
}, 100); | |
})).click(); | |
// ミーティングの詳細内のアイコンを取得する | |
const iconInPanel = await new Promise((resolve, _reject) => { | |
let i = setInterval(() => { | |
const iconInPanel = document.querySelector('[aria-label="ミーティングの詳細"] [role="tabpanel"] [aria-hidden="true"]'); | |
if (iconInPanel) { | |
clearInterval(i); | |
resolve(iconInPanel); | |
} | |
}, 100); | |
}); | |
// カレンダーと紐付いていればアイコンの後ろに開始・終了時刻が表示されているはず | |
const maybeTimeRange = iconInPanel.nextSibling.innerText; | |
const match = maybeTimeRange.match(/^20[0-9]{2}年[0-9]{1,2}月[0-9]{1,2}日\(.\) ([0-9]{1,2}):([0-9]{1,2})~([0-9]{1,2}):([0-9]{1,2})$/); | |
if (match) { | |
// TODO: timerを手でOFFにできると便利そう | |
const timer = setInterval(() => { | |
const currentTime = new Date(); | |
let endTime = new Date(); | |
endTime.setHours(match[3]); | |
endTime.setMinutes(match[4]); | |
endTime.setSeconds(0); | |
endTime.setTime(endTime.getTime() - 120 * 1000); // 終了時刻の120秒前 | |
if (timer && currentTime >= endTime) { | |
// YouTubeを一番手前に表示 | |
document.body.insertAdjacentHTML('beforeend', '<iframe width="560" height="315" src="https://www.youtube.com/embed/NHKq8IOXPxA" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen style="z-index: 999;position: absolute;"></iframe>'); | |
clearInterval(timer); | |
} | |
}, 1000); | |
} | |
// popupを閉じる | |
(await new Promise((resolve, _reject) => { | |
const i = setInterval(() => { | |
const el = findButton(true); | |
if (el) { | |
clearInterval(i); | |
// NOTE: 少し待ってから押さないと閉じてくれない | |
setTimeout(() => resolve(el), 300); | |
} | |
}, 100); | |
})).click(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment