User:Frietjes/docsandboxtestcaseslinks.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Adds [sandbox] and [testcases] to the documentation links
// Clicking on [sandbox] and [testcases] will view those respective pages
//
jQuery(document).ready(function($) {
	mw.loader.using(['mediawiki.util']).done( function() {
var span_element = document.getElementById('doc_editlinks');
if(span_element && span_element.innerHTML.search(/\[<a[^<>]*>view<\/a>\]/g) >= 0) {
  var view_link = span_element.innerHTML.replace(/^.*(\[<a[^<>]*>view<\/a>\]).*$/, '$1');
  var sandbox_link = view_link.replace(/("[^"]*)\/doc(?:\/[^"]*|)(")/g, '$1/sandbox$2');
  sandbox_link = sandbox_link.replace(/>view</, '>sandbox<');
  var testcases_link = view_link.replace(/("[^"]*)\/doc(?:\/[^"]*|)(")/g, '$1/testcases$2');
  testcases_link = testcases_link.replace(/>view</, '>testcases<');
  span_element.innerHTML = span_element.innerHTML + ' ' + sandbox_link + ' ' + testcases_link;
}
});
});