Widget:TalkToc:修订间差异
跳到导航
跳到搜索
imported>=海豚= 无编辑摘要 |
标签:回退 |
||
(未显示4个用户的73个中间版本) | |||
第1行: | 第1行: | ||
<noinclude>Only for | <noinclude>Only for Talk</noinclude><includeonly><!--{if !isset($wgTalkToc) || !$wgTalkToc}--><!--{assign var="wgTalkToc" value=true scope="global"}--><script> | ||
window. | window.addEventListener('jquery-ready', function() { | ||
if (location.hostname.includes("m.hmoegirl.info")) return; | |||
if (location.hostname.includes("m.hmoegirl. | |||
mw.loader.using(["oojs-ui"]).then(function() { | mw.loader.using(["oojs-ui"]).then(function() { | ||
if (!mw.config.get('talkTocLoaded', false)) { | if (!mw.config.get('talkTocLoaded', false)) { | ||
第25行: | 第24行: | ||
$tocBox, $level2, $li, $svdDcs, $title, $toggle, $tocText, | $tocBox, $level2, $li, $svdDcs, $title, $toggle, $tocText, | ||
appendToggleButton; | appendToggleButton; | ||
/* 预处理 */ | |||
//备份目录 | |||
$toc.after($toc.clone().hide().attr('id', 'tocClone')); | |||
//整理讨论串 | |||
$('#mw-content-text > .mw-parser-output > h2').each(function() { | |||
var head = $(this); | |||
var container = $('<' + 'div/>'); | |||
container.addClass('discussionContainer'); | |||
head.addClass('discussionHead'); | |||
head.before(container); | |||
head.nextUntil('h2').not('h2').appendTo(container); | |||
head.prependTo(container); | |||
if (container.find('.saveNotice')[0] && head.nextUntil(".saveNotice").length === 0) { | |||
$toc.find('a[href="#' + head.find('.mw-headline')[0].id.replace(/"/g, '\\\"') + '"]').parent().addClass("savedDiscussion hiddenDiscussion"); | |||
container.addClass('savedDiscussion'); | |||
} else if (window.CSS && CSS.supports && CSS.supports('position', 'sticky')) { | |||
head.css({ | |||
position: 'sticky', | |||
top: 0, | |||
'background-color': bgcolor, | |||
'z-index': 2 | |||
}); | |||
container.css('position', 'relative'); | |||
} | |||
}); | |||
// Temporary padding fix for Microsoft Edge | |||
// TODO: Report this issue to Edge team | |||
if (/Edge/.test(navigator.userAgent)) { | |||
$('.discussionContainer').css('padding-top', '10px'); | |||
} | |||
//整理标题列表 | |||
$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.hide(); | |||
$(this).text(shTx); | |||
} else { | |||
$Obj.show(); | |||
$(this).text(hiTx); | |||
} | |||
} | |||
} | |||
})); | |||
if (typeof fun == 'function') fun(); | |||
}; | |||
/* 业务处理*/ | /* 业务处理*/ | ||
//添加存档讨论串标题toggle按钮 | |||
if ($svdDcs[0]) { | |||
$toggle.append($('<' + 'a/>', { | |||
text: '显示已被存档标题', | |||
'class': 'toggleButton', | |||
href: 'javascript:void(0);', | |||
on: { | |||
click: function() { | |||
if ($svdDcs.hasClass('hiddenDiscussion')) { | |||
$svdDcs.removeClass('hiddenDiscussion'); | |||
$(this).text('隐藏已被存档标题'); | |||
} else { | |||
$svdDcs.addClass('hiddenDiscussion'); | |||
$(this).text('显示已被存档标题'); | |||
} | |||
} | |||
} | |||
})); | |||
$tocText.append("<" + "div class='tocText'>(有下划线标题是已被存档标题)<" + "/div>"); | |||
} | |||
//添加二三四五级标题toggle按钮和标题数量 | //添加二三四五级标题toggle按钮和标题数量 | ||
appendToggleButton($level2, $toggle, '显示段落', '隐藏段落', function() { | appendToggleButton($level2, $toggle, '显示段落', '隐藏段落', function() { | ||
第46行: | 第134行: | ||
containers.first().before('<' + 'div id="talkTocBox"><' + 'table><' + '/table><' + '/div>'); | containers.first().before('<' + 'div id="talkTocBox"><' + 'table><' + '/table><' + '/div>'); | ||
var self = $('#talkTocBox table'), | var self = $('#talkTocBox table'), | ||
a = $('<' + 'a/>').text(' | a = $('<' + 'a/>').text(''); | ||
self.append('<' + 'caption/>').find('caption').append | self.append('<' + 'caption/>').find('caption').append('<br/>').append('').append(a).append('') | ||
.end().append('<' + 'tbody/>'); | .end().append('<' + 'tbody/>'); | ||
containers.not('.savedDiscussion').each(function(i) { | containers.not('.savedDiscussion').each(function(i) { | ||
第58行: | 第146行: | ||
if (!href) return; | if (!href) return; | ||
var link = new mw.Uri(href); | var link = new mw.Uri(href); | ||
if (link.host !== 'www. | 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 (/^\/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 if (!link.query.title && /\.php$/i.test(link.path)) this.userNameErrorReason = "!!(!link.query.title && /\\.php$/i.test(link.path))"; | ||
第121行: | 第209行: | ||
if (i % 4 === 0) self.find('tbody:last').append('<' + 'tr/>'); | 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, """) + '">' + $(this).clone().find('.mw-headline:first').children('.mw-headline-number').remove().end().prepend(containers.index(this) + 1 + ' ').text() + '<' + '/a><' + '/td>'); | self.find('tr:last').append('<' + 'td><' + 'a class="savedTitle" href="#' + $(this).find('.mw-headline:first').attr('id').replace(/"/g, """) + '">' + $(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() { | self.find('tbody').not('.hr').each(function() { | ||
第126行: | 第218行: | ||
that.append(("<" + "td> <" + "/td>").repeat(4 - that.find("td").length)); | that.append(("<" + "td> <" + "/td>").repeat(4 - that.find("td").length)); | ||
}); | }); | ||
$('#talkTocBox caption').append(' | $('#talkTocBox caption').append('').append($('<' + 'a/>').addClass('cbutton')).append(''); | ||
$('#tocText').append('<' + 'br> | $('#tocText').append('<' + 'br>').append($('<' + 'a/>').addClass('cbutton')).append(''); | ||
$('.cbutton').on('click', function() { | $('.cbutton').on('click', function() { | ||
if (!localStorage.wgTocStyle || localStorage.wgTocStyle !== 'list') { | if (!localStorage.wgTocStyle || localStorage.wgTocStyle !== 'list') { | ||
第133行: | 第225行: | ||
$('#tocBox').show(); | $('#tocBox').show(); | ||
localStorage.setItem('wgTocStyle', 'list'); | localStorage.setItem('wgTocStyle', 'list'); | ||
$('.cbutton').text(' | $('.cbutton').text(''); | ||
$(toclist.filter(function(l) { | $(toclist.filter(function(l) { | ||
return l !== "tocBox"; | return l !== "tocBox"; | ||
}).map(function(l) { | }).map(function(l) { | ||
return 'a[href="#' + l + '" | return 'a[href="#' + l + '"'; | ||
}).join(', ')).attr("href", "#tocBox"); | }).join(', ')).attr("href", "#tocBox"); | ||
} else { | } else { | ||
第143行: | 第235行: | ||
$('#tocBox').hide(); | $('#tocBox').hide(); | ||
localStorage.setItem('wgTocStyle', 'table'); | localStorage.setItem('wgTocStyle', 'table'); | ||
$('.cbutton').text(' | $('.cbutton').text(''); | ||
$(toclist.filter(function(l) { | $(toclist.filter(function(l) { | ||
return l !== "talkTocBox"; | return l !== "talkTocBox"; | ||
}).map(function(l) { | }).map(function(l) { | ||
return 'a[href="#' + l + '" | return 'a[href="#' + l + '"'; | ||
}).join(', ')).attr("href", "#talkTocBox"); | }).join(', ')).attr("href", "#talkTocBox"); | ||
} | } | ||
第153行: | 第245行: | ||
if (!localStorage.wgTocStyle || localStorage.wgTocStyle !== 'list') { | if (!localStorage.wgTocStyle || localStorage.wgTocStyle !== 'list') { | ||
$('#talkTocBox').show(); | $('#talkTocBox').show(); | ||
$('.cbutton').text(' | $('.cbutton').text(''); | ||
$(toclist.filter(function(l) { | $(toclist.filter(function(l) { | ||
return l !== "talkTocBox"; | return l !== "talkTocBox"; | ||
}).map(function(l) { | }).map(function(l) { | ||
return 'a[href="#' + l + '" | return 'a[href="#' + l + '"'; | ||
}).join(', ')).attr("href", "#talkTocBox"); | }).join(', ')).attr("href", "#talkTocBox"); | ||
} else { | } else { | ||
$('#tocBox').show(); | $('#tocBox').show(); | ||
$('.cbutton').text(' | $('.cbutton').text(''); | ||
$(toclist.filter(function(l) { | $(toclist.filter(function(l) { | ||
return l !== "tocBox"; | return l !== "tocBox"; | ||
}).map(function(l) { | }).map(function(l) { | ||
return 'a[href="#' + l + '" | return 'a[href="#' + l + '"'; | ||
}).join(', ')).attr("href", "#tocBox"); | }).join(', ')).attr("href", "#tocBox"); | ||
} | } | ||
$tocBox.css({ | $tocBox.css({ | ||
position: 'relative', | position: 'relative', | ||
第206行: | 第292行: | ||
}).trigger('hashchange'); | }).trigger('hashchange'); | ||
const g = ["sysop", "patroller"]; | const g = ["sysop", "patroller"]; | ||
} | } | ||
} | } | ||
第234行: | 第298行: | ||
</script><style> | </script><style> | ||
/* <pre> */ | /* <pre> */ | ||
@media screen and (min-width: 600px) { | |||
body { | |||
opacity: 0.95; | |||
background-image:url(https://www.hmoegirl.info/images/a/af/%E8%AE%A8%E8%AE%BA%E7%89%88%E8%AF%8D%E4%BA%91.jpg); | |||
background-repeat:no-repeat; | |||
} | |||
} | |||
#ca-nstab-project { | |||
display: none; | |||
} | |||
.widgetTalkTocEnable #tocBox { | .widgetTalkTocEnable #tocBox { | ||
max-width: 37%; | max-width: 37%; | ||
第242行: | 第316行: | ||
display: table; | display: table; | ||
} | } | ||
.widgetTalkTocEnable div.toc#toc { | .widgetTalkTocEnable div.toc#toc:not(.toc-custom) { | ||
min-width: 300px; | min-width: 300px; | ||
box-sizing: border-box; | box-sizing: border-box; | ||
第292行: | 第366行: | ||
display: inline-block; | display: inline-block; | ||
} | } | ||
#toc:not(.toc-custom), | |||
#tocBox, | #tocBox, | ||
#talkTocBox { | #talkTocBox { | ||
display: none; | display: none; | ||
} | } | ||
.widgetTalkTocDisable #toc { | .widgetTalkTocDisable #toc:not(.toc-custom) { | ||
display: table; | display: table; | ||
} | } | ||
第338行: | 第396行: | ||
.widgetTalkTocEnable .cbutton { | .widgetTalkTocEnable .cbutton { | ||
cursor: pointer; | cursor: pointer; | ||
} | |||
#ca-edit, #ca-editTopSection .mw-editsection { | |||
display: none !important; | |||
} | } | ||
.signInfo { | .signInfo { | ||
第362行: | 第423行: | ||
#right-navigation.no-need-to-edit-whole-page ul>li#Wikiplus-Edit-TopBtn, | #right-navigation.no-need-to-edit-whole-page ul>li#Wikiplus-Edit-TopBtn, | ||
#right-navigation.no-need-to-edit-whole-page ul>li#ca-edit, | #right-navigation.no-need-to-edit-whole-page ul>li#ca-edit, | ||
#right-navigation.no-need-to-edit-whole-page ul>li#ca-editTopSection { | #right-navigation.no-need-to-edit-whole-page ul>li#ca-editTopSection{ | ||
display: none; | display: none; | ||
} | } | ||
.cloaked-element.transparent-shield { | .cloaked-element.transparent-shield { | ||
z-index: 9999999; | z-index: 9999999; | ||
} | |||
.navpopup { | |||
z-index: 1000000; | |||
} | } | ||
/* </pre> */ | /* </pre> */ | ||
</style><!--{/if}--></includeonly> | </style><!--{/if}--></includeonly> |
2023年8月18日 (五) 10:14的最新版本
Only for Talk