Widget:TalkToc:修订间差异

H萌娘,万物皆可H的百科全书!
跳到导航 跳到搜索
imported>=海豚=
([InPageEdit] 没有编辑摘要 (编辑自Special:Diff/43088))
imported>=海豚=
([InPageEdit] 没有编辑摘要 (编辑自Special:Diff/43088))
第125行: 第125行:
            });
            });
          });
          });
         //添加整体toggle按钮
         appendToggleButton($toc.find('ol'), $title.find('#toctoggle'), '显示', '隐藏');
         $('#toc').addClass('noOrigin');
         /*
         $('.saveNotice').each(function() {
           $(this).prev('h2').addClass('savedNotice');
         });*/
         var containers = $('.discussionContainer');
         containers.first().before('<' + 'div id="talkTocBox"><' + 'table><' + '/table><' + '/div>');
         var self = $('#talkTocBox table'),
           a = $('<' + 'a/>').text('');
         self.append('<' + 'caption/>').find('caption').append(mw.config.get('wgTitle') + '现有讨论串').append('').append(a).append('' + '<br>').append('(这里的讨论串不会被存档,无用及已解决的即时讨论会被定期删除)')
           .end().append('<' + 'tbody/>');
         containers.not('.savedDiscussion').each(function(i) {
           if (i % 4 === 0) self.find('tbody:last').append('<' + 'tr/>');
           var that = $(this);
           /* var content = that.children().not('h2');
           content.find('a').each(function() {
             try {
               var href = $(this)[0].href;
               if (!href) return;
               var link = new mw.Uri(href);
               if (link.host !== 'www.moegirl.com') this.userNameErrorReason = "link.host !== 'www.moegirl.com'";
               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(containers).clone();
             var now = Date.now() + (Math.random() + '').substring(2);
             parent.find('.userTalkPage').text(now);
             var regExec = RegExp(now + '(.*)(\\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 || regExec[1].length > 20) {
               this.userNameErrorReason = 'Too far away from timestamp (' + (regExec ? regExec[1].length : 'null') + ')';
               this.userNameErrorRegExec = regExec;
               $(this).removeClass('userTalkPage');
             } else $(this).data('userTalkTime', regExec[2]);
           });
           var userTalkPage = [];
           content.find('.userTalkPage').each(function() {
             var timestamp = $(this).data('userTalkTime').replace(/ \([A-Z]{3,4}\)$|\([日一二三四五六]\)/g, ''),
               date = new Date(),
               time = timestamp.split(/[年月日\s\(\)\:]+/).map(function(n) {
                 return +n;
               });
             if (!time || !time[4]) return $(this).removeClass('.userTalkPage')[0].userNameErrorReason = 'Error Timestamp(' + timestamp + ')';
             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];
           titlereg[that.find('.mw-headline:first').attr('id')] = that;*/
           self.find('tr:last').append('<' + 'td><' + '/td>')
             .find('td:last').append(
               $('<' + 'a/>').attr('href', '#' + that.find('.mw-headline:first').attr('id').replace(/"/g, "&quot;")).append(that.find('.mw-headline:first').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(); */
         self.append('<' + 'tbody class="hr"><' + 'tr><' + 'td colspan="4"> <' + '/td><' + '/tr><' + '/tbody>').append('<' + 'tbody/>').find('tbody').not(':first').hide();
         containers.filter('.savedDiscussion').each(function(i) {
           if (i % 4 === 0) self.find('tbody:last').append('<' + 'tr/>');
           self.find('tr:last').append('<' + 'td><' + 'a class="savedTitle" href="#' + $(this).find('.mw-headline:first').attr('id').replace(/"/g, "&quot;") + '">' + $(this).clone().find('.mw-headline:first').children('.mw-headline-number').remove().end().prepend(containers.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');
           that.append(("<" + "td>&#32;<" + "/td>").repeat(4 - that.find("td").length));
         });
         $('#talkTocBox caption').append('').append($('<' + 'a/>').addClass('cbutton')).append('');
         $('#tocText').append('<' + 'br>').append($('<' + 'a/>').addClass('cbutton')).append('');
         $('.cbutton').on('click', function() {
           if (!localStorage.wgTocStyle || localStorage.wgTocStyle !== 'list') {
             $('#talkTocBox').hide();
             $('#tocBox').show();
             localStorage.setItem('wgTocStyle', 'list');
             $('.cbutton').text('');
             $(toclist.filter(function(l) {
               return l !== "tocBox";
             }).map(function(l) {
               return 'a[href="#' + l + '"';
             }).join(', ')).attr("href", "#tocBox");
           } else {
             $('#talkTocBox').show();
             $('#tocBox').hide();
             localStorage.setItem('wgTocStyle', 'table');
             $('.cbutton').text('');
             $(toclist.filter(function(l) {
               return l !== "talkTocBox";
             }).map(function(l) {
               return 'a[href="#' + l + '"';
             }).join(', ')).attr("href", "#talkTocBox");
           }
         });
         if (!localStorage.wgTocStyle || localStorage.wgTocStyle !== 'list') {
           $('#talkTocBox').show();
           $('.cbutton').text('');
           $(toclist.filter(function(l) {
             return l !== "talkTocBox";
           }).map(function(l) {
             return 'a[href="#' + l + '"';
           }).join(', ')).attr("href", "#talkTocBox");
         } else {
           $('#tocBox').show();
             });
           });
         }
        }
        }
      }
      }

2020年5月1日 (五) 20:35的版本