Reddit Image Direcly (Farside)

This script uses the farside.link gateway to redirect images direcly on reddit

目前為 2025-01-23 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            Reddit Image Direcly (Farside)
// @namespace       https://greasyfork.org/users/821661
// @match           https://www.reddit.com/media?url=*
// @grant           none
// @version         1.0
// @run-at          document-start
// @license         GPL-3.0
// @author          hdyzen
// @description     This script uses the farside.link gateway to redirect images direcly on reddit
// ==/UserScript==

// This script works thanks to farside.link gateway: https://github.com/benbusby/farside
// Alternatively, you can use an extension to upload the image directly to Reddit:
// Only for Firefox: https://addons.mozilla.org/pt-BR/firefox/addon/load-reddit-images-directly/

const getUrlObj = (url) => new URL(url);

const getImgUrl = (url) => {
	const nUrl = getUrlObj(url);
	const paramUrl = getUrlObj(nUrl.searchParams.get("url"));
	console.log(nUrl);

	if (paramUrl.hostname === "external-preview.redd.it") {
		return `https://farside.link/libreddit/preview/external-pre${paramUrl.pathname + paramUrl.search}`;
	}

	const fileName = paramUrl.pathname.match(/[^-\/]+\.(?:png|jpg|jpeg)$/)?.[0];
	return `https://farside.link/libreddit/img/${fileName}`;
};

window.location.href = getImgUrl(window.location.href);