userscript: proxy using post ID
This commit is contained in:
parent
9c5342a053
commit
c438ea3b2d
1 changed files with 49 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
|||
// ==UserScript==
|
||||
// @name LibMedium proxy
|
||||
// @version 0.1.0
|
||||
// @version 0.1.1
|
||||
// @description Re-writes medium.com URLs in point to libmedium
|
||||
// @author Aravinth Manivannan
|
||||
// @match https://*/*
|
||||
|
@ -9,25 +9,62 @@
|
|||
// ==/UserScript==
|
||||
|
||||
// websites to be proxied
|
||||
const blacklist = ["medium.com", "blog.discord.com", "uxdesign.cc"];
|
||||
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 = "https://libmedium.batsense.net";
|
||||
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";
|
||||
|
||||
// morty has a button to go to the original site, re-writing that would be stupid
|
||||
if (!window.location.href.includes(libmediumHost)) {
|
||||
if (!window.location.href.includes(libmediumHost.host)) {
|
||||
let urls = document.links;
|
||||
let lib = new URL(libmediumHost);
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
blacklist.forEach((url) => {
|
||||
if (urls[i].host.includes(url)) {
|
||||
urls[i].host = lib.host;
|
||||
}
|
||||
});
|
||||
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 = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
Loading…
Reference in a new issue