-
Notifications
You must be signed in to change notification settings - Fork 0
/
AniDB_anime_entries_extra_links.user.js
122 lines (104 loc) · 4.82 KB
/
AniDB_anime_entries_extra_links.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
// ==UserScript==
// @namespace seiya-anidb-extra-links
// @name AniDB anime entries extra links
// @version 1.11.91
// @description AniDB extra links for anime entries
// @author Seiya
// @homepageURL https://twitter.com/seiya_loveless
// @icon https://static.anidb.net/favicon.ico
// @match https://anidb.net/anime/*
// @grant none
// @run-at document-end
// ==/UserScript==
(()=>{
const doc = window.document;
function quoteattr(s) {
return ('' + s)
.replace(/`/g, '\'')
.replace(/&/g, '&')
.replace(/'/g, ''')
.replace(/"/g, '"')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/\r\n/g, ' ')
.replace(/[\r\n]/g, ' ');
}
if(!doc.querySelector('.pane.info')){
console.error('[error] panel info not found!')
return;
}
let reOdd = false;
let isOdd = true;
if(!doc.querySelector('.pane.info .resources')){
const afterEl = doc.querySelector('.pane.info .tags') ? '.pane.info .tags' : '.pane.info .year';
const trEl = doc.createElement('tr');
trEl.classList.add('resources');
trEl.innerHTML = '<th class="field">Resources</th><td class="value"></td>';
doc.querySelector(afterEl).insertAdjacentElement('afterend', trEl);
reOdd = true;
}
if(reOdd){
const trSel = doc.querySelectorAll('.pane.info .g_definitionlist > table > tbody > tr');
for(const e of trSel){
if(e.classList.contains('g_odd')){
e.classList.remove('g_odd');
}
if(isOdd){
e.classList.add('g_odd');
isOdd = false;
}
else if(!isOdd){
isOdd = true;
}
}
}
const targetEl = '.pane.info .resources .value .group.thirdparty.english';
if(!doc.querySelector(targetEl)){
const divEl = doc.createElement('div');
divEl.classList.add('group','thirdparty','english');
doc.querySelector('.pane.info .resources .value').insertAdjacentElement('beforeend', divEl);
}
const titleEl = doc.querySelector('.pane.info .romaji .value span');
const titleText = titleEl.textContent.replace(/Gekijouban/,'').replace(/\(\d{4}\)/, '').replace(/ +/g, ' ').trim();
const titleId = doc.querySelector('.shortlink').textContent.replace(/a/, '.');
const rtSec = [
'181,1900,208,209,2258,2343,2365,4,484,521,539,822,84,930',
'1460,815,816,921',
'1105,1386,1387,1389,1390,1391,1642,2484,2491,2544,33,404,599,809,893',
].join(',');
const links = [
{ name: 'AniList', domain: 'anilist.co', icon: 'i.imgur.com/2Dlvrnj.png', urlPrefix: '/search/anime?sort=SEARCH_MATCH&search=' },
{ name: 'Shikimori', domain: 'shikimori.me', icon: 'i.imgur.com/FCEAKfv.png', urlPrefix: '/animes?search=' },
{ name: 'NyaaV2', domain: 'nyaa.si', icon: 'i.imgur.com/rGFiDrK.png', urlPrefix: '/?c=1_0&q=' },
{ name: 'SukebeiV2', domain: 'sukebei.nyaa.si', icon: 'i.imgur.com/7O8uBsn.png', urlPrefix: '/?c=1_1&q=' },
{ name: 'AniDex', domain: 'anidex.info', icon: 'i.imgur.com/vApI8cH.png', urlPrefix: '/?q=' },
{ name: 'AnimeTosho-Series', domain: 'animetosho.org', icon: 'i.imgur.com/bMpKDYG.png', urlPrefix: `/series/anidb${titleId}#` },
{ name: 'AnimeTosho-Search', domain: 'animetosho.org', icon: 'i.imgur.com/bMpKDYG.png', urlPrefix: '/search?q=' },
{ name: 'RuTracker', domain: 'rutracker.org', icon: 'i.imgur.com/W5VLN29.png', urlPrefix: `/forum/search.php?f=${rtSec}&nm=` },
];
const extraLinks = doc.createElement('div');
extraLinks.classList.add('icons');
extraLinks.innerHTML = '';
for(const icon of links){
const classList = `i_icon i_resource_${icon.name} brand`;
const uriHref = `https://${icon.domain}${icon.urlPrefix}${quoteattr(titleText)}`;
// data-anidb-rel="anidb::extern" itemprop="sameAs"
extraLinks.innerHTML += `<a class="${classList}" href="${uriHref}" target="_blank" title="${icon.name}">`
+ `<span class="text">${icon.name}</span>`
+ '</a>';
}
doc.querySelector(targetEl).insertAdjacentElement('beforeend', extraLinks);
const styleEl = document.createElement('style');
doc.head.appendChild(styleEl);
for(const icon of links){
const icoUrl = !icon.icon.match(/^\//) ? icon.icon : `${icon.domain}${icon.icon}`;
styleEl.sheet.insertRule(
`.i_resource_${icon.name}{`
+ ` background-image: url('https://${icoUrl}');`
+ ' background-size: contain;'
+ ' height: 16px;'
+ ' width: 16px;'
+ '}'
);
}
})();