imported>=海豚= |
|
第1行: |
第1行: |
| <noinclude>Only for [[Talk:讨论版]] & [[Talk:提问求助区]]</noinclude><includeonly><!--{if !isset($wgTalkToc) || !$wgTalkToc}--><!--{assign var="wgTalkToc" value=true scope="global"}--><script>
| | == 文件说明 == |
| window.RLQ = window.RLQ || [];
| | 是 《巨乳ファンタジー》 中的 シャムシェル。 |
| window.RLQ.push(function() {
| |
| mw.hook('wikipage.content').add(function() {
| |
| if (!mw.config.get('talkTocLoaded')) {
| |
| mw.config.set('talkTocLoaded', window.setInterval(function() {
| |
| if (mw.config.get('talkTocStop')) return;
| |
| if (!$('#talkTocBox')[0]) {
| |
| console.debug('widgetTalkToc', 'initing');
| |
| var $toc = $('#toc'),
| |
| $tocBox, $level2, $li, $svdDcs, $title, $toggle, $tocText,
| |
| appendToggleButton;
| |
| $('#talkTocBox').fadeIn();
| |
| $('#tocBox').fadeOut();
| |
| localStorage.setItem('wgTocStyle', 'table');
| |
| /* 预处理 */
| |
| //备份目录
| |
| $toc.after($toc.clone().hide().attr('id', 'tocClone'));
| |
| //标记存档讨论串
| |
| $('.saveNotice').each(function() {
| |
| var prevHeadline = $(this).prev('h2');
| |
| if (prevHeadline[0]) $toc.find('a[href="#' + prevHeadline.find('.mw-headline')[0].id + '"]').parent().addClass("savedDiscussion hiddenDiscussion");
| |
| });
| |
| //整理标题列表
| |
| $toc.append("<ol style='margin-left: 1.7em;'></ol>").after('<div id="tocBox"></div>');
| |
| $toc.children('ul').children().appendTo($toc.find('ol'));
| |
| $toc.find(".toclevel-1 > a > .tocnumber").remove();
| |
| $toc.appendTo("#tocBox");
| |
| | |
| /* 定义变量 */
| |
| $tocBox = $('#tocBox');
| |
| $level2 = $toc.find('.toclevel-2').hide();
| |
| $li = $toc.find('ol > li');
| |
| $svdDcs = $toc.find('.savedDiscussion');
| |
| $title = $toc.find('#toctitle').css("margin-right", "1em").append('<span id="toctoggle"></span>');
| |
| $toggle = $title.append('<div id="toggle"></div>').find('#toggle');
| |
| $tocText = $title.after('<div id="tocText"></div>').parents('#toc').find('#tocText');
| |
| appendToggleButton = function($Obj, $set, shTx, hiTx, fun) {
| |
| if (!$Obj[0]) return false;
| |
| $set.append($('<a/>', {
| |
| text: function() {
| |
| if ($Obj.is(':visible')) return hiTx;
| |
| else return shTx;
| |
| },
| |
| 'class': 'toggleButton',
| |
| href: 'javascript:void(0);',
| |
| bind: {
| |
| click: function() {
| |
| if ($Obj.is(':visible')) {
| |
| $Obj.fadeOut();
| |
| $(this).text(shTx);
| |
| } else {
| |
| $Obj.fadeIn();
| |
| $(this).text(hiTx);
| |
| }
| |
| }
| |
| }
| |
| }));
| |
| if (typeof fun == 'function') fun();
| |
| };
| |
| | |
| /* 业务处理*/
| |
| //添加存档讨论串标题toggle按钮
| |
| if ($svdDcs[0]) {
| |
| $toggle.append($('<a/>', {
| |
| text: '显示已被存档标题',
| |
| 'class': 'toggleButton',
| |
| href: 'javascript:void(0);',
| |
| bind: {
| |
| click: function() {
| |
| if ($svdDcs.hasClass('hiddenDiscussion')) {
| |
| $svdDcs.removeClass('hiddenDiscussion');
| |
| $(this).text('隐藏已被存档标题');
| |
| } else {
| |
| $svdDcs.addClass('hiddenDiscussion');
| |
| $(this).text('显示已被存档标题');
| |
| }
| |
| }
| |
| }
| |
| }));
| |
| $tocText.append("<div class='tocText'>(有下划线标题 是 已被存档标题)</div>");
| |
| }
| |
| //添加二三四五级标题toggle按钮和标题数量
| |
| appendToggleButton($level2, $toggle, '显示段落', '隐藏段落', function() {
| |
| $tocText.append("<div class='tocText'>( 中 括号内数字是该大段下小段数量)</div>");
| |
| $toc.find('.toclevel-1').each(function() {
| |
| var subtitleLength = $(this).find('.toctext').length - 1;
| |
| if (subtitleLength) $(this).children('a').after('[' + subtitleLength + ']');
| |
| });
| |
| });
| |
| //添加整体toggle按钮
| |
| appendToggleButton($toc.find('ol'), $title.find('#toctoggle'), '显示', '隐藏');
| |
| $('#toc').addClass('noOrigin');
| |
| $('.saveNotice').each(function() {
| |
| $(this).prev('h2').addClass('savedNotice');
| |
| });
| |
| $('#mw-content-text > h2:first').before('<div id="talkTocBox"><table></table></div>');
| |
| var self = $('#talkTocBox table'),
| |
| heads = $('#mw-content-text > h2'),
| |
| a = $('<a/>').text('显示已存档讨论串标题');
| |
| self.append('<caption/>').find('caption').append(mw.config.get('wgTitle') + '现有讨论串').append(' [').append(a).append(']<br>').append('(有下划线标题是已被存档讨论串标题)')
| |
| .end().append('<tbody/>');
| |
| heads.not('.savedNotice').each(function(i) {
| |
| if (i % 4 === 0) self.find('tbody:last').append('<tr/>');
| |
| var content = $(this).nextUntil('h2');
| |
| content.find('a').each(function() {
| |
| try {
| |
| var href = $(this)[0].href;
| |
| if (!href) return;
| |
| var link = new mw.Uri(href);
| |
| if (link.host !== 'zh.moegirl.org') this.userNameErrorReason = "link.host !== 'zh.moegirl.org'";
| |
| else if (/^\/api\.php/i.test(link.path)) this.userNameErrorReason = "!!/^\\/api\\.php/i.test(link.path)";
| |
| else if (!link.query.title && /\.php$/i.test(link.path)) this.userNameErrorReason = "!!(!link.query.title && /\\.php$/i.test(link.path))";
| |
| else {
| |
| var t = link.query.title || decodeURIComponent(link.path.substring(1));
| |
| if (/^user([ _]talk)?:[^\/]+$/i.test(t)) $(this).data('userName', t.replace(/^user([ _]talk)?:/i, '')).addClass('userTalkPage');
| |
| else this.userNameErrorReason = "!!/^user([ _]talk)?:[^\\/]+$/i.test(t)";
| |
| }
| |
| } catch (e) {
| |
| return;
| |
| }
| |
| });
| |
| content.find('.userTalkPage').each(function() {
| |
| var parent = $(this).closest('dd, p').clone();
| |
| var now = Date.now() + (Math.random() + '').substring(2);
| |
| parent.find('.userTalkPage').text(now);
| |
| var regExec = RegExp(now + '.{0,20}(\\d{4}年([1-9]|1[0-2])月([1-9]|[12]\\d|3[01])日\\s{0,10}\\([一二三四五六日]\\)\\s{0,10}([01]\\d|2[0-3]):[0-5]\\d\\s{0,10}(\\([A-Z]{3}\\))?)').exec(parent.text());
| |
| if (!regExec) {
| |
| this.userNameErrorReason = 'Too far away from timestamp';
| |
| $(this).removeClass('userTalkPage');
| |
| } else $(this).data('userTalkTime', regExec[1]);
| |
| });
| |
| var userTalkPage = [];
| |
| content.find('.userTalkPage').each(function() {
| |
| var timestamp = $(this).data('userTalkTime').replace(/ \([A-Z]{3,4}\)$/, ''),
| |
| date = new Date(),
| |
| time = timestamp.replace(/\([日一二三四五六]\)/g, '').split(/[年月日\s\(\)\:]+/).map(function(n) {
| |
| return +n;
| |
| });
| |
| if (!time || !time[4]) return $(this).removeClass('.userTalkPage');
| |
| date.setFullYear(time[0]);
| |
| date.setMonth(time[1] - 1);
| |
| date.setDate(time[2]);
| |
| date.setHours(time[3]);
| |
| date.setMinutes(time[4]);
| |
| userTalkPage.push([$(this).data('userName'), timestamp, date.getTime()]);
| |
| });
| |
| if (!userTalkPage[0]) userTalkPage.push(['Unsigned user/Nonstandard sign', 'Unknown Time']);
| |
| else userTalkPage.sort(function(a, b) {
| |
| return a[2] - b[2]
| |
| });
| |
| var firstName = userTalkPage[0],
| |
| lastName = userTalkPage[userTalkPage.length - 1];
| |
| self.find('tr:last').append('<td></td>')
| |
| .find('td:last').append($('<a/>').attr('href', '#' + $(this).children('.mw-headline').attr('id')).append($(this).children('.mw-headline').clone().find('a').replaceWith(function() {
| |
| return $(this).text();
| |
| }).end().html()))
| |
| .append(
| |
| $('<div/>').addClass('signInfo').append('话题发起:' + (firstName[0] === 'Unsigned user/Nonstandard sign' ? 'Unsigned user/Nonstandard sign' : '<a href="/User_talk:' + firstName[0] + '" title="' + firstName[0] + '的讨论页" target="_blank">' + firstName[0].replace(/_/g, ' ') + '</a>'))
| |
| .append('<br>最后回复:' + (lastName[0] === 'Unsigned user/Nonstandard sign' ? 'Unsigned user/Nonstandard sign' : '<a href="/User_talk:' + lastName[0] + '" title="' + lastName[0] + ' 的 讨论页" target="_blank">' + lastName[0].replace(/_/g, ' ') + '</a>') + '(' + lastName[1] + ')')
| |
| );
| |
| });
| |
| if ($('.signInfo').filter(function() {
| |
| return $(this).text().indexOf('Unsigned user/Nonstandard sign') !== -1;
| |
| }).length * 2 > $('.signInfo').length) $('.signInfo').hide().attr('data-hidden', 'true');
| |
| self.append('<tbody class="hr"><tr><td colspan="4"> </td></tr></tbody>').append('<tbody/>').find('tbody').not(':first').hide();
| |
| heads.filter('.savedNotice').each(function(i) {
| |
| if (i % 4 === 0) self.find('tbody:last').append('<tr/>');
| |
| self.find('tr:last').append('<td><a class="savedTitle" href="#' + $(this).children('.mw-headline').attr('id') + '">' + $(this).clone().children('.mw-headline').children('.mw-headline-number').remove().end().prepend(heads.index(this) + 1 + ' ').text() + '</a></td>');
| |
| });
| |
| a.on('click', function() {
| |
| self.find('tbody').not(':first').fadeToggle();
| |
| $(this).text($(this).text() === '显示已存档讨论串标题' ? '隐藏已存档讨论串标题' : '显示已存档讨论串标题');
| |
| });
| |
| self.find('tbody').not('.hr').each(function() {
| |
| var that = $(this).find('tr:last');
| |
| switch (that.find("td").length) {
| |
| case 3:
| |
| that.append("<td> </td>");
| |
| break;
| |
| case 2:
| |
| that.append("<td> </td><td> </td>");
| |
| break;
| |
| case 1:
| |
| that.append("<td> </td><td> </td><td> </td>");
| |
| }
| |
| });
| |
| $('#talkTocBox caption').append('<br>[').append($('<a/>').addClass('cbutton')).append(']');
| |
| $('#tocText').append('<br>[').append($('<a/>').addClass('cbutton')).append(']');
| |
| $('.cbutton').on('click', function() {
| |
| if (!localStorage.wgTocStyle || localStorage.wgTocStyle !== 'list') {
| |
| $('#talkTocBox').fadeOut();
| |
| $('#tocBox').fadeIn();
| |
| localStorage.setItem('wgTocStyle', 'list');
| |
| $('.cbutton').text('点击切换至表格格式');
| |
| } else {
| |
| $('#talkTocBox').fadeIn();
| |
| $('#tocBox').fadeOut();
| |
| localStorage.setItem('wgTocStyle', 'table');
| |
| $('.cbutton').text('点击切换至列表格式');
| |
| }
| |
| });
| |
| } else if ($('.signInfo').attr('data-hidden') === 'true') {
| |
| console.debug('widgetTalkToc', 'sign exec error');
| |
| $('.savedDiscussion, .hiddenDiscussion, .savedNotice, .userTalkPage').removeClass('savedDiscussion hiddenDiscussion savedNotice userTalkPage');
| |
| $('#tocBox, #talkTocBox').remove();
| |
| $('#tocClone').attr('id', 'toc').removeAttr('style');
| |
| } else {
| |
| var boxs = $('#tocBox, #talkTocBox');
| |
| if (boxs.is(':hidden') && boxs.is(':visible')) return;
| |
| if (!localStorage.wgTocStyle || localStorage.wgTocStyle !== 'list') {
| |
| $('#talkTocBox').fadeIn();
| |
| $('.cbutton').text('点击切换至列表格式');
| |
| } else {
| |
| $('#tocBox').fadeIn();
| |
| $('.cbutton').text('点击切换至表格格式');
| |
| }
| |
| }
| |
| }, 730));
| |
| }
| |
| });
| |
| });
| |
| </script><style>
| |
| #tocBox {
| |
| max-width: 37%;
| |
| min-width: 300px;
| |
| float: left;
| |
| }
| |
| #toc.noOrigin {
| |
| display: table;
| |
| }
| |
| div.toc#toc {
| |
| min-width: 300px;
| |
| box-sizing: border-box;
| |
| margin-right: 37px;
| |
| padding-right: 1em;
| |
| padding-left: 1em;
| |
| }
| |
| div.toc#toc div#toctitle h2 {
| |
| margin-right: 1em;
| |
| }
| |
| div.toc.noOrigin#toc .toctoggle {
| |
| display: none;
| |
| }
| |
| div#toc.toc #toctoggle,
| |
| div#toc.toc #toggle {
| |
| font-size: 94%;
| |
| -webkit-user-select: none;
| |
| -ms-user-select: none;
| |
| -o-user-select: none;
| |
| -moz-user-select: none;
| |
| user-select: none;
| |
| }
| |
| div#toc.toc .toggleButton:before {
| |
| content: "[";
| |
| color: black;
| |
| }
| |
| div#toc.toc .toggleButton:after {
| |
| content: "]";
| |
| color: black;
| |
| }
| |
| #toc .toggleButton:first-child {
| |
| margin-right: 0.5em;
| |
| }
| |
| div#toc.toc .toggleButton:last-child {
| |
| margin-right: 0;
| |
| }
| |
| div#toc.toc .hiddenDiscussion {
| |
| visibility: hidden;
| |
| height: 0;
| |
| margin: 0;
| |
| }
| |
| div.toc#toc li.savedDiscussion a {
| |
| text-decoration: underline;
| |
| }
| |
| #toc div#tocText {
| |
| text-align:center;
| |
| }
| |
| #toc div.tocText {
| |
| display:inline-block;
| |
| }
| |
| /* 节操酱的beg */
| |
| #content ol,
| |
| #content ul {
| |
| margin: 0 !important;
| |
| padding: 0.3em 0 0 1.6em !important;
| |
| }
| |
| #toc .toclevel-1 > ul {
| |
| padding-left: 0!important;
| |
| }
| |
| /* 由于节操酱的beg导致分类那边有秘制空白 */
| |
| #content #catlinks ol,
| |
| #content #catlinks ul {
| |
| padding: 0 !important;
| |
| }
| |
| #toc,
| |
| #tocBox,
| |
| #talkTocBox {
| |
| display: none;
| |
| }
| |
| #talkTocBox td {
| |
| text-align: center;
| |
| border: 1px solid #a7d7f9;
| |
| width: 25%;
| |
| padding: 0 1em;
| |
| }
| |
| #talkTocBox .hr td {
| |
| width: 100%;
| |
| }
| |
| #talkTocBox table {
| |
| border-collapse: collapse;
| |
| margin-bottom: 1em;
| |
| width: 100%;
| |
| }
| |
| #talkTocBox a {
| |
| cursor: pointer;
| |
| }
| |
| #talkTocBox .savedTitle {
| |
| text-decoration: underline;
| |
| }
| |
| .cbutton {
| |
| cursor: pointer;
| |
| }
| |
| </style><!--{/if}--></includeonly>
| |