-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-actions.user.js
292 lines (247 loc) · 8.74 KB
/
page-actions.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// ==UserScript==
// @name Page Actions
// @namespace agrmohit
// @require https://cdn.jsdelivr.net/npm/@violentmonkey/dom@2
// @require https://cdn.jsdelivr.net/npm/@violentmonkey/shortcut@1
// @match https://www.youtube.com/watch?v=*
// @match https://mangadex.org/title/*
// @match https://mangasee123.com/manga/*
// @match https://mangakatana.com/manga/*
// @match https://imgur.com/*
// @match https://raw.githubusercontent.com/*
// @match https://rss.agrmohit.com/unread
// @match https://rss.agrmohit.com/feed/*
// @exclude-match https://imgur.com/gallery/*
// @match https://cdn.jsdelivr.net/npm/*
// @match https://twitter.com/*
// @match https://www.reddit.com/*
// @match https://x.com/*
// @match https://anilist.co/*
// @match https://paperless.agrmohit.com/documents/*
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @version 1.14.0
// @author agrmohit
// @description Extension to perform various actions on wesbites
// @downloadURL https://github.com/agrmohit/userscripts/raw/main/page-actions.user.js
// @supportURL https://github.com/agrmohit/userscripts/issues
// @license MIT
// ==/UserScript==
const { register } = VM.shortcut;
// Write default config values if user config is not present
if (typeof GM_setValue !== "undefined" && typeof GM_getValue !== "undefined") {
if (GM_getValue("shortcut") === undefined) {
GM_setValue("shortcut", "alt-p");
}
// twiiit.com is a redirecting proxy for nitter instances.
// It redirects to a public, working nitter instance from the following list
// https://github.com/zedeus/nitter/wiki/Instances
if (GM_getValue("nitter_url") === undefined) {
GM_setValue("nitter_url", "twiiit.com");
}
} else {
console.log(
`${constants.log_prefix} Storage access is not allowed by userscript manager, please update to the latest version`
);
console.log(`${constants.log_prefix} Alternatively, use Violentmonkey (https://violentmonkey.github.io/get-it/)`);
return;
}
const youtubeActions = () => {
const clip = document.querySelector('[aria-label="Clip"]');
if (clip) clip.remove();
const thanks = document.querySelector('[aria-label="Thanks"]');
if (thanks) thanks.remove();
const join = document.querySelector('[aria-label="Join this channel"]');
if (join) join.remove();
const openInMpv = () => {
window.location = `ytdl://${window.location}`;
};
const removeRightSidebar = () => {
const el = document.querySelector("#secondary");
if (el) el.remove();
};
const removeCommentsSection = () => {
const el = document.querySelector("#comments");
if (el) el.remove();
};
GM_registerMenuCommand("Open video in mpv", openInMpv);
GM_registerMenuCommand("Remove right sidebar (Watch Next, Live Chat)", removeRightSidebar);
GM_registerMenuCommand("Remove comments section", removeCommentsSection);
register(GM_getValue("shortcut"), () => {
const choice = prompt(
`0. Open video in mpv\n1. Remove right sidebar (Watch Next, Live Chat)\n2. Remove comments section\n3. All of the above`
);
switch (choice) {
case "":
case "0":
openInMpv();
break;
case "1":
removeRightSidebar();
break;
case "2":
removeCommentsSection();
break;
case "3":
removeRightSidebar();
removeCommentsSection();
break;
}
});
};
const mangadexActions = () => {
const regex = /https:\/\/mangadex.org\/title\/([a-z0-9-]+)/;
const match = regex.exec(window.location.href);
const readInCubari = () => {
window.location.href = `https://cubari.moe/read/mangadex/${match[1]}`;
};
GM_registerMenuCommand("Read in Cubari", readInCubari);
register(GM_getValue("shortcut"), readInCubari);
};
const mangaseeActions = () => {
const regex = /https:\/\/mangasee123.com\/manga\/([a-z0-9-]+)/;
const match = regex.exec(window.location.href);
const readInCubari = () => {
window.location.href = `https://cubari.moe/read/mangasee/${match[1]}`;
};
GM_registerMenuCommand("Read in Cubari", readInCubari);
register(GM_getValue("shortcut"), readInCubari);
};
const mangakatanaActions = () => {
const readInCubari = () => {
window.location.href = `https://cubari.moe/mk/${window.location.href}`;
};
GM_registerMenuCommand("Read in Cubari", readInCubari);
register(GM_getValue("shortcut"), readInCubari);
};
const imgurActions = () => {
VM.observe(document.body, () => {
const imageElement = document.querySelector(".image-placeholder");
if (imageElement && imageElement.src.match(/./)) {
const openImage = () => {
window.location.href = imageElement.src;
};
GM_registerMenuCommand("Open image", openImage);
register(GM_getValue("shortcut"), openImage);
} else {
GM_unregisterMenuCommand("Open image", openImage);
register(GM_getValue("shortcut"), null);
}
});
};
const jsdelivrActions = () => {
const regex = /https:\/\/cdn.jsdelivr.net\/npm\/(@?[a-zA\/0-9]+)(?:[@0-9a-z\/\.-]*)/;
const match = regex.exec(window.location.href);
const openInNpm = () => {
window.location.href = `https://www.npmjs.com/package/${match[1]}`;
};
GM_registerMenuCommand("Open in npm", openInNpm);
register(GM_getValue("shortcut"), openInNpm);
};
const githubRawActions = () => {
const regex = /http.?:\/\/raw.githubusercontent.com\/([\w-]*)\/([\w_.-]*)\/([\w_.-]*)\/([a-zA-Z0-9-_\/\.]*)/;
const match = regex.exec(window.location.href);
const openInGitHub = () => {
window.location.href = `https://github.com/${match[1]}/${match[2]}/blob/${match[3]}/${match[4]}`;
};
GM_registerMenuCommand("Open in GitHub", openInGitHub);
register(GM_getValue("shortcut"), openInGitHub);
};
const twitterActions = () => {
const openInNitter = () => {
window.location = window.location.href.replace(/(twitter\.com|x\.com)/, GM_getValue("nitter_url"));
};
GM_registerMenuCommand("Open in Nitter", openInNitter);
register(GM_getValue("shortcut"), openInNitter);
};
const minifluxActions = () => {
const removeNoisyArticles = () => {
let count = 1;
let articles = document.querySelectorAll("article");
articles.forEach((article) => {
if (article.querySelector(".category").textContent.match(/YouTube|Frequent/) !== null) {
// Without a timeout it does not remove all of the matching elements
setTimeout(() => {
article.remove();
}, count * 10);
count += 1;
}
});
};
const openYoutubeLinksInMpv = () => {
document.querySelectorAll('a[href*="youtube.com/watch"]').forEach((link) => {
link.href = `ytdl://${link.href}`;
});
};
openYoutubeLinksInMpv();
GM_registerMenuCommand("Remove YouTube articles", removeNoisyArticles);
register(GM_getValue("shortcut"), removeNoisyArticles);
};
const redditActions = () => {
const regex = /https:\/\/www.reddit.com([\/\w]*)/;
const match = regex.exec(window.location.href);
const openInShReddit = () => {
window.location.href = `https://sh.reddit.com${match[1]}`;
};
GM_registerMenuCommand("Open in sh.reddit", openInShReddit);
register(GM_getValue("shortcut"), openInShReddit);
};
const anilistActions = () => {
const regex = /https:\/\/anilist.co\/(?:anime|manga)\/(\d*)/;
const match = regex.exec(window.location.href);
const openOpenGraphImage = () => {
window.location.href = `https://img.anili.st/media/${match[1]}`;
};
GM_registerMenuCommand("Open Open Graph image", openOpenGraphImage);
register(GM_getValue("shortcut"), openOpenGraphImage);
};
const paperlessActions = () => {
const regex = /https:\/\/paperless.agrmohit.com\/documents\/(\d*)/;
const match = regex.exec(window.location.href);
const openPDF = () => {
window.location.href = `https://paperless.agrmohit.com/api/documents/${match[1]}/preview/`;
};
GM_registerMenuCommand("Open PDF", openPDF);
register(GM_getValue("shortcut"), openPDF);
};
switch (window.location.hostname) {
case "www.youtube.com":
setTimeout(() => youtubeActions(), 7_000);
break;
case "mangadex.org":
mangadexActions();
break;
case "mangasee123.com":
mangaseeActions();
break;
case "mangakatana.com":
mangakatanaActions();
break;
case "imgur.com":
imgurActions();
break;
case "cdn.jsdelivr.net":
jsdelivrActions();
break;
case "raw.githubusercontent.com":
githubRawActions();
break;
case "twitter.com":
case "x.com":
twitterActions();
break;
case "rss.agrmohit.com":
minifluxActions();
break;
case "www.reddit.com":
redditActions();
break;
case "anilist.co":
anilistActions();
break;
case "paperless.agrmohit.com":
paperlessActions();
break;
}