MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 7: | Line 7: | ||
var printCss = ` | var printCss = ` | ||
@media print { | @media print { | ||
/* Hide all non-content elements */ | /* Hide all non-content elements */ | ||
#mw-page-base, | #mw-page-base, | ||
| Line 59: | Line 58: | ||
// --- 2. Add PDF + Share buttons to Vector-2022 action bar --- | // --- 2. Add PDF + Share buttons to Vector-2022 action bar --- | ||
if (mw.config.get('wgNamespaceNumber') === 0) { | |||
var $actions = $('.vector-page-toolbar .vector-page-tools .vector-menu-content-list'); | |||
if ($actions.length) { | |||
// Remove any old PDF buttons (cleanup) | |||
$actions.find('a:contains("PDF")').closest('li').remove(); | |||
// PDF button (uses clean print mode) | |||
$actions.prepend( | |||
'<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download clean PDF">PDF</a></li>' | |||
); | |||
// Share button | |||
$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>' | |||
); | |||
} | |||
} | |||
// --- 3. Google Search Results under MediaWiki Search --- | |||
mw.loader.using('mediawiki.util', function () { | |||
// | // Nur auf der Suchseite aktivieren | ||
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return; | |||
// | // Suchbegriff aus URL holen | ||
var query = mw.util.getParamValue('search'); | |||
if (!query) return; | |||
); | |||
} | // Container für zusätzliche Ergebnisse | ||
}); | var container = document.createElement('div'); | ||
container.id = 'extra-search-results'; | |||
container.style.marginTop = '2em'; | |||
// --- Google Programmable Search --- | |||
var googlePSE = document.createElement('div'); | |||
googlePSE.innerHTML = ` | |||
<h2>Google Programmable Search</h2> | |||
<script async src="https://cse.google.com/cse.js?cx=86021a982e3a14848"></script> | |||
<div class="gcse-searchresults-only"></div> | |||
`; | |||
// --- Normale Google Websuche --- | |||
var googleNormal = document.createElement('div'); | |||
googleNormal.innerHTML = ` | |||
<h2>Google Websuche</h2> | |||
<iframe | |||
src="https://www.google.com/search?q=${encodeURIComponent(query)}" | |||
style="width:100%; height:600px; border:0;"> | |||
</iframe> | |||
`; | |||
// Unterhalb der MediaWiki-Suchergebnisse einfügen | |||
var mwResults = document.getElementById('mw-search-results'); | |||
if (mwResults) { | |||
container.appendChild(googlePSE); | |||
container.appendChild(googleNormal); | |||
mwResults.parentNode.insertBefore(container, mwResults.nextSibling); | |||
} | |||
}); | |||
}); // Ende $(function(){}) | |||
Revision as of 00:48, 21 January 2026
/* Any JavaScript here will be loaded for all users on every page load. */
/* Clean Print mode + PDF & Share buttons for Vector-2022 */
$(function () {
// --- 1. Inject Clean Print CSS (full-width A4, desktop + mobile) ---
var printCss = `
@media print {
/* Hide all non-content elements */
#mw-page-base,
#mw-head-base,
#mw-navigation,
#mw-panel,
#footer,
.vector-header,
.vector-page-toolbar,
.vector-toc,
.vector-sticky-header,
.vector-page-tools,
.vector-menu,
.mw-indicators,
.vector-user-links,
.vector-search-box,
.vector-pinned-container {
display: none !important;
}
/* Full-width content for A4 printing */
#content,
.mw-body,
.mw-content-container,
.mw-body-content {
margin: 0 !important;
padding: 0 !important;
width: 100% !important;
max-width: none !important;
}
/* White background for clean PDF */
body,
#content {
background: white !important;
}
/* Better print typography */
.mw-body-content {
font-size: 14pt !important;
line-height: 1.5 !important;
}
}
`;
var styleEl = document.createElement('style');
styleEl.type = 'text/css';
styleEl.appendChild(document.createTextNode(printCss));
document.head.appendChild(styleEl);
// --- 2. Add PDF + Share buttons to Vector-2022 action bar ---
if (mw.config.get('wgNamespaceNumber') === 0) {
var $actions = $('.vector-page-toolbar .vector-page-tools .vector-menu-content-list');
if ($actions.length) {
// Remove any old PDF buttons (cleanup)
$actions.find('a:contains("PDF")').closest('li').remove();
// PDF button (uses clean print mode)
$actions.prepend(
'<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download clean PDF">PDF</a></li>'
);
// Share button
$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>'
);
}
}
// --- 3. Google Search Results under MediaWiki Search ---
mw.loader.using('mediawiki.util', function () {
// Nur auf der Suchseite aktivieren
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;
// Suchbegriff aus URL holen
var query = mw.util.getParamValue('search');
if (!query) return;
// Container für zusätzliche Ergebnisse
var container = document.createElement('div');
container.id = 'extra-search-results';
container.style.marginTop = '2em';
// --- Google Programmable Search ---
var googlePSE = document.createElement('div');
googlePSE.innerHTML = `
<h2>Google Programmable Search</h2>
<script async src="https://cse.google.com/cse.js?cx=86021a982e3a14848"></script>
<div class="gcse-searchresults-only"></div>
`;
// --- Normale Google Websuche ---
var googleNormal = document.createElement('div');
googleNormal.innerHTML = `
<h2>Google Websuche</h2>
<iframe
src="https://www.google.com/search?q=${encodeURIComponent(query)}"
style="width:100%; height:600px; border:0;">
</iframe>
`;
// Unterhalb der MediaWiki-Suchergebnisse einfügen
var mwResults = document.getElementById('mw-search-results');
if (mwResults) {
container.appendChild(googlePSE);
container.appendChild(googleNormal);
mwResults.parentNode.insertBefore(container, mwResults.nextSibling);
}
});
}); // Ende $(function(){})