[fragment="Foreword"]Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum[/fragment]
Table of contents
Сообщений 1 страница 9 из 9
Поделиться22018-07-13 20:44:35
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum
[fragment="Chapter 1"]Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat, facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.[/fragment]
Поделиться32018-07-13 20:44:58
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum
[fragment="Chapter 2"]Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat, facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.[/fragment]
Поделиться42018-07-13 20:46:03
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum
[fragment="Chapter 3"]Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiaе consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat, facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.[/fragment]
Поделиться52018-07-13 20:47:22
Tool for making the table of contents on the literary forums
Adds a new button to the reply form which allows to select a fragment of the message, give it a title (or leave untitled) and bring it into the table of contents on the topic page
Author: Ezingrin
Platform: MyBB
Description:
Every user sees a new button in topics, created or being created by them (admins and moders see it always). The button allows to select a fragment of the message, give it a title (or leave untitled) and bring it into the table of contents.
The table of contents is created automatically when you select the first fragment.
After the toc is created it's shown in the block above the messages of the topic. The toc displays the fragments' titles (if they have no ones, then link is named as "Fragment") and the posting time in Moscow time zone. New fragments (individually for each user) highlight by an icon (new).
Below every message that conents the fragment of the toc or a block of such messages (untitled fragmets in sequence) there are a navigation bar which, I hope, is intuitive.
CSS:
#button-fragment{background:url(http://sa.uploads.ru/kl9Aw.png) no-repeat;} .chapters-box { height: 15em; overflow: auto; } #chapters { width: 40em; margin: auto; padding-bottom: 1em; } .chapt .fragment-name { display: block; padding-top: 0.7em; font-size: 1.3em; font-weight: bold; font-style: normal; text-align: center; margin: 0; } #chpt td { border: none !important; padding: 0.5em 0 0 0; } .mrk { width:1em; text-align: center; } .newc { width:5em; } .new_chp { background-color: #ca050f; border-radius: 10px; font-weight: bold; color: #ffe78a; } .chp_name { font-size: 1.1em; font-weight: 600; font-style: normal; } .fragment { border: 1px solid; border-color: #fff #ccc #ccc #fff; margin: 0.4em 1.8em 1.4em 1.8em; padding: 1em; background-color: #fff9e7; } .fragment h4 { display: block; padding-bottom: 0.7em; font-size: 1.3em; font-weight: bold; font-style: normal; text-align: center; margin: 0; } .fragment-navigation { border-top: 1px solid #ccc; } .fragment-navigation ul { margin: 0; padding: 4px; text-align: center; } .fragment-navigation ul li { display: inline; margin-right: 5px; padding: 3px; }
JS (To HTML-bottom):
<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 are not allowed to use the table of contents tags outside of your artworks!'); $('.button[disabled]').removeAttr('disabled');return false; } }); } }()); </script>
Поделиться92018-07-13 21:27:25
Modify the hide text
Scipt improves the abilities of the hide text: by groups, certain users, age or reputation.
Author: Duka
Platform: MyBB
This script improves the standard abilities of "hide text".
Includes the next conditions:
Возможности использования по нескольким условиям:
• by reputation points (respect);
• by positive points;
• by group;
• by certain user;
• by age.
Put the script to HTML - Form of reply (Admin → Options: 7th form). If you need the script only for closed topics, then put it to HTML-bottom (Admin → Options: 2nd form).
How does it work? Use the standard hide , then, in the beginning of hide's body, write one of the next requirements:
user=56; //for user with id=56 (check the profile link)
group=3; //for group. Check the id in the parameter show_group= of the Members page web address
respect=50; //for users with total reputation (+/-) is over 50
positive=20; //for users with total positive (+/-) is over 20
age=18; //for users over 18 years old
For example,
[hide]group=2; Message for moderators...[/hide]
With the number of posts requirement
[hide=20]group=2; Message for moderators having 20 posts...[/hide]
Screen:
Script:
<script type="text/javascript"> var quote = document.getElementsByTagName("blockquote") var n, condition; var typet = new Array("respect", "group", "positive", "user", "age"); var typer = new Array((UserRespectPlus-UserRespectMinus).toString(), (GroupID).toString(), (UserPositivePlus-UserPositiveMinus).toString(), (UserID).toString(), (UserAge).toString()); for(q=0;q<typet.length;q++){ for(i=0;i<quote.length;i++){ if(quote[i].previousSibling.innerHTML.indexOf("Скрытый текст")!=-1){ if(quote[i].innerHTML.indexOf(typet[q]+"=")!=-1){ n=parseInt(quote[i].innerHTML.substring(quote[i].innerHTML.indexOf(typet[q]+"=")+(typet[q].length+1), quote[i].innerHTML.indexOf(";"))) if(isNaN(n)==false){ if(q==0){condition = parseInt(typer[0]) < n;} else if(q==1){condition = parseInt(typer[1]) != n;} else if(q==2){condition = parseInt(typer[2]) < n;} else if(q==3){condition = parseInt(typer[3]) != n;} else if(q==4){condition = parseInt(typer[4]) < n;} if(condition){ if(q==0){ quote[i].innerHTML="To view the hidden text you need to have "+n+" points of reputation. It remains to get "+(n-parseInt(typer[q])) }else if(q==1){ quote[i].innerHTML="Your group is not allowed to view this message." }else if(q==2){ quote[i].innerHTML="To view the hidden text you need to have "+n+" points of positive. It remains to get "+(n-parseInt(typer[q])) }else if(q==3){ quote[i].innerHTML="This text is left for <a href='profile.php?id="+n+"'>this</a> user." }else if(q==4){ quote[i].innerHTML="You need to be "+n+" years old." } } else { quote[i].innerHTML=quote[i].innerHTML.substring(quote[i].innerHTML.indexOf(typet[q]+"="+n+";")+((typet[q].length+2)+n.toString().length)) } } } } } } </script>
The script does not work with several requirements at the same time, so it's pointless to cross hides.