Eyes Tool,用于Flickr的Greasemonkey脚本

2009年11月4日 | 标签: , , ,

因为要最近的eyes都是关于flickr的,而每次收集这样的图并通过wordpress发布是很麻烦的。于是想写一个脚本来完成一些工作。原本想的是用python来处理的,但是仔细想想,而且平时基本都是用Firefox在浏览网页,而且Greasemonkey都是必备扩展,使用Greasemonkey的效率更高,也可以再学习下Javascript。

// ==UserScript==
// @name           Eyes Tool.Show image information for eyes.
// @namespace      http://5.yupana.net
// @include        *flickr.com/photos/*/*
// ==/UserScript==

function xPath (arg) {
    return document.evaluate(
    arg,document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}

var images = xPath('//div[starts-with(@id,"photo")]//img');
var image = images.snapshotItem(0);
var titles = xPath('//meta[starts-with(@name,"title")]');
var title = titles.snapshotItem(0);
var url = window.location.href;
var text = '&ltstrong&gt' + title.content + '&lt\/strong&gt <br /> &ltimg title="' + title.content + '" src="' + image.src + '" alt="' + title.content + '" width="' + image.width + '" height="' + image.height + '" \/&gt <br /> &lta href="' + url + '" target="_blank"&gt' + url + '&lt/a&gt<br />';
var newdiv = document.createElement('div');
newdiv.innerHTML = text;
image.parentNode.appendChild(newdiv, image);
//======end===
目前还没有任何评论.

Switch to our mobile site