User:He7d3r/Tools/TalkPageTools.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// [[File:User:He7d3r/Tools/TalkPageTools.js]] (workaround for [[phab:T35355]])
// <nowiki>
/*
 * Altera a formatação dos tópicos das páginas de discussão, ocultando aqueles que não recebem novos comentários há alguns dias
 * @author: Helder (https://github.com/he7d3r)
 * @license: CC BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0/>
 */
(function(e,t){"use strict";e.config.get("wgDBname")==="ptwiki"&&(window.tpt={extraTalkPages:["Wikipédia:Café_dos_administradores","Wikipédia:Esplanada/propostas","Wikipédia:Esplanada/geral","Wikipédia:Fusão/Central_de_fusões","Wikipédia:Fontes_fiáveis/Central_de_fiabilidade"]});var a={collapseTopics:!0,level:2,maxDays:7,extraTalkPages:[],monthNames:{en:["january","february","march","april","may","june","july","august","september","october","november","december"],pt:["janeiro","fevereiro","março","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro"]},reTimeStamp:{en:/(\d{1,2}):(\d{1,2}), (\d{1,2}) (January|February|March|April|May|June|July|August|September|October|November|December) (\d{4}) \(UTC\)/gi,pt:/(\d{1,2})h(\d{1,2})min de (\d{1,2}) de (janeiro|fevereiro|março|abril|maio|junho|julho|agosto|setembro|outubro|novembro|dezembro) de (\d{4}) \(UTC\)/gi},dateOrder:{},i18n:{en:{"tpt-old-topic-text":"This topic was last edited $1 days ago. Click on the section header to toggle the comments.","tpt-unsigned-topic-text":"All comments on this topic are unsigned.","tpt-change-max-days":"Duration of topics","tpt-change-max-days-title":"Change the number of days during which the topics stay open by default","tpt-change-max-days-question":"Do you want to automatically hide the topics last commented more than how many days ago?"},pt:{"tpt-old-topic-text":"Este tópico foi editado pela última vez há $1 dias. Clique no título da seção para exibir ou ocultar os comentários.","tpt-unsigned-topic-text":"Todos os comentários deste tópico estão sem assinatura.","tpt-change-max-days":"Tempo de duração dos tópicos","tpt-change-max-days-title":"Alterar o número de dias durante os quais os tópicos ficam exibidos por padrão","tpt-change-max-days-question":"Deseja ocultar automaticamente os tópicos cuja última edição ocorreu há mais de quantos dias?"}}};a.timeDistanceInDays=function(e,t){var a=Math.floor((e.getTime()-t.getTime())/864e5);return a},a.getDates=function(o){var i,s,n=e.config.get("wgContentLanguage"),r=a.monthNames[n]||a.monthNames.en,d=a.reTimeStamp[n]||a.reTimeStamp.en,l={hours:1,minutes:2,day:3,month:4,year:5},c=a.dateOrder[n]||l,m=[];i=d.exec(o);while(i)s=new Date,s.setUTCFullYear(i[c.year],t.inArray(i[c.month].toLowerCase(),r),i[c.day]),s.setUTCHours(i[c.hours],i[c.minutes],0,0),m.push(s),i=d.exec(o);return m},a.formatTalkPage=function(){var o,i,s=a.level,n=new Date,r=!1,d=t(),l=t(),c=function(e,t,a){var o={"float":"none",cursor:"pointer","text-align":"left","-moz-user-select":"all","-webkit-user-select":"all","-ms-user-select":"all","user-select":"all"};a?e.addClass("mw-collapsible-toggle").css(o).add(t.wrapAll('<div class="mw-collapsible-content"></div>').parent()).wrapAll('<div class="topic mw-collapsible"></div>'):e.add(t).wrapAll('<div class="topic"></div>')};e.util.addCSS(["div.ongoing-discussion {background-color:#FFF;} ",".topic {background-color:#EEE;}"].join("\n")),t("#mw-content-text").contents().each(function(){var e=t(this),o=e.parent();!e.is("h"+s)||o.is("#toctitle")||o.hasClass("lqt-contents-wrapper")||e.attr("id")==="mw-previewheader"||e.hasClass("lqt_header")||e.hasClass("diff-currentversion-title")?d=d.add(e):(r&&c(l,d,a.collapseTopics),l=e,d=t(),r=!0)}),r&&c(l,d,a.collapseTopics),t(".topic").each(function(){var i,s,r=t(this);return o=a.getDates(r.text()),o.length===0?(r.find("h2").after(t('<i class="error" style="margin-bottom: 2em; display: block;"></i>').text(e.msg("tpt-unsigned-topic-text"))),!0):(o.sort(function(e,t){return t-e}),i=a.timeDistanceInDays(n,o[0]),s=e.cookie.get("tpt-maxDays")||a.maxDays,s>i?r.addClass("ongoing-discussion"):a.collapseTopics&&(r.find("h2").after(t('<i style="margin-bottom: 2em; display: block;"></i>').text(e.msg("tpt-old-topic-text",i))),r.addClass("mw-collapsed")),void 0)}),t(".mw-collapsible").makeCollapsible(),t("#mw-content-text").show(),i=t('[id="'+window.location.hash.substr(1)+'"]'),i.length&&t("html, body").animate({scrollTop:i.offset().top},0)},a.run=function(){if(t("#ca-addsection").length>0||t.inArray(e.config.get("wgPageName"),a.extraTalkPages)!==-1){var o=a.i18n.en;a.i18n["pt-br"]=a.i18n.pt,t.extend(!0,o,a.i18n[e.config.get("wgUserLanguage")]),e.messages.set(o),t(a.addLink),e.loader.using(["mediawiki.util","jquery.makeCollapsible","mediawiki.cookie"],a.formatTalkPage)}},a.addLink=function(){t(e.util.addPortletLink("p-cactions","#",e.msg("tpt-change-max-days"),"#ca-tpt-max-days",e.msg("tpt-change-max-days-title"))).click(function(t){t.preventDefault(),e.loader.using("mediawiki.cookie",function(){var t=prompt(e.msg("tpt-change-max-days-question"),"7");t!==null&&(e.cookie.set("tpt-maxDays",t,{expires:86400,path:"/"}),document.location.reload(!1))})})},window.tpt===void 0?window.tpt=a:typeof window.tpt=="object"&&(window.tpt=t.extend({},a,window.tpt)),t.inArray(e.config.get("wgAction"),["view","purge"])!==-1&&t(a.run)})(mediaWiki,jQuery);
// </nowiki>