-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMR stuff.user.js
216 lines (200 loc) · 5.91 KB
/
AMR stuff.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// ==UserScript==
// @name AMR stuff
// @version 0.7
// @description just some AMR QOL stuff
// @author Robo
// @include *
// @grant GM_addStyle
// @grant GM_registerMenuCommand
// @grant GM.registerMenuCommand
// @grant GM_getValue
// @grant GM_setValue
// @require https://openuserjs.org/src/libs/sizzle/GM_config.js
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==
/* globals jQuery, $, waitForKeyElements, gmfetch, MonkeyConfig*/
/* #region setup */
const optionss = [{
id: 'webtoon',
name: 'webtoon mode on always',
default: true
},
{
id: 'mangaTitle',
name: "set page title to 'manga'",
default: false
},
{
id: '100Width',
name: 'always scale up images',
default: true
},
{
id: '100Width toggalable',
name: 'toggle always scale up images',
default: false
},
]
let fieldDefs = JSON.parse('{' + optionss.map(ele => ret(ele)).join('\n,') + '}')
GM_config.init({
id: 'GM_config',
title: 'Config for AMR Manga Reading',
fields: fieldDefs,
css: `
[id^="GM_config_ID"] {
float: left
}
.iconImg {
width: 16px;
vertical-align: middle;
}
.config_var {
margin-right: 5% !important;
display: inline !important;
}`,
events: {
open: function (doc) {
[...doc.querySelectorAll(".section_header_holder")].filter(ele => ele.querySelector('.center')).forEach(function (ele) {
ele.style.backgroundColor = 'transparent'
ele.style.border = '4px solid transparent'
});
},
save: function () {
location.reload();
}
}
});
function ret(ele) {
return `"${ele.id}": {
"section": [],
"label": "${ele.name}",
"type": "checkbox",
"default": ${ele.default}
}`
}
GM_registerMenuCommand("Config for AMR Manga Reading", function () {
GM_config.open();
});
/* #endregion */
let observerr = new MutationObserver(callbackk);
let start = 0
function callbackk(mutations) {
if (document.querySelector("#amrapp div.v-select__selections")) {
observerr.disconnect();
start = 1
//no boarders in continuous scroll mode
if (GM_config.get('webtoon')) {
document.querySelector("#amrapp > div.v-application--wrap > main > div > div > table").classList.add('webtoon');
}
//code probably only i need
if (GM_config.get('mangaTitle')) {
if (document.querySelector("head > title").textContent != 'Manga') {
document.querySelector("head > title").textContent = 'Manga'
}
}
if (GM_config.get('mangaTitle')) {
let observer = new MutationObserver(callback);
let options = {
characterData: true,
childList: true
}
observer.observe(document.querySelector("head > title"), options);
}
/*
in order
make the scan 100% width (for portrait viewing)
no boarders in side by side mode
*/
if (GM_config.get('100Width')) {
GM_addStyle(`
.scanContainer.res-w img {
width: 100%;
}
.scanContainer img {
object-fit: contain;
}
.amr-scan-container td {
padding: 0 !important;
}`
)
}
if (GM_config.get('100Width toggalable')) {
console.log('hihihihihihi')
let toggle = GM_config.get('100Width')
document.addEventListener('keydown', doc_keyUp, false);
console.log('hihihihihihi')
function doc_keyUp(e) {
if (e.keyCode == 83 && e.shiftKey == true){
let ogpos = window.pageYOffset;
let here = getPos(ogpos);
toggle = !toggle
if (toggle){
GM_addStyle(`
.scanContainer.res-w img {
width: 100%;
}
.scanContainer img {
object-fit: contain;
}`
);
setPos(here);
}else{
GM_addStyle(`
.scanContainer.res-w img {
width: auto;
}
.scanContainer img {
object-fit: unset;
}`
)
setPos(here);
}
}
}
}
if (GM_config.get('webtoon')) {
GM_addStyle(`
.amr-scan-container td {
padding: 0 !important;
}`
)
}
}
}
function getPos(scrollPos) {
let pos = 0;
let img = {};
$('.v-main__wrap .amr-scan-container tr').each(function(i){
let height = this.getBoundingClientRect().height;
pos += height;
if (pos > scrollPos && img.index == undefined) {
img.index = i;
img.viewRatio = (pos - scrollPos)/height;
}
});
return img;
}
function setPos(img) {
let pos = 0;
$('.v-main__wrap .amr-scan-container tr').each(function(i){
let height = this.getBoundingClientRect().height;
pos += height;
if (img.index == i) {
window.scrollTo({top: pos - img.viewRatio*height});
}
});
}
function callback() {
if (GM_config.get('mangaTitle')) {
if (document.querySelector("head > title").textContent != 'Manga') {
document.querySelector("head > title").textContent = 'Manga'
}
}
}
let options = {
characterData: true,
childList: true,
subtree: true
}
//run the observer that checks for if the page is taekn over by amr
observerr.observe(document.querySelector("body"), options);