Jump to content

MediaWiki:Common.js

From International Treaty Law 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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/* Add PDF + Share links to the Vector-2022 page tools bar */
$(function () {

    // Only on article pages (namespace 0)
    if (mw.config.get('wgNamespaceNumber') !== 0) return;

    // Find the Vector-2022 action bar (the row with Read / Edit / View history)
    var $actions = $('.vector-page-toolbar .vector-page-tools .vector-menu-content-list');

    if ($actions.length) {

        // PDF link
        $actions.prepend(
            '<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download as PDF">PDF</a></li>'
        );

        // Share link
        $actions.prepend(
            '<li class="vector-menu-content-list-item"><a href="javascript:navigator.share ? navigator.share({title: document.title, url: location.href}) : prompt(\'Copy link:\', location.href)" title="Share this page">Share</a></li>'
        );
    }
});