User:Dinoguy1000/common.js
< User:Dinoguy1000
Revision as of 05:03, 5 July 2023 by Dinoguy1000 (talk | contribs) (increase syntax highlighter timeout)
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: hold down Ctrl and click the Refresh or Reload button. Firefox: hold down ⇧ Shift while clicking Reload (or press Ctrl+⇧ Shift+R). Google Chrome and Safari users can just click the Reload button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
console.log('05:03, 5 July 2023 (UTC)');
const dgconf = mw.config.get([
'wgServer',
'wgPageName',
'wgCanonicalNamespace',
'wgTitle'
]);
dgconf.link = mw.util.addPortletLink;
/* begin stuff from [[User:Deltaneos/monobook.js]]
*/
// CSS refresh tab
$('#ca-purge').after('<li><a href="#" id="ca-css_refresh" title="Refresh the CSS on this page">css</a></li>');
$('#ca-css_refresh').click(function(ev)
{
ev.preventDefault();
var link = document.querySelector('link[href*="only=styles"]');
if (link !== null)
{
link.href += '&ts='+Date.now();
}
});
/* end copied from [[User:Deltaneos/monobook.js]] */
/* some mw.util.addPortletLink() documentation:
function mw.util.addPortletLink(
'HTML ID of the menu box to add the link to',
'full URL of the link's target page[1]',
'text to be displayed for the link',
'HTML ID for the inserted link',
'tooltip description to be displayed when hovering over the link',
'keyboard shortcut for the link' );
[1] This can be a literal URL, or JS variables such as wgServer can be used to enhance the code's portability.
A little bit of cleverness can be used to generate dynamic URLs as well; for instance,
"wgServer + '/index.php?title=Special:Log&page=' + wgPageName" will link to the current page's logs.
*/
$( function() {
// Courtesy of Becasita =D
$( '#catlinks li a' ).after( function( i, categoryName ) {
return $( '<a>', {
href: '/wiki/Special:RandomInCategory/' + categoryName,
title: 'Random page in category',
text: '⤭',
} );
} ).after( ' ' );
if( dgconf.wgCanonicalNamespace != 'Special' ) {
dgconf.link( 'p-tb', dgconf.wgServer + '/index.php?title=Special:Log&page=' + dgconf.wgPageName, 'Page logs', 'ca-viewlogs',
'View the logs for this page, such as renames, deletions, and protections', '' );
}
if( dgconf.wgCanonicalNamespace == 'Category' ) {
dgconf.link( 'p-tb', dgconf.wgServer + '/wiki/Special:RandomInCategory/' + dgconf.wgTitle, 'Random page in category', 'ca-randomincat',
'View a random page or file in this category', '' );
}
/* increase syntax highlighter timeout */
syntaxHighlighterConfig = {
timeout: 60,
}
});