Greasy Fork

Greasy Fork is available in English.

Tumblr Images to HD Redirector

Automatically promotes Tumblr image links to raw HD versions

当前为 2017-08-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Tumblr Images to HD Redirector
// @namespace    TumblrImgReszr
// @description  Automatically promotes Tumblr image links to raw HD versions
// @version      0.8
// @author       Kai Krause <[email protected]>
// @match        http://*.media.tumblr.com/*
// @match        https://*.media.tumblr.com/*
// @grant        GM_xmlhttpRequest
// @connect      media.tumblr.com
// @run-at       document-start
// ==/UserScript==

// Check if this page contains a single image whose source is also the location.
var image = document.getElementsByTagName('img')[0];
var loc = location.toString();
var imageType = loc.match(/[^.]*$/);
var checkSize;

if (image && image.getAttribute('src') == loc) {
	// Do not create a looped redirect by redirecting already HD images to itself
	if (loc.includes('_raw') || loc.includes('_1280')) return;
	
	// If the URL is HTTP, change it to HTTPS
	if (!loc.startsWith('https://')) {
		loc = loc.replace(/^http/, 'https');
	}
	
	checkSize = function(i) {
		// Define which patterns to check
		var i = i || 0;
		var imageSizes = ['raw', '1280'];
		if (i > imageSizes) return;
		
		// Create the HD image url pattern
		var newLoc = loc;
		if (imageSizes[i] == 'raw') {
			newLoc = newLoc.replace(/[^/]*media.tumblr.com/, 'media.tumblr.com');
			newLoc = newLoc.replace(/[^_]*$/, imageSizes[i] + '.' + imageType[0]);
		} else {
			newLoc = newLoc.replace(/[^_]*$/, imageSizes[i] + '.' + imageType[0]);
		}
		
		// Check that the HD image exists, then redirect to it
		GM_xmlhttpRequest({
			url: newLoc,
			method: 'HEAD',
			onload: function(response) {
				if (response.status != '200') {
					checkSize(i+1);
					return;
				}
				window.location = newLoc;
			}
		});
	};
	checkSize();
}