微博相册图片地址批量获取工具

批量获取微博相册图片地址

目前为 2016-03-17 提交的版本。查看 最新版本

// ==UserScript==
// @name        WeiboPhotoUrlBatchGet
// @name:zh-CN  微博相册图片地址批量获取工具
// @namespace   http://www.mapaler.com/
// @description BatchGetWeiboPhotoURL
// @description:zh-CN 批量获取微博相册图片地址
// @include     *://weibo.com/*/home*
// @include     *://photo.weibo.com/*/albums/detail/album_id/*
// @include     *://photo.weibo.com/*/photos*
// @version     1.1.0
// @grant       none
// @copyright   2016+, Mapaler <[email protected]>
// @icon        http://img.t.sinajs.cn/t5/style/images/register/logo_big.png
// ==/UserScript==

(function() {
var imgs = { img: [] };
function imgObj()
{
	var obj = {
		addFormUrl: function (url)
		{
			var regSrc = /(https?:\/\/[^\/]+)\/.+\/([\d\w]+)\.([\d\w]+)/ig;
			var result = regSrc.exec(url);
			if (result == null) return this;
			this.host = result[1];
			this.pid = result[2];
			this.extention = result[3];
			return this;
		},
		add: function (host, pid, extention)
		{
			if (extention == undefined) extention = "jpg";
			this.host = host;
			this.pid = pid;
			this.extention = extention;
			return this;
		},
		get: function (size)
		{
			if (size == undefined) size = "large";
			var src = "";
			src = this.host + "/" + size + "/" + this.pid + "." + this.extention;
			return src;
		},
		host: "",
		pid: "",
		extention: "",
		//width: 0,
		//height: 0,
		//large: "",	mw690: "",	mw600: "",	bmiddle: "",	small: "",	square: "",	sq612: "",	orj480: "",	smsq612all: "",	thumb300: "",	thumb180: "",	thumb150: "",	
	}
	return obj;
}

var win = document.createElement('div');
win.id = "WeiboPhotoUrlBatchGet"
win.className = "WPUBG_win"

var style = document.createElement("style");
win.appendChild(style);
style.type = "text/css";
style.innerHTML +=
	[
		".WPUBG_win" + "{\r\n" + [
            'box-shadow:0 0 10px #333',
            'position:fixed',
            'top:0',
            'right:0',
            'z-index:1000000',
            'font-family:arial,sans-serif',
            'padding:5px',
            'margin:0',
            'border-radius: 0 0 0 5px',
            'background:#F5F8FA',
		].join(';\r\n') + "\r\n}",
		".WPUBG_box" + "{\r\n" + [
            'width:180px',
		].join(';\r\n') + "\r\n}",
		".WPUBG_tra" + "{\r\n" + [
            'width:180px',
            'height:180px',
		].join(';\r\n') + "\r\n}",
		".WPUBG_cls" + "{\r\n" + [
			'width:40px',
			'box-shadow:0 0 2px #333',
			'position:absolute',
			'top:0',
			'left:-40px',
			'line-height:25px',
			'padding:0',
			'margin:0',
			'border-radius:0',
			'border:none',
			'background:#515151',
			'z-index:99999',
			'text-align:center',
			'color:#aaa',
			'cursor:pointer',
		].join(';\r\n') + "\r\n}",
	].join('\r\n');

var box = document.createElement('div');
box.className = "WPUBG_box";
win.appendChild(box);

var tra = document.createElement('textarea');
tra.className = "WPUBG_tra";
tra.wrap = "off";
box.appendChild(tra);

var lbl = document.createElement('label');
lbl.className = "WPUBG_lbl";
lbl.innerHTML = "Size:";
lbl.title = "常见尺寸:\r\nlarge\r\nmw690\r\nmw600\r\nbmiddle\r\nsmall\r\nsquare\r\nsq612\r\norj480\r\nsmsq612all\r\nthumb300\r\nthumb180\r\nthumb150";
box.appendChild(lbl);

var ipt = document.createElement('input');
ipt.className = "WPUBG_ipt";
ipt.type = "text";
ipt.placeholder = "large";
ipt.name = "WPUBG_size";
ipt.title = "常见尺寸:\r\nlarge\r\nmw690\r\nmw600\r\nbmiddle\r\nsmall\r\nsquare\r\nsq612\r\norj480\r\nsmsq612all\r\nthumb300\r\nthumb180\r\nthumb150";
ipt.value = getConfig("WPUBG_size");
ipt.onblur = function ()
{
	setConfig("WPUBG_size", this.value);
	reCreatList();
}
lbl.appendChild(ipt);
        
var cls = document.createElement('div');
cls.className = "WPUBG_cls";
win.appendChild(cls);
cls.innerHTML = '关闭';//关闭
cls.onclick = function (){	win.parentNode.removeChild(win);}


	
if (document.location.host == "photo.weibo.com")
{
	var album = !(typeof($GLOBAL_DETAIL) == "undefined");
	var btnGetAll = document.createElement('button');
	//btnGetAll.className = "W_ficon ficon_send S_ficon ";
	btnGetAll.innerHTML = "获取全部图片地址";
	btnGetAll.onclick = function () { getAll(album); }
	if (album)
		var insertPlace = document.getElementsByClassName("m_share_like")[0];
	else
		var insertPlace = document.getElementsByClassName("m_user_album")[0];
	insertPlace.insertBefore(btnGetAll, insertPlace.firstChild);
} else
{
	var btnGetUp = document.createElement('button');
	//btnGetUp.className = "W_ficon ficon_send S_ficon";
	btnGetUp.innerHTML = "获得上传的图地址";
	btnGetUp.onclick = function () { getUp(); }
	var insertPlace = document.getElementById("plc_top");
	insertPlace.appendChild(btnGetUp);
}

function getUp()
{
	if (win.parentNode || win.parentNode != document.body) document.body.appendChild(win);
	var drag_pic_list = document.getElementsByClassName("drag_pic_list")[0];
	var pics = drag_pic_list.getElementsByClassName("pic");
	for (var pi = 0; pi < pics.length; pi++)
	{
		var pdiv = pics[pi].getElementsByTagName("div")[0];
		var img = new imgObj;
		imgs.img.push(img.addFormUrl(pdiv.style.backgroundImage))
		tra.value += img.get() + "\r\n";
	}
}
function getAll(isAlbum)
{
	if (win.parentNode || win.parentNode != document.body) document.body.appendChild(win);
	if (imgs.img.length > 0)
		reCreatList();
	else
		getSource("http://photo.weibo.com/photos/get_all?uid=" + $CONFIG.owner_uid + (isAlbum?"&album_id=" + $GLOBAL_DETAIL.album_info.album_id:"") + "&count=1&type=1&__rnd=" + new Date().getTime(),
			getFirstJSON, $CONFIG.owner_uid, (isAlbum?"&album_id=" + $GLOBAL_DETAIL.album_info.album_id:isAlbum));
}

function getFirstJSON(response,uid, aid)
{
	var info = JSON.parse(response);
	getSource("http://photo.weibo.com/photos/get_all?uid=" + uid + (aid?"&album_id=" + aid:"") + "&count=" + info.data.total + "&type=1&__rnd=" + new Date().getTime(),
		getAllJSON, uid, aid);
}

function getAllJSON(response, uid, aid)
{
	var info = JSON.parse(response);
	plist = info.data.photo_list
	for (pi = plist.length - 1; pi >= 0; pi--)
	{
		var img = new imgObj;
		var regFn = /([\d\w]+)\.([\d\w]+)/ig;
		var resultFn = regFn.exec(plist[pi].pic_name);

		imgs.img.push(img.add(plist[pi].pic_host, plist[pi].pic_pid, resultFn[2]))
		//tra.value += img.get(size) + "\r\n";
	}
	reCreatList();
}

function reCreatList(size)
{
	if (size == undefined) size = getConfig("WPUBG_size").length > 0 ? getConfig("WPUBG_size") : "large";
	tra.value = "";
	for (pi = 0; pi < imgs.img.length; pi++)
	{
		tra.value += imgs.img[pi].get(size) + "\r\n";
	}
}

//直接通过XMLHttpRequest对象获取远程网页源代码
function getSource(url, callback, index, index2)
{
	var xhr = new XMLHttpRequest();	//创建XMLHttpRequest对象
	xhr.onreadystatechange = function ()  //设置回调函数
	{
		if (xhr.readyState == 4 && xhr.status == 200)
			callback(xhr.responseText, index, index2);
	}
	xhr.open("GET", url, true);
	xhr.send(null);
	return xhr.responseText;
}

function getConfig(key) {
	if (window.localStorage) {
		return window.localStorage.getItem(key) || "";
	} else {
		return getCookie(key);
	}
};
function setConfig(key, value) {
	if (window.localStorage) {
		window.localStorage.setItem(key, value);
	} else {
		setGdCookie(key, value, 86400 * 365);
	}
};

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址