-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTransitYahooJp.user.js
More file actions
62 lines (59 loc) · 2.35 KB
/
TransitYahooJp.user.js
File metadata and controls
62 lines (59 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// ==UserScript==
// @name Transit Yahoo japan Enhanced
// @namespace Yr
// @version 1.4
// @description Add clipboard feature to simple copy infos of current page
// @author yanagiragi
// @match https://transit.yahoo.co.jp/search/result*
// @icon https://www.google.com/s2/favicons?sz=64&domain=yahoo.co.jp
// @grant GM_setClipboard
// ==/UserScript==
(function () {
'use strict';
Mount();
})();
function sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function Mount () {
const summaries = [...document.querySelectorAll('.routeSummary .option ul')]
const buttonHtml = `
<li class="print yrTransitBtn">
<p class="btnDefault" style="width:35px">
<a href="#">
<span class="icnShare"></span>
</a>
</p>
</li>`
summaries.forEach(x => {
x.insertAdjacentHTML('beforeend', buttonHtml)
const btn = x.querySelector('.yrTransitBtn')
btn.addEventListener('click', async (event) => {
event.stopPropagation()
const title = document.querySelector('.title').textContent.replace('→', ' → ')
const time = x.parentElement.parentElement.querySelector('.time').textContent
const startTime = time.substring(0, time.indexOf('発'))
const endTime = time.substring(time.indexOf('→') + 1, time.indexOf('着'))
let shortUrl = x.parentElement.querySelector('.shortUrl').value
if (!shortUrl) {
const shareButton = x.parentElement.querySelector('.shareButton')
shareButton.click()
while (!shortUrl) {
shortUrl = x.parentElement.querySelector('.shortUrl').value
await sleep(500)
}
}
console.log(`shortUrl = ${shortUrl}`)
const firstTransit = [...x.parentElement.parentElement.parentElement.querySelectorAll('.transport')]
?.filter(x => !x.textContent.includes('徒歩'))
?.[0]
?.textContent
?.replace('当駅始発', ' ')
?.replace('※巡回ルート', ' ')
.trim()
const content = `${startTime} ~ ${endTime}: ${title} via [${firstTransit}](${shortUrl})`
GM_setClipboard(content)
console.log(`Copied: ${content}`)
})
})
}