-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeta-sankaku-complex.js
168 lines (148 loc) · 4.98 KB
/
beta-sankaku-complex.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// ==UserScript==
// @name Beta Sankaku complex
// @namespace http://tampermonkey.net/
// @version 1.0.0
// @description Beta Sankaku Complex
// @author LeonAM
// @match *://beta.sankakucomplex.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=sankakucomplex.com
// @require file://<PATH>/beta-sankaku-complex.js
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @grant GM_registerMenuCommand
// @grant GM_info
// ==/UserScript==
/* globals $ */
(function () {
'use strict';
console.log(`Running UserScript "${GM_info.script.name}"`);
// Constants
const RE_URL_TAGS = /\?tags=(.*)/;
var currentSrc = "";
/**
* Interval to detect the current post's image and add a link to show only
* the image on the browser
*/
setInterval(() => {
document
.querySelectorAll(".swiper-zoom-container img")
.forEach(img => {
if (img.parentElement.tagName !== "A") {
var a = document.createElement("a")
currentSrc = a.href = img.src
img.parentElement.appendChild(a)
a.appendChild(img)
} else {
if (currentSrc !== img.src) {
currentSrc = img.parentElement.href = img.src
}
}
});
});
/**
* Interval for detecting the presence of an ad dialog and close it
* automatically
*/
const interval2 = setInterval(() => {
let dialogList = document.querySelectorAll("MuiDialog-paper")
if (dialogList.length > 0) {
dialogList.forEach(dialog => {
dialog.querySelectorAll("button")
.forEach(button => { button.click() })
})
clearInterval(interval2)
console.log("Diálogo cancelado")
}
}, 500);
/** Chars to replace in the URL to show as the post's window title */
const REPLACE = {
"%20": " ",
"%21": "!",
"%28": "(",
"%29": ")",
"%3A": ":"
};
/**
* Interval for changing the window title of a page for the tags list to
* identify the search or the post
*/
setInterval(() => {
let currURL = document.location.href
// If on a book page, the title is left unchanged
if (currURL.includes("/books/")) return
let titleFirstPart = ""
if (currURL.includes("post/show")) {
let tag = document.querySelector("a[class*='MuiChip-root-'] > span")
titleFirstPart = tag ? tag.textContent : "Post"
} else {
titleFirstPart = "Browse"
let reMatch = RE_URL_TAGS.exec(currURL)
if (reMatch) {
titleFirstPart = reMatch[1]
for (let key in REPLACE) {
titleFirstPart = titleFirstPart
.replaceAll(key, REPLACE[key])
}
}
}
document.title = `${titleFirstPart} | Sankaku Complex`
}, 500)
/**
* Gets the tags from the URL's queryparams
*
* @return {string[]} Tags list
*/
function getTags(url) {
var reMatch = /.*:\/\/beta\.sankakucomplex\.com(?:\/\?tags=(.*))?/
.exec(url)
if (!reMatch) return null
if (!reMatch[1]) return []
var tags = reMatch[1]
for (let key in REPLACE) {
tags = tags.replaceAll(key, REPLACE[key])
}
return tags.split(" ")
}
/**
* Tags to filter in a posts search, to be added to the URL with the `-`
* symbol to the head
*/
const TAGS_FILTRO = ["3d", "cg_art", "doujinshi"]
/** Filters the tags in a posts search and redirects */
function filterTags() {
var tags = getTags(document.location.href)
var changes = 0
for (let tag of TAGS_FILTRO) {
if (tags.includes(tag)) {
tags.remove(tag)
}
let notTag = `-${tag}`
if (!tags.includes(notTag)) {
tags.push(notTag)
changes++
}
}
if (changes) {
document.location.href = "https://beta.sankakucomplex.com/?tags=" + tags.join(" ")
}
}
const TAGS_DOUJINSHI = ["doujinshi", "english"]
function doujinshi() {
var tags = getTags(document.location.href)
var changes = 0
for (let tag of TAGS_DOUJINSHI) {
if (!tags.includes(tag)) {
let notTag = `-${tag}`
if (tags.includes(notTag)) {
tags.remove(notTag)
}
tags.push(tag)
changes++
}
}
if (changes) {
document.location.href = "https://beta.sankakucomplex.com/?tags=" + tags.join(" ")
}
}
GM_registerMenuCommand("Filtrar", filterTags)
GM_registerMenuCommand("Doujinshi", doujinshi)
})()