forked from Masaiki/dmhy-bangumi-current-season
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmhy-bangumi-current-season.js
115 lines (114 loc) · 4.67 KB
/
dmhy-bangumi-current-season.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
// ==UserScript==
// @name dmhy-bangumi-current-season
// @name:zh-CN 动漫花园新番索引更新脚本
// @namespace https://github.com/VegeHime/dmhy-bangumi-current-season
// @version 0.4.3
// @description update data of new season bangumi on dmhy
// @description:zh-CN 更新动漫花园新番列表及搜索关键词
// @author Masaiki
// @match *://dmhy.org/*
// @match *://www.dmhy.org/*
// @match *://share.dmhy.org/*
// @match *://dmhy.anoneko.com/*
// @match *://dmhy.ye1213.com/*
// @match *://share.dongmanhuayuan.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
Element.prototype.empty = function () {
while (this.firstChild) this.removeChild(this.firstChild);
return this;
}
function createElementWithAttr(TagName, Attrs = {}, Text = '') {
let element = document.createElement(TagName);
for (let attr in Attrs)
element[attr] = Attrs[attr];
element.textContent = Text;
return element;
}
function loadJS(url, callback) {
let script = document.createElement('script'),
fn = callback || function () { };
script.type = 'text/javascript';
script.onload = function () {
fn();
};
script.src = url;
document.head.appendChild(script);
}
let ShowAllBangumi = localStorage.ShowAllBangumi !== "false";
let today = new Date();
let day = today.getDay();
let trs = [];
let panel = document.querySelector(".jmd");
function data2doms() {
trs = [];
for (let i = 0; i < bangumi_data.length; i++) {
let td = document.createElement('td');
for (let j = 0; j < bangumi_data[i].length; j++) {
if (bangumi_data[i][j][2] && today < new Date(bangumi_data[i][j][2])) continue;
if (bangumi_data[i][j][3] && today > new Date(bangumi_data[i][j][3])) continue;
let name = bangumi_data[i][j][0];
let keyword = bangumi_data[i][j][1] || name;
let link = createElementWithAttr('a', {
'href': `/topics/list?keyword=${encodeURIComponent(keyword)}`
}, name);
td.appendChild(link);
}
let tr = document.createElement('tr');
let th = createElementWithAttr('th', null, bangumi_group_name[i]);
tr.appendChild(th);
tr.appendChild(td);
trs.push(tr);
}
trs[day].classList.add('today');
}
function bangumiRefresh() {
panel.empty();
if (ShowAllBangumi)
trs.forEach((item) => { panel.appendChild(item); });
else {
for (let i = 5; i <= 8; ++i)
panel.appendChild(trs[(day + i) % 7]);
for (let i = 7; i < bangumi_data.length; ++i)
panel.appendChild(trs[i]);
}
panel.childNodes.forEach((item, index) => {
if (index % 2) item.classList.add("odd");
else item.classList.add("even");
});
}
document.querySelector("div[id$='_ad']").removeAttribute('align');
let DataURL = localStorage.DataURL || 'https://aliyun-wb-bai621pis7-klt02wd7.oss-cn-shanghai.aliyuncs.com/dmhy-bangumi-current-season-master/bangumi-data.js';
loadJS(DataURL, function () {
data2doms();
bangumiRefresh();
});
let switchButton = createElementWithAttr('a', {
'href': "javascript:;",
'style': "margin-right:2px;"
}, '顯示切換');
switchButton.onclick = () => {
ShowAllBangumi = !ShowAllBangumi;
localStorage.ShowAllBangumi = ShowAllBangumi;
bangumiRefresh();
};
let select = createElementWithAttr('select', { 'style': 'margin-right:2px; background-color:#247; color:#FFF' });
select.onchange = (e) => {
localStorage.DataURL = history_list.urls[select.selectedIndex];
location.reload();
};
document.querySelector('.nav_title').style.paddingBottom = '5px';
let block = document.querySelector('span.fr');
block.insertBefore(switchButton, block.firstChild);
block.insertBefore(select, block.firstChild);
loadJS('https://aliyun-wb-bai621pis7-klt02wd7.oss-cn-shanghai.aliyuncs.com/dmhy-bangumi-current-season-master/history-list.js', function () {
for (let i = 0; i < history_list.values.length; i++) {
let option = createElementWithAttr('option', { 'value': history_list.values[i] }, history_list.names[i]);
select.add(option);
}
let selectedIndex = history_list.urls.indexOf(DataURL);
if (selectedIndex !== -1) select.value = history_list.values[selectedIndex];
});
})();