用于调整Blogger帖子中照片大小的JavaScript [英] JavaScript for resizing photos in Blogger posts
问题描述
我正在尝试自动调整Blogger帖子中照片的大小(运气不佳).基本上,我需要一段JavaScript,
I am trying to automate resizing of photos in Blogger posts (without much luck). Basically I need a piece of JavaScript that would
- 找到所有元素
- 在上述每个元素中找到所有元素
这些形式:
<img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 265px;" src="http://1.bp.blogspot.com/-y8j5IluAe4g/TykduAo1gnI/AAAAAAAAD38/K6VakbKwowU/s400/Czerwony%2BStompee%2Bdla%2Bdzieci.jpeg" alt="" id="BLOGGER_PHOTO_ID_5704123079323910770" border="0" />
对于其中的每一个,我需要:
For every one of these I need to:
- 将
width: 400px;
更改为width: 556px;
- 删除
height: 256px;
- 将链接中的字符串
/s400/
更改为/s556/
- change
width: 400px;
towidth: 556px;
- remove
height: 256px;
- change the string
/s400/
in the link to/s556/
所以在更改之后我得到了:
So after the changes I get:
<img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 556px;" src="http://1.bp.blogspot.com/-y8j5IluAe4g/TykduAo1gnI/AAAAAAAAD38/K6VakbKwowU/s556/Czerwony%2BStompee%2Bdla%2Bdzieci.jpeg" alt="" id="BLOGGER_PHOTO_ID_5704123079323910770" border="0" />
我正在使用的博客是: http://buczekmruczek.blogspot.com/2012/01/rowerkiem-przez-bedgebury-forest.html (调整了第一张照片的尺寸,以下未更改)
The blog I am working with is: http://buczekmruczek.blogspot.com/2012/01/rowerkiem-przez-bedgebury-forest.html (the first photo is resized, the following not)
对于提示和/或代码示例,我将不胜感激.
I would be grateful for hints and/or code samples.
推荐答案
对于希望获得可复制复制答案的人,只需将此脚本粘贴到模板末尾:
For people who want a copy-pastable answer, just paste this script somewhere at the end of the template:
<script type='text/javascript'>
/* <![CDATA[ */
var imageTags = document.getElementsByTagName('img');
for(i = 0 ; i < imageTags.length; i++){
if( imageTags[i].src.indexOf('/s400/', 0)>-1 ) {
if(imageTags[i].style.width=='400px')
imageTags[i].style.width='556px';
else
imageTags[i].style.width='368px';
imageTags[i].style.height='';
imageTags[i].src=imageTags[i].src.replace('/s400/', '/s556/');
}
}
/* ]]> */
</script>
这篇关于用于调整Blogger帖子中照片大小的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!