MediaWiki:UpdateLinks.js
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.
$(document).ready(function() {
//Update links pointing to vanisource with terms found in spans with class="terms"
//get terms from <span class="terms" and sanitize them
terms = "";
if ($('span.terms').length) {
$('span.terms').each(function () {
text = $(this).text().replace(/"/g, "");
text = text.replace(/(\w+) {2,}(\w+)/g, "$1 $2");
text = text.replace(/^\ {0,}/m, "");
text = text.replace(/\ {0,}$/m, "");
terms += text+'+';
});
} else { terms = wgTitle; }
//serach in the body for any anchor <a with a attribute href pointing to Vanisource
//and append the terms to be passed to Vanisource for highlighting
//Define function to append terms
append_terms = function() {
class_this = $(this).attr('class');
//alert(class_this);
//Check if class has been already defined with this same routine (if we have been here), the terms have already been appended
if(class_this != 'selected'){
search_str1 = this.href+'?terms='+terms;
$(this).attr({href: search_str1, class: 'selected'});
}
}
//Now bind it onclick
$('#bodyContent a[@href*="vanisource.org"]').not( $('#bodyContent a[@href*="edit"]') ).click(append_terms);
});