-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.go
68 lines (56 loc) · 1.95 KB
/
scripts.go
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
// Copyright 2022 Wayback Archiver. All rights reserved.
// Use of this source code is governed by the GNU GPL v3
// license that can be found in the LICENSE file.
package screenshot // import "github.com/wabarc/screenshot"
import (
"fmt"
"net/url"
"github.com/chromedp/chromedp"
"golang.org/x/net/publicsuffix"
)
var scripts = map[domain]string{
"substack.com": `let maybeLater = document.querySelector('button.maybe-later'); if (maybeLater !== null) { maybeLater.click(); }`,
"archiveofourown.org": `let tosAgree = document.querySelector('#tos_agree');
if (tosAgree !== null) {
tosAgree.click();
}
let tosAccept = document.querySelector('#accept_tos');
if (tosAccept !== null) {
tosAccept.click();
}`,
// https://zhuanlan.zhihu.com/p/12345
"zhihu.com": `var loginPop = document.querySelector('div.Modal.Modal--default.signFlowModal > button');
if (loginPop !== null) {
loginPop.click();
}`,
"douban.com": `let noteMask = document.querySelector('.ui-overlay-mask');
let noteDial = document.querySelector('iframe[src*="login"]');
if (noteDial !== null && noteMask !== null) {
if (noteMask.style.display === '') {
document.elementFromPoint(1, 1).click();
}
}
let noteReadMore = document.querySelector('#link-report .taboola-open');
if (noteReadMore !== null) {
noteReadMore.click();
}`,
"jacobinmag.com": `let mailingPop = document.getElementById('mailing-list-popup');
if (mailingPop !== null) {
mailingPop.remove();
}`,
}
type domain string
func evaluate(u *url.URL) chromedp.Action {
dom, err := publicsuffix.EffectiveTLDPlusOne(u.Hostname())
if err != nil {
return chromedp.Tasks{}
}
script := scripts[domain(dom)]
if script == "" {
return chromedp.Tasks{}
}
script = fmt.Sprintf("() => {\n try{ \n%s\n }catch(_){};\n return true;\n}\n", script)
// action := chromedp.PollFunction(script, nil, chromedp.WithPollingTimeout(5*time.Second))
action := chromedp.Evaluate(script, nil, chromedp.EvalIgnoreExceptions)
return chromedp.Tasks{action}
}