-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
libmedium.user.js
70 lines (63 loc) · 1.58 KB
/
libmedium.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
// ==UserScript==
// @name LibMedium proxy
// @version 0.1.1
// @description Re-writes medium.com URLs in point to libmedium
// @author Aravinth Manivannan
// @match https://*/*
// @match http://*/*
// @grant AGPLv3 or above
// ==/UserScript==
// websites to be proxied
const blacklist = [
"medium.com",
"blog.discord.com",
"uxdesign.cc",
"towardsdatascience.com",
"hackernoon.com",
"medium.freecodecamp.org",
"psiloveyou.xyz",
"betterhumans.coach.me",
"codeburst.io",
"theascent.pub",
"medium.mybridge.co",
"uxdesign.cc",
"levelup.gitconnected.com",
"itnext.io",
"entrepreneurshandbook.co",
"proandroiddev.com",
"blog.prototypr.io",
"thebolditalic.com",
"blog.usejournal.com",
];
// Location of the proxy
const libmediumHost = new URL("https://libmedium.batsense.net");
const isMedium = (url) => {
url = new URL(url);
if (blacklist.find((bl) => url.host.includes(bl))) {
return true;
}
let componenets = url.host.split(".");
let len = componenets.length;
if (
len > 1 &&
componenets[len - 1] == "com" &&
componenets[len - 2] == "medium"
) {
return true;
}
};
(function () {
"use strict";
if (!window.location.href.includes(libmediumHost.host)) {
let urls = document.links;
for (let i = 0; i < urls.length; i++) {
if (isMedium(urls[i])) {
let url = urls[i];
let path = url.pathname.split("-");
urls[i].pathname = `/utils/post/${path[path.length - 1]}`;
urls[i].host = libmediumHost.host;
urls[i].search = "";
}
}
}
})();