forked from dodying/UserJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhCopyInfo.user.js
123 lines (123 loc) · 4.58 KB
/
hCopyInfo.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// ==UserScript==
// @name [H]CopyInfo
// @version 1.01.5
// @author dodying
// @namespace https://github.com/dodying/UserJs
// @supportURL https://github.com/dodying/UserJs/issues
// @icon https://cdn.jsdelivr.net/gh/dodying/UserJs@master/Logo.png
// @include http*://www.javlibrary.com/*
// @include http*://www.javbus.com/*
// @include http*://www.caribbeancom.com/moviepages/*
// @include http*://www.caribbeancompr.com/moviepages/*
// @grant GM_setClipboard
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js
// @run-at document-end
// ==/UserScript==
(function () {
if (window.location.href.match('/search/') && $('.item').length === 1) {
window.location = $('.item>a').attr('href')
return
} else if (window.location.href.match('vl_searchbyid')) {
var find = $('.id').filter(function () {
return this.textContent === window.location.href.match(/keyword=(.*?)$/)[1] && !$(this).parents().eq(1).text().match('(ブルーレイディスク)')
})
if (find.length === 1) window.location = find.parent().attr('href')
return
}
var linkLib = {
'www.javlibrary.com': {
searchInput: '#idsearchbox',
searchButton: '#idsearchbutton',
code: '#video_id .text',
name: '.post-title',
star: 'span.star>a',
genre: '.genre>a',
score: 'span.score',
length: '#video_length .text'
},
'www.javbus.com': {
searchInput: '#search-input',
searchButton: '#navbar .btn[type="submit"]',
code: '.info>p>span:eq(1)',
name: 'h3',
star: '.star-show~p:eq(0)>.genre>a',
genre: '.header:contains(類別)~p:eq(0)>.genre>a',
length: '.info>p:eq(2)'
},
'www.caribbeancompr.com': {
searchInput: '#q',
searchUrl: 'https://www.caribbeancompr.com/moviepages/{{q}}/',
code: /moviepages\/(.*?)\//,
name: '.video-detail>h1',
star: '.movie-info>dl:contains("出演") a',
genre: '.movie-info-cat>dd>a',
length: function () {
var time = $('.movie-info>dl:contains("再生時間")>dd').text()
time = new Date('1970-01-01 ' + time + ' GMT+000').getTime()
return Math.round(time / 1000 / 60)
}
},
'www.caribbeancom.com': {
searchInput: '#q',
searchUrl: 'https://www.caribbeancom.com/moviepages/{{q}}/',
code: /moviepages\/(.*?)\//,
name: '.video-detail>h1',
star: '.movie-info>dl:contains("出演") a',
genre: '.movie-info-cat>dd>a',
length: function () {
var time = $('.movie-info>dl:contains("再生時間")>dd').text()
time = new Date('1970-01-01 ' + time + ' GMT+000').getTime()
return Math.round(time / 1000 / 60)
}
}
}
var rule = linkLib[window.location.host]
$(rule.searchInput).on('paste', function () {
var _ = this
setTimeout(function () {
_.value = _.value.replace(/\..*$/, '')
if (_.value && rule.searchButton) {
$(rule.searchButton).click()
} else if (_.value && rule.searchUrl) {
window.location.href = rule.searchUrl.replace('{{q}}', _.value)
}
}, 20)
})
var stars, genres, info // total info
var stars2 = [] // stars
stars = []
genres = []
$(rule.star).each(function () {
stars.push(this.innerText)
stars2.push(this.innerText + '\t' + this.href)
})
$(rule.genre).each(function () {
genres.push(this.innerText)
})
info = [
typeof rule.code === 'string' ? $(rule.code).text().trim() : window.location.href.match(rule.code)[1], // code
$(rule.name).text().replace(/^(\w+(_|-))?\w+ /, '').replace(/\n/g, '').trim(), // name
stars.sort().join(' '), // star
genres.join(' ') // genre
]
if (!info[0]) return
if (typeof rule.score === 'string') { // score
info.push($(rule.score).text() ? $(rule.score).text().match(/[\d.]+/)[0] : '')
}
if (typeof rule.length === 'string' && $(rule.length).length > 0) { // length
info.push($(rule.length).text().match(/\d+/)[0])
} else {
info.push(rule.length())
}
document.title = info[0]
document.onkeydown = function (e) {
if (e.ctrlKey && e.key === 'c' && window.getSelection().toString() === '') {
GM_setClipboard(info.join('\t'))
if ($('.hBanner')) $('.addCode').click()
} else if (e.ctrlKey && e.key === 'v' && e.target.tagName === 'BODY') {
$(rule.searchInput).select()
} else if (e.ctrlKey && e.key === 'x' && window.getSelection().toString() === '') {
GM_setClipboard(stars2.join('\r\n'))
}
}
})()