-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOpenTwitterPixivLinksInGmail.user.js
68 lines (60 loc) · 1.96 KB
/
OpenTwitterPixivLinksInGmail.user.js
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
63
64
65
66
67
68
// ==UserScript==
// @name OpenTwitterPixivLinks
// @namespace Yr
// @version 1.4
// @description Open all twitter or pixiv image links in new tab in gmail
// @author yanagiragi
// @match https://mail.google.com/mail/u/0/
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant none
// ==/UserScript==
function openTwitterLinks () {
const content = document.querySelector('.ii.gt').textContent
const matches = content.match(/(pbs\.twimg\.com\/media\/.*:orig)/g)
const set = [...new Set(matches)]
set.forEach(el => {
console.log(`open ${el}`)
window.open(`https://${el}`, '_blank')
})
}
function openPixivLinks () {
const content = document.querySelector('.ii.gt').textContent
const matches = content.match(/www\.pixiv\.net\/artworks\/\d+/g)
const set = [...new Set(matches)]
set.forEach(el => {
console.log(`open ${el}`)
window.open(`https://${el}`, '_blank')
})
}
function click () {
console.log('click')
openTwitterLinks()
openPixivLinks()
}
function mount () {
const bar = [...document.querySelectorAll('.G-atb')]
.filter(x => x.style['display'] != 'none')
?.[0]
if (bar.querySelector('.YrOpenTwtterButuon')) {
// already mounted
return;
}
bar.insertAdjacentHTML('beforeend', `<div class="YrOpenTwtterButuon" class="asa"><div class="ar8 T-I-J3 J-J5-Ji"></div></div>`)
const button = bar.querySelector('.YrOpenTwtterButuon')
button.addEventListener('click', click)
console.log(`mount on ${button}`)
}
(function () {
'use strict';
const mailRegex = /mail\.google\.com\/mail\/u\/0\/(.*)/
let interval = setInterval(() => {
// only mount button in mail detail page
if (!location.href.match(mailRegex)) {
return;
}
// wait for bar shows up
if (document.querySelector('.asa')) {
mount()
}
}, 1000)
})();