-
Notifications
You must be signed in to change notification settings - Fork 1
/
eh_functions.user.js
62 lines (54 loc) · 2.2 KB
/
eh_functions.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
// ==UserScript==
// @name E-H Function
// @version 1.0
// @include https://g.e-hentai.org/*
// @include https://exhentai.org/*
// @grant GM_registerMenuCommand
// ==/UserScript==
(function () {
var list = [{
name: "查MyTags各tag最後發表日期距今幾天",
func: async function () {
const gts = Array.from(document.querySelectorAll('.gt').values());
const tags = gts.map(el => el.title).filter(tag => tag.startsWith('artist:') || tag.startsWith('group:'));
for (const tag of tags) {
const res = await fetch(`/tag/${tag}`);
const text = await res.text();
const parser = new DOMParser();
const doc = parser.parseFromString(text, "text/html");
const div = doc.querySelector('.gl1t:nth-child(1) .gl5t div:nth-child(1) div:nth-child(2)');
if (!div) break;
const time = div.innerText;
const days = Math.floor((Date.now() - new Date(time).getTime()) / 8640000) / 10;
const gt = gts.find(el => el.title.includes(tag));
if (!gt) break;
gt.parentNode.appendChild(document.createTextNode(days));
}
}
}];
var localScript = function (scriptText, args) {
var args = JSON.stringify(args);
if (typeof scriptText == 'function')
scriptText = '(' + scriptText + ')(' + args + ');';
var script = document.createElement('script');
script.type = 'text/javascript';
script.appendChild(document.createTextNode(scriptText));
document.body.appendChild(script);
setTimeout(function () {
script.parentNode.removeChild(script);
}, 1000);
};
var runMenu = function (id) {
localScript(function (args) {
(eval(args.func))();
}, {
namespace: this.namespace,
func: '(' + this.func + ')'
});
};
if (GM_registerMenuCommand && typeof GM_registerMenuCommand === 'function') {
for (var i = 0; i < list.length; i++) {
GM_registerMenuCommand('E-H Function - ' + list[i].name, runMenu.bind(list[i], i));
}
}
})()