Greasy Fork

Greasy Fork is available in English.

Twitter expanded image

Replace image address to original and adjust single image's height. Work in with https://userstyles.org/styles/165662/expanded-twitter

当前为 2018-12-07 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitter expanded image
// @namespace    https://github.com/Boneflame/groessere-schriftgroesse
// @require
// @version      0.2
// @description  Replace image address to original and adjust single image's height. Work in with https://userstyles.org/styles/165662/expanded-twitter
// @author       Hitomi Jamella Hoshino
// @include      https://twitter.com/*
// @grant        none
// ==/UserScript==


//Replace image's address

function replace() {
	var img, match;
	for (img of document.images) {
		if (match = img.src.match(/(.*?pbs\.twimg\.com\/media\/.+)\.(jpg|gif|png|jpeg|bmp|webp)/)) {
            img.src = match[1] + "?format=" + match[2] + "&name=orig";
		}
	}
};

new MutationObserver(replace).observe(document.getElementsByClassName("stream-items")[0], {
	childList: true,
	subtree: true
});


//Adjust image's height

var stream_Width = document.getElementsByClassName("AdaptiveMedia-container")[0].clientWidth;
var single_photo, Bild, nWidth, nHeight, i;
//i = amount of single image that after site first load + keeping scroll down.
//var i = 0;

function adjust() {
    single_photo = document.getElementsByClassName("AdaptiveMedia-singlePhoto");
    //i = 0, when new tweet loaded, do the adjust ALL OVER.
    i = 0;
    while (i < single_photo.length) {
        Bild = single_photo[i].firstChild.nextSibling.firstChild.nextSibling;
        nWidth = Bild.naturalWidth;
        nHeight = Bild.naturalHeight;

        if (nHeight > 0) {
            if (nWidth < stream_Width) {
                single_photo[i].style.paddingTop = nHeight + 'px';
            }
            i++;
        }
        else {
            //When scroll to the bottom, stop loop, because image isn't loaded yet.
            single_photo = i;
        }
    }
};

//new MutationObserver(adjust).observe(document.getElementsByClassName("stream-items")[0], {
new MutationObserver(adjust).observe(document.body, {
	childList: true,
	subtree: true
});


//click "new tweets"

//total amount of single image after "new tweets" click
/*
var k = 0;
function bbb() {
    document.getElementsByClassName("new-tweets-bar")[0].onclick = function(){
        //j = amount of single image in each "new tweet" click
        var j = 0;
        single_photo = document.getElementsByClassName("AdaptiveMedia-singlePhoto");
        alert(single_photo.length);
        while (j < single_photo.length - i - k) {
            Bild = single_photo[j].firstChild.nextSibling.firstChild.nextSibling;
            nWidth = Bild.naturalWidth;
            nHeight = Bild.naturalHeight;

            if (nHeight > 0) {
                if (nWidth < stream_Width) {
                    single_photo[j].style.paddingTop = nHeight + 'px';
                    alert(Bild.src + single_photo.length);
                }
                j++;
                k++;
            }
        }
    }
};

new MutationObserver(bbb).observe(document.getElementsByClassName("stream-item")[0], {
	childList: true,
	subtree: true
});
*/