There are 19 previous versions of this script.
// ==UserScript==
// @author Chamie (id290393)
// @name vk_quickphotos
// @include http://vkontakte.ru/photo*
// @include http://www.vkontakte.ru/photo*
// @include http://vk.com/photo*
// @include http://www.vk.com/photo*
// @description Добавляет панель быстрой навигации по фотографиям альбома на ВКонтакте.ру
// @version 1.3.6.2
// ==/UserScript==
var pagesize;
var current_page;
var show_qnav;
var ph; //массив информации о фотографиях, выдранный со страницы.
var current;//номер текущего фото
function ge(element_name){//такие функции есть во фреймворке Вконтакте
return(document.getElementById(element_name));
}
function show_all(){
wnd = window.open();
wnd.focus();
wnd.document.open();
txt = "<html><head><title>Все фото</title></head><body>";
for (i=0;i<ph.length;i++){
txt+="<a href='http://vkontakte.ru/photo"+ph[i][0];
txt+="' onclick='selectCurrent(";
txt+=(i+1)+");'>";
txt+= "<img src='"+ph[i][2]+"'>";
txt+="</a>\n";
}
txt+="</body></html>";
wnd.document.write(txt);
wnd.document.close();
}
function selectCurrent(num){
var output="Num(page):";
num = (num)?num:ph.length;
num = (num>ph.length)?1:num;
if(current_page != Math.floor((num-1)/pagesize))
show_navbar(Math.floor((num-1)/pagesize));
num = ((num-1)%pagesize)+1;
var tds = ge("row").getElementsByTagName("td");
for(var i = 0; i<tds.length;i++){
if (i == (num-1)){
tds[i].style.borderWidth="3px";
tds[i].style.borderStyle="solid";
}
else{
tds[i].style.borderWidth="1px";
tds[i].style.borderStyle="dashed";
}
}
ge("quickBrowse").scrollLeft=((num-1)-1.7)*136;//сдвиг на 1.7 превьюхи. Это примерно расстояние до цнтра
}
function show_navbar(page){
var cur_photo = window.location.hash.replace("#photo/","");
if(cur_photo)
for(var i=0; i< ph.length;i++)
if (ph[i][0]==cur_photo)
current = i+1;
if(typeof(page)=='undefined'){
page = Math.floor((current-1)/pagesize);
current_page = page;
}
var parent = ge("photoborder");
if (ge("quick_nav_wrapper")){
parent.removeChild(ge("quick_nav_wrapper"));
}
var wrapperDiv = document.createElement("div");
wrapperDiv.style.width="100%";
wrapperDiv.align="center";
wrapperDiv.id="quick_nav_wrapper";
var bar = document.createElement("div");
bar.id ="quickBrowse";
bar.setAttribute("style","width:97%;overflow:auto;");
//Добавляем ссылку для перехода к прев. странице превью:
if(page){
var goUpDiv = document.createElement("div");
goUpDiv.setAttribute("style","width:97%;text-align:left");
txt="<a id='goUp'>↑ предыдущие "+pagesize+" фото ↑</a>";
goUpDiv.innerHTML= txt;
goUpDiv.addEventListener("click",function(){show_navbar(page-1);},false);
wrapperDiv.appendChild(goUpDiv);
}
//Добавляем таблицу с превьюхами:
txt = "<table><tr valign='middle' id='row'>";
var start = page*pagesize;
var end = start+(pagesize-1);
end = (end > ph.length)?(ph.length-1):end;
for (i=start;i<=end;i++){
txt+="<td style='text-align:center;border-color:#678AA9;border-width:1px;border-style:dashed;";
txt+="text-align:center;min-width:130px;'>";
txt+="<a href='#photo/"+ph[i][0];
txt+="' id='thumb"+i+"'>";
txt+= "<img src='"+ph[i][1]+"' style='max-height:130px'>";
txt+="</a></td>";
}
txt+="</tr></table>";
bar.innerHTML=txt;
wrapperDiv.appendChild(bar);
if(end<ph.length-1){
var goDownDiv = document.createElement("div");
goDownDiv.setAttribute("style","width:97%;text-align:right");
txt="<a>↓ следующие "+(((ph.length-end-1)<pagesize)?(ph.length-end-1):pagesize)+" фото ↓</a>";
goDownDiv.innerHTML= txt;
goDownDiv.addEventListener("click",function(){show_navbar(page+1);},false);
wrapperDiv.appendChild(goDownDiv);
}
parent.appendChild(wrapperDiv);
//Добавляем обработчики кликов:
for (i=start;i<=end;i++){
eval('var select=function(){selectCurrent('+(i+1)+');}');
ge("thumb"+i).addEventListener("click",select,false);
}
ge("photoareaouter").addEventListener("click",function(){selectCurrent(unsafeWindow.this_id+1);}, false);
ge("nextp").addEventListener("click",function(){selectCurrent(current+1);}, false);
ge("prevp").addEventListener("click",function(){selectCurrent(current-1);}, false);
}
function switchQuickView(e){
var btn= e.target;
show_qnav = !show_qnav;
btn.innerHTML = (show_qnav)?"Скрыть":"Показать";
if(show_qnav){
show_navbar();
selectCurrent(current);
}
else
ge("photoborder").removeChild(ge("quick_nav_wrapper"));
GM_setValue("show_quickphotonav",show_qnav);
}
function addBrowseBar(){
if (typeof(unsafeWindow.ph)=='undefined') return;//thx 2 NiCloAy 4 a reference 2 'unsafeWindow' =)
pagesize = GM_getValue("pagesize",100);
show_qnav = GM_getValue("show_quickphotonav",false);
var txt=". <a id='switchQuickView'>";
txt+=(show_qnav)?"Скрыть":"Показать";
txt+="</a>";
txt+="<input id='pagesize_input' style='height:13px;width:33px' type='number' value='";
txt+=pagesize+"' /> <a id='showallbutton'>Показать все</a>";
ge("photodate").innerHTML+=txt;
ge("pagesize_input").addEventListener("change",function(){pagesize=this.value;GM_setValue("pagesize",pagesize);show_navbar();},false);
ge("showallbutton").addEventListener("click",function(){show_all();},false);
ge("switchQuickView").addEventListener("click",switchQuickView,false);
ph = unsafeWindow.ph;
current = unsafeWindow.this_id;
if(show_qnav){
show_navbar();
selectCurrent(current);
}
}
addBrowseBar();
