微博图片全显示

同屏显示多图微博的全部大图。

目前為 2015-07-13 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        微博图片全显示
// @namespace   hzhbest
// @include     http://weibo.com/*
// @include     http://www.weibo.com/*
// @description    同屏显示多图微博的全部大图。
// @version     1.3
// @grant       none
// ==/UserScript==

(function() {

	// http://weibo.com/2710065263/BmxiVDCgt?from=page_1005052710065263_profile&wvr=6&mod=weibotime&type=comment#_rnd1436436058420
	// http://weibo.com/2328516855/CnYCvixUq?type=comment#_rnd1436493435761
var regex = /weibo\.com\/\d{10}\/[a-z0-9A-Z]{9}\??/;

// window.addEventListener('load', function(){if (regex.test(document.location.href)) {setTimeout(init, 3000);}}, false);
if (regex.test(document.location.href)) init(); //console.log(regex.test(document.location.href));

function init(){  console.log("init");
	var list_ul = getElementsByClass("list_ul", 'div')[0]; //alert(!list_ul + "1");
	var expbox = getElementsByClass("WB_expand_media_box", 'div')[0]; //alert(!expbox + "2");
	if (!list_ul && !expbox){
		setTimeout(init, 2000); //console.log("wait2a");
		return;
	} else if (!!list_ul){
		if (!expbox) {  //console.log("exit");
			return;
		} else if (!list_ul.getElementsByTagName('div')[0] && !getElementsByClass("tips_rederror", 'div')[0]){
			setTimeout(init, 1000); //console.log("wait2b");
			return;
		} else if (document.documentElement.scrollTop < 400){
			setTimeout(init, 300); //console.log("wait2c");
			return;
		} else { //console.log(document.documentElement.scrollTop);
			go();
		}
	}
}

function go(){
	var wrpbox = getElementsByClass("WB_media_wrap", 'div')[0];
	var expbox = getElementsByClass("WB_expand_media_box", 'div')[0];
	var box = wrpbox.parentNode;
	var imgthumbs = wrpbox.getElementsByTagName('img');
	var imgsrc = [], imgs = [], imgl = imgthumbs.length;

	// Insert CSS
	var headID = document.getElementsByTagName("head")[0];         
	var cssNode = creaElemIn('style', headID);
	cssNode.type = 'text/css';
	cssNode.innerHTML = '.big_pic{max-width: 890px;} .WB_frame_c {width: auto !important; max-width: 920px; min-width: 600px;} .WB_text.W_f14, .WB_text{width: 520px;} .media_box{display: none !important;}';
	
	for (var i = 0; i < imgl; i++) {
		if (/\/square\//.test(imgthumbs[i].src)) {		// http://ww1.sinaimg.cn/square/c0788b86gw1etxemfiltjj20go0gowf8.jpg
			imgsrc[i] = imgthumbs[i].src.replace("/square/", "/large/");
		} else if (/\/thumbnail\//.test(imgthumbs[i].src)) {	// http://ww3.sinaimg.cn/thumbnail/bfc243a3gw1etx3ffxyhvg206y03ukjm.gif
			imgsrc[i] = imgthumbs[i].src.replace("/thumbnail/", "/large/");
		} else {
			continue;
		}
		imgs[i] = creaElemIn('img', box);
		creaElemIn('br', box);
		imgs[i].src = imgsrc[i];
		imgs[i].className = "big_pic";
	}
	// console.log(!!wrpbox + "1 " + !!expbox + "2");
	if (!!wrpbox) box.removeChild(wrpbox);
	if (!!expbox) expbox.parentNode.removeChild(expbox);
	document.documentElement.scrollTop = 360;
}

// Create an element
function creaElemIn(tagname, destin) {
	var theElem = destin.appendChild(document.createElement(tagname));
	return theElem;
}

function getElementsByClass(cName ,tagName){
	var elements = tagName ? document.getElementsByTagName(tagName) : document.getElementsByTagName('*');
	var findEles = [];
	var reg = new RegExp('^'+cName+'\\s*|\\s+'+cName+'\\s+|\\s+'+cName+'$');
	for(var i=0;i<elements.length;i++) {
		if(reg.test(elements[i].className))findEles.push(elements[i]);          
	}
	return findEles;
}


})();