MediaWiki:Gadget-find-archived-section.js: Difference between revisions

Content deleted Content added
.
escape $ in the section names, that would break JS replace(), tweak comments a bit
Line 12:
 
var sectionName = decodeURIComponent(
window.___location.hash.slice(1) // .slice(1) to remove the leading #
.replace(/_/g, ' ')
);
 
// Try to undo theFor anchor encoding-encoded (UTF-8 percent encoding but with % replaced by a period (.) ), try to undo the encoding.
// For some strange reason, theMediaWiki doesn't encode . itself, isn'tbecause encoded,of this means the encoding process isn't
// exactly reversible. But this should work for the vast majority of cases.
var sectionNameDotDecoded = decodeURIComponent(sectionName.replace(/\.([0-9A-F]{2})/g, '%$1'));
 
Line 57:
$('#mw-content-text').before(
$('<div>')
.text(msg['starter-text'].replace('$1', sectionName.replace(/\$/g, '$$$$')) + msg['finding'])
.addClass('archived-section-prompt')
.css({
Line 97:
var results = json.query.search;
if (results.length === 0) {
divHtml = msg['no-search-results'].replace('$1', mw.html.escape(sectionName).replace(/\$/g, '$$$$'));
 
} else {
Line 127:
});
 
divHtml = msg['starter-text'].replace('$1', mw.html.escape(sectionNameFound || sectionName).replace(/\$/g, '$$$$'));
 
if (pageTitle) { // if a section with the same name was found
Line 141:
$('.archived-section-prompt').html(divHtml);
 
}).failcatch(function(err) {
console.error('[find-archived-section]: ', JSON.stringify(err));
});