Closed sticky topic
Сообщений 1 страница 30 из 32
Поделиться22018-06-18 19:18:04
Отредактировано forumd.ru (2018-06-18 19:18:08)
Поделиться32018-06-18 19:18:13
Отредактировано forumd.ru (2018-06-18 19:18:17)
Поделиться62018-06-18 19:19:02
Отредактировано forumd.ru (2018-06-18 19:19:06)
Поделиться82018-06-18 19:19:28
Отредактировано forumd.ru (2018-06-18 19:19:45)
Поделиться92018-06-18 19:19:50
Отредактировано forumd.ru (2018-06-18 19:20:05)
Поделиться112018-06-18 19:20:19
Отредактировано forumd.ru (2018-06-18 19:20:22)
Поделиться142018-06-18 19:21:00
Отредактировано forumd.ru (2018-06-18 19:21:02)
Поделиться152018-06-18 19:21:07
Отредактировано forumd.ru (2018-06-18 19:21:09)
Поделиться162018-06-18 19:21:15
Отредактировано forumd.ru (2018-06-18 19:21:18)
Поделиться172018-06-18 19:21:24
[b][/b]
Отредактировано forumd.ru (2018-06-18 19:21:32)
Поделиться192018-06-18 19:21:42
Отредактировано forumd.ru (2018-06-18 19:21:46)
Поделиться262018-07-13 20:24:56
<script type="text/javascript">
// remove the guest ForumAPITicket and insert manually
//you can see it by logging out the account and opening Sources (via chrome) (right mouse button -> source code -> Sources tab -> choose the current page in left list -> find ForumAPITicket)
GuestAPITicket='3f29aad94e883b9c00f7227d6a2fa700bd934768';
function NameTit()
{
var fname=prompt('Enter the chapter title!\n(leave blank if the fragment has no title)');
return (fname ? '[fragment=\"'+fname+'\"]':'[fragment]');
}
//Sending the toc by frame
$.postFrame = function(lnk,data) {
var rnd = Math.random().toString().substr(6);
$('<iframe src="about:blank" name="MyFrame_'+rnd+'" id="MyFrame_'+rnd+'"></iframe>').appendTo("head");
var form = $('<form action="'+lnk+'" target="MyFrame_'+rnd+'" method="post"></form>');
var kk, vk;
if(data) for(var inf in data){
vk=data[inf];
kk='<input name="'+inf+'" id="'+inf+'" value=\''+vk+'\' type="hidden" />';
form.append(kk);
}
setTimeout(function(){ //Sending
form.submit();
},50);
$('#MyFrame_'+rnd).on('load',function() {
if($.trim($(this).contents().html()).length>0)$(this).remove()
});
};
//Date format
$.chTime = function(time)
{
var ctime = new Date();
ctime.setTime(parseInt(time)*1000);
return (ctime.getDate()<10 ? "0" : "")+ctime.getDate()+"."+(ctime.getMonth()<9 ? "0" : "")+(ctime.getMonth()+1)+"."+ctime.getFullYear()+" "+ctime.toTimeString().replace(/ .+$/img, "");
}
//Check and replacement of the toc tag
var s='</p>',
e='<p>',
//c=$(this).html(),
x,
m,
end='<span class="fragment-inner">$1</span></div>';
x=s+'<div class="fragment"><h4 class="fragment-name">$1</h4><span class="fragment-inner">$2</span></div>'+e;
m=s+'<div class="fragment">'+end+e;
$('.post').find('.post-content:contains("[fragment=")').map(function() {
var c=$(this).html();
c=c.replace(/\n/mgi,'');
try
{
c=c.replace(/\[fragment=\"(.*?)\"\](.*?)\[\/fragment\]/mgi,x);
} catch(e){}
c=c.replace(/<p><\/p>/mgi,'');
$(this).html(c);
});
$('.post').find('.post-content:contains("[fragment]")').map(function() {
var c=$(this).html();
c=c.replace(/\n/mgi,'');
try
{
c=c.replace(/\[fragment\](.*?)\[\/fragment\]/mgi,m);
} catch(e){}
c=c.replace(/<p><\/p>/mgi,'');
$(this).html(c);
});
var punv = $('#pun-viewtopic').length,
punp = $('#pun-post').length,
pune = $('#pun-edit').length;
//Preview, sending and editing messages
if(punv || punp || pune)(function() {
var tl0='fragment';
var t0 = '<td id="button-fragment" style="cursor: pointer !important;"><img src="i/blank.gif" title="'+tl0+'" onclick="bbcode(NameTit(),\'[/fragment]\');"></td>';
var tid;
var this_author=false;
var last_rev, tmplr;
var this_chapter;
//If the topic view, then display the toc
if(punv || pune)
{
tid=(punv ? document.URL.split("id=")[1].split("#")[0].split("&p=")[0] : $("#pun-crumbs1").find("a:last").attr("href").split("id=")[1]);
//Request of the toc
this_chapter = JSON.parse($.ajax({
url: 'http://www.en.'+location.hostname.replace(/^www\./,'')+"/api.php?method=storage.get&key=chapters-"+tid,
async: false,
cache: false
}).responseText);
//If the toc exists
try
{
var q = /"/g,
a = /'/g;
//replace the unicode quotes and apostrophes
this_chapter=(this_chapter.response.storage.data['chapters-'+tid]).replace(q, "\"").replace(a, "\'");
this_chapter=JSON.parse(this_chapter);
//else empty array
} catch(e) {this_chapter=[];}
last_rev = JSON.parse($.ajax({
url: "/api.php?method=storage.get&key=newchp",
async: false,
cache: false
}).responseText);
try
{
last_rev=JSON.parse(last_rev.response.storage.data.newchp);
if(last_rev=='') last_rev={};
} catch(e){last_rev={};}
if(!(last_rev[tid]))
{
last_rev[tid]=0;
}
tmplr=last_rev[tid];
var hchp = '<div class="section"><div class="container chapt"><h4 class="fragment-name">The table of contents</h4><div class="formal chapters-box"><div id="chapters"><table id="chpt">';
//And make changes if there is an appropriate cookie
if($getCookie('postChap'))
{
$deleteCookie('postChap');
var cc=$('.endpost:last .fragment-name')
var PstId=$('.endpost:last').find('.permalink').attr('href').replace(/^.+?#p(\d+)$/gim,'$1');
var PstD=$('.endpost:last').attr('data-posted');
//If there is no toc element in the previous message
if($('.endpost:last').prev().find('.fragment').length==0 || cc.length)
{
//create new
this_chapter.push([PstId, PstId, PstD, (cc.length ? cc.text():"")]);
}else
{
//else
//the last post number
this_chapter[this_chapter.length-1][1] = PstId;
}
var titstr='[';
this_chapter.forEach(function(item, i)
{
//Asseble a line for bringing into the repository
titstr+='[\"'+item[0]+'\",\"'+item[1]+'\",\"'+item[2]+'\",\"'+item[3]+'\"],';
//Assemble the toc
hchp+='<tr class="'+(item[3] ? 'yname':'nname')+'"><td class="mrk">'+(item[3] ? '• </td><td class="namech">':'</td><td class="namech">⚬ ')
+'<a href="'+($('#p'+item[0]).length ? '#p'+item[0] :'http://'+location.hostname+'/viewtopic.php?pid='+item[0]+'#p'+item[0])+'"'
+'data-posted="'+item[2]+'">'+(item[3] ? '<span class="chp_name">'+item[3]+'</span>' : 'Fragment')+'</a></td><td class="datach" width="60%">'+' from '+$.chTime(item[2])
+' Moscow time '+(last_rev[tid]<item[2] ? '<span class="new_chp"> new </span>':'')+'</td></tr>';
if(tmplr<item[2]) tmplr=item[2];
//inserting the nav bar
var this_fragment=$('#p'+this_chapter[i][1]);
if(this_fragment.length)
{
try
{
var nav = '<div class="fragment-navigation"><ul>'+
(i!=0 ? '<li class="prev_fragment"><a href="'+($('#p'+this_chapter[i-1][0]).length?'#p'+this_chapter[i-1][0] : 'http://'+location.hostname+'/viewtopic.php?pid='+this_chapter[i-1][0]+'#p'+this_chapter[i-1][0])+'">\<\<Previous fragment</a></li>' : '')+
'<li class="back_chapter"><a href="#pun-main">To the table of contents</a></li>'+
(i!=this_chapter.length-1 ? '<li class="next_fragment"><a href="'+($('#p'+this_chapter[i+1][0]).length?'#p'+this_chapter[i+1][0] : 'http://'+location.hostname+'/viewtopic.php?pid='+this_chapter[i+1][0]+'#p'+this_chapter[i+1][0])+'">Next fragment\>\></a></li>' : '')+
'</ul></div>';
this_fragment.find('.post-box').after(nav);
} catch(e)
{
var nav = '<div class="fragment-navigation"><ul>'+
'<li class="back_chapter"><a href="#pun-main">To the table of contents</a></li>'+
'</ul></div>';
this_fragment.find('.post-box').after(nav);
}
}
});
titstr=titstr.substring(0,titstr.length-1)+']';
//bringing into the repository
$.postFrame(
'http://www.en.'+location.hostname.replace(/^www\./,'')+'/api.php',
{
method: 'storage.set',
user_id: 1,
token: GuestAPITicket,
key: 'chapters-'+tid,
value: titstr
});
} else
{
//if no cookie
//then asseble the toc and create the nav bar
this_chapter.forEach(function(item, i)
{
hchp+='<tr class="'+(item[3] ? 'yname':'nname')+'"><td class="mrk">'+(item[3] ? '• </td><td class="namech">':'</td><td class="namech">⚬ ')
+'<a href="'+($('#p'+item[0]).length ? '#p'+item[0] :'http://'+location.hostname+'/viewtopic.php?pid='+item[0]+'#p'+item[0])+'"'
+'data-posted="'+item[2]+'">'+(item[3] ? '<span class="chp_name">'+item[3]+'</span>' : 'Fragment')+'</a></td><td class="datach" width="60%">'+' from '+$.chTime(item[2])
+' Moscow time '+(last_rev[tid]<item[2] ? '<span class="new_chp"> new </span>':'')+'</td></tr>';
if(tmplr<item[2]) tmplr=item[2];
var this_fragment=$('#p'+this_chapter[i][1]);
if(this_fragment.length)
{
try
{
var nav = '<div class="fragment-navigation"><ul>'+
(i!=0 ? '<li class="prev_fragment"><a href="'+($('#p'+this_chapter[i-1][0]).length?'#p'+this_chapter[i-1][0] : 'http://'+location.hostname+'/viewtopic.php?pid='+this_chapter[i-1][0]+'#p'+this_chapter[i-1][0])+'">\<\<Previous fragment</a></li>' : '')+
'<li class="back_chapter"><a href="#pun-main">To the table of contents</a></li>'+
(i!=this_chapter.length-1 ? '<li class="next_fragment"><a href="'+($('#p'+this_chapter[i+1][0]).length?'#p'+this_chapter[i+1][0] : 'http://'+location.hostname+'/viewtopic.php?pid='+this_chapter[i+1][0]+'#p'+this_chapter[i+1][0])+'">Next fragment\>\></a></li>' : '')+
'</ul></div>';
this_fragment.find('.post-box').after(nav);
} catch(e)
{
var nav = '<div class="fragment-navigation"><ul>'+
'<li class="back_chapter"><a href="#pun-main">To the table of contents</a></li>'+
'</ul></div>';
this_fragment.find('.post-box').after(nav);
}
}
});
}
//if preview
if(this_chapter.length && punv)
{
if(last_rev[tid]!=tmplr && UserID!=1)
{
last_rev[tid]=tmplr;
$.post("/api.php", {
method: "storage.set",
token: ForumAPITicket,
key: "newchp",
value: JSON.stringify(last_rev)
}, "json");
}
//painting the toc
hchp+='</table></div></div></div></div>';
$('.topic').find('h2:first').before(hchp);
}
}else
{
//just to write the topic id on the sending page
tid=$("#pun-crumbs1").find("a:last").attr("href").split("id=")[1];
}
//author check
var sel=".topicpost .pl-email:first>a";
var id;
if(document.URL.indexOf('fid')>-1) {this_author = true;} else
if( $(".topicpost").length){ id = $(sel).attr("href").split("id=")[1]
} else
{
$.ajax({ url:"/viewtopic.php?id="+tid,async:false,cache:true,success:function(data){
id = $(data).find(sel).attr("href").split("id=")[1];
}});
}
if( id && +id == UserID) this_author = true;
//if author or moder
if(GroupID<=2 || !!this_author)
{
$('#button-right').after(t0);
// process the form, call the function...
var xx=$('[name="submit"]');
var nn=xx.length;
xx.click(function() {
//var tmp_chapter;
var cc = $('#main-reply:first').val();
var nameCook;
// if edit
if(pune)
{
//ajax call for next and previous post
//and related info
var pid = document.URL.split("id=")[1].split("&")[0];
var nextc, prevc, thc;
var dataPost;
var idn, idp;
$.ajax({ url:"/viewtopic.php?pid="+pid+"#p"+pid,async:false,cache:true,success:function(data){
thc = $(data).find('#p'+pid).text();
nextc = $(data).find('#p'+pid).next().text();
try
{
idn = $(data).find('#p'+pid).next().attr('id').replace(/p/gim,'');
} catch(e){}
prevc = $(data).find('#p'+pid).prev().text();
try
{
idp = $(data).find('#p'+pid).prev().attr('id').replace(/p/gim,'');
} catch(e){}
dataPost = $(data).find('#p'+pid).attr('data-posted');
}});
//if was the part of toc and now the part of toc
if(cc.indexOf('[/fragment]')!=-1 && thc.indexOf('[/fragment]')!=-1)
{
//now titled
if(cc.indexOf('[fragment=')!=-1)
{
//titled before
if(thc.indexOf('[fragment=')!=-1)
{
//change the title in the appropriate element
this_chapter.forEach(function(item, i){if(item[0]==pid)item[3]=cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'));});
} else
{
//no title before
//if previous and next messages are part of toc
if(nextc.indexOf('[/fragment]')!=-1 && prevc.indexOf('[/fragment]')!=-1)
{
//if next post has title
if(nextc.indexOf('[fragment=')!=-1)
{
//to change the ending post number in previous element
var idarr;
this_chapter.forEach(function(item, i)
{
if(item[1]==pid)
{
idarr=i;
item[1]=idp;
}
});
//and insert a new toc element
this_chapter.splice(idarr+1,0,[pid, pid, dataPost, cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'))]);
} else
{
//if no title
//find and change previous
var idarr;
var tmp;
this_chapter.forEach(function(item, i)
{
if(item[0]<pid && pid<item[1])
{
idarr=i;
tmp=item[1];
item[1]=idp;
}
});
//and insert new
//And I'm too lazy to keep commenting.
this_chapter.splice(idarr+1,0,[pid, tmp, dataPost, cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'))]);
}
} else if(nextc.indexOf('[/fragment]')!=-1)
{
this_chapter.forEach(function(item)
{
if(item[0]==pid)
{
item[3]=cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'));
}
});
} else if(prevc.indexOf('[/fragment]')!=-1)
{
var idarr;
this_chapter.forEach(function(item, i)
{
if(item[1]==pid)
{
idarr=i;
item[1]=idp;
}
});
this_chapter.splice(idarr+1,0,[pid, pid, dataPost, cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'))]);
} else
{
//var idarr=0;
this_chapter.forEach(function(item, i)
{
if(item[0]==pid)
{
item[3]=cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'));
}
});
//this_chapter.splice(idarr+1,0,[pid, pid, dataPost, cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'))]);
}
}
} else
{
if(thc.indexOf('[fragment=')!=-1)
{
if(prevc.indexOf('[/fragment]')!=-1)
{
var idarr;
this_chapter.forEach(function(item, i)
{
if(item[0]==pid)
{
this_chapter[i-1][1]=item[1];
idarr=i;
}
});
this_chapter.splice(idarr,1);
} else
{
this_chapter.forEach(function(item, i)
{
if(item[0]==pid)
{
item[3]="";
}
});
}
}
}
} else if(cc.indexOf('[/fragment]')!=-1)
{
if(cc.indexOf('[fragment=')!=-1)
{
if(nextc.indexOf('[/fragment]')!=-1 && prevc.indexOf('[/fragment]')!=-1)
{
if(nextc.indexOf('[fragment=')!=-1)
{
var idarr;
this_chapter.forEach(function(item, i)
{
if(item[1]==idp)
{
idarr=i;
}
});
this_chapter.splice(idarr+1,0,[pid, pid, dataPost, cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'))]);
} else
{
this_chapter.forEach(function(item, i)
{
if(item[0]==idn)
{
item[0]=pid;
item[3]=cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'));
}
});
}
} else if(nextc.indexOf('[/fragment]')!=-1)
{
if(nextc.indexOf('[fragment=')!=-1)
{
var idarr;
this_chapter.forEach(function(item, i)
{
if(item[0]==idn)
{
idarr=i;
}
});
this_chapter.splice(idarr,0,[pid, pid, dataPost, cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'))]);
} else
{
this_chapter.forEach(function(item, i)
{
if(item[0]==idn)
{
item[0]=pid;
item[3]=cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'));
}
});
}
} else if(prevc.indexOf('[/fragment]')!=-1)
{
var idarr;
this_chapter.forEach(function(item, i)
{
if(item[1]==idp)
{
idarr=i;
}
});
this_chapter.splice(idarr+1,0,[pid, pid, dataPost, cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'))]);
} else
{
var idarr=0;
this_chapter.forEach(function(item, i)
{
if(item[0]<pid)
{
idarr=i;
}
});
this_chapter.splice(idarr+1,0,[pid, pid, dataPost, cc.substring(cc.indexOf('[fragment="')+11,cc.indexOf('"]'))]);
}
} else
{
if(nextc.indexOf('[/fragment]')!=-1 && prevc.indexOf('[/fragment]')!=-1)
{
if(nextc.indexOf('[fragment=')!=-1)
{
this_chapter.forEach(function(item, i)
{
if(item[1]==idp)
{
item[1]=pid;
}
});
} else
{
var idarr;
this_chapter.forEach(function(item, i)
{
if(item[1]==idp)
{
idarr=i;
item[1]=this_chapter[i+1][1];
}
});
this_chapter.splice(idarr+1,1);
}
} else if(nextc.indexOf('[/fragment]')!=-1)
{
if(nextc.indexOf('[fragment=')!=-1)
{
var idarr;
this_chapter.forEach(function(item, i)
{
if(item[0]==idn)
{
idarr=i;
}
});
this_chapter.splice(idarr,0,[pid, pid, dataPost, ""]);
} else
{
this_chapter.forEach(function(item, i)
{
if(item[0]==idn)
{
item[0]=pid;
}
});
}
} else if(prevc.indexOf('[/fragment]')!=-1)
{
this_chapter.forEach(function(item, i)
{
if(item[1]==idp)
{
item[1]=pid;
}
});
} else
{
var idarr=0;
this_chapter.forEach(function(item, i)
{
if(item[0]<pid)
{
idarr=i;
}
});
this_chapter.splice(idarr+1,0,[pid, pid, dataPost, ""]);
}
}
} else if(thc.indexOf('[/fragment]')!=-1)
{
if(nextc.indexOf('[/fragment]')!=-1 && prevc.indexOf('[/fragment]')!=-1)
{
if(nextc.indexOf('[fragment=')!=-1)
{
var idarr;
this_chapter.forEach(function(item, i)
{
if(item[1]==pid)
{
idarr=i;
item[1]=idp;
}
});
if(thc.indexOf('[fragment=')!=-1)
this_chapter.splice(idarr,1);
} else
{
if(thc.indexOf('[fragment=')!=-1)
{
this_chapter.forEach(function(item, i)
{
if(item[0]==pid)
{
item[0]=idn;
item[3]="";
}
});
}else
{
var idarr;
var tmp;
this_chapter.forEach(function(item, i)
{
if(item[0]<pid && pid<item[1])
{
idarr=i;
tmp=item[1];
item[1]=idp;
}
});
this_chapter.splice(idarr+1,0,[idn, tmp, dataPost, ""]);
}
}
} else if(nextc.indexOf('[/fragment]')!=-1)
{
if(nextc.indexOf('[fragment=')!=-1)
{
var idarr;
this_chapter.forEach(function(item, i)
{
if(item[0]==pid)
{
idarr=i;
}
});
this_chapter.splice(idarr,1);
} else
{
this_chapter.forEach(function(item, i)
{
if(item[0]==pid)
{
item[0]=idn;
item[3]="";
}
});
}
} else if(prevc.indexOf('[/fragment]')!=-1)
{
if(thc.indexOf('[fragment=')!=-1)
{
var idarr=0;
this_chapter.forEach(function(item, i)
{
if(item[1]==pid)
{
idarr=i;
}
});
this_chapter.splice(idarr,1);
} else
{
this_chapter.forEach(function(item, i)
{
if(item[1]==pid)
{
item[1]==idp;
}
});
}
} else
{
var idarr=0;
this_chapter.forEach(function(item, i)
{
if(item[1]==pid)
{
idarr=i;
}
});
this_chapter.splice(idarr,1);
}
}
//asseble a line for bringing into the repository
var titstr='[';
this_chapter.forEach(function(item, i)
{
titstr+='[\"'+item[0]+'\",\"'+item[1]+'\",\"'+item[2]+'\",\"'+item[3]+'\"],';
});
titstr=titstr.substring(0,titstr.length-1)+']';
//of the line has a title
if(titstr.length>1)
{
$.postFrame(
'http://www.en.'+location.hostname.replace(/^www\./,'')+'/api.php',
{
method: 'storage.set',
user_id: 1,
token: GuestAPITicket,
key: 'chapters-'+tid,
value: titstr
});
} else //else delete
{
$.post('http://www.en.'+location.hostname.replace(/^www\./,'')+'/api.php', {
method: "storage.delete",
token: GuestAPITicket,
key: 'chapters-'+tid
}, "json");
}
//if create new post
//and form has element
} else if(cc.indexOf('[/fragment]')!=-1)
{
//create cookie
nameCook='postChap';
$setCookie(nameCook, true, 120*1000);
}
});
//if delete post
$('[name="delete"]').click(function() {
var pid = document.URL.split("id=")[1].split("&")[0];
if($('post-content:contains("[/fragment]")').length)
{
var titstr='[';
this_chapter.forEach(function(item){if(item[0]!=pid || item[1]!=pid)
{
if(item[1]==pid) item[1]=$(this).prev().attr("href").split("id=")[1];
if(item[0]==pid) item[0]=$(this).next().attr("href").split("id=")[1];
titstr+='[\"'+item[0]+'\",\"'+item[1]+'\",\"'+item[2]+'\",\"'+item[3]+'\"],';
}});
titstr=titstr.substring(0,titstr.length-1)+']';
if(titstr.length>1)
{
$.postFrame(
'http://www.en.'+location.hostname.replace(/^www\./,'')+'/api.php',
{
method: 'storage.set',
user_id: 1,
token: GuestAPITicket,
key: 'chapters-'+tid,
value: titstr
});
} else
{
$.post('http://www.en.'+location.hostname.replace(/^www\./,'')+'/api.php', {
method: "storage.delete",
token: GuestAPITicket,
key: 'chapters-'+tid
}, "json");
}
}
});
}
else
{
$('.formsubmit .button').click(function() {
var txt = $('#main-reply:first').val();
if(txt.indexOf('[/fragment]')!=-1)
{
alert('You're not allowed to use the table of contents tags outside of your artworks!');
$('.button[disabled]').removeAttr('disabled');return false;
}
});
}
}());
</script>