MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 5: | Line 5: | ||
// --- 1. Inject Clean Print CSS (full-width A4, desktop + mobile) --- | // --- 1. Inject Clean Print CSS (full-width A4, desktop + mobile) --- | ||
var printCss = | var printCss = '' | ||
@media print { | + '@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; | + ' display: none !important;' | ||
+ ' }' | |||
+ ' #content,' | |||
+ ' .mw-body,' | |||
+ ' .mw-content-container,' | |||
+ ' .mw-body-content {' | |||
+ ' margin: 0 !important;' | |||
+ ' padding: 0 !important;' | |||
margin: 0 !important; | + ' width: 100% !important;' | ||
padding: 0 !important; | + ' max-width: none !important;' | ||
width: 100% !important; | + ' }' | ||
max-width: none !important; | + ' body,' | ||
+ ' #content {' | |||
+ ' background: white !important;' | |||
+ ' }' | |||
+ ' .mw-body-content {' | |||
+ ' font-size: 14pt !important;' | |||
background: white !important; | + ' line-height: 1.5 !important;' | ||
+ ' }' | |||
+ '}'; | |||
font-size: 14pt !important; | |||
line-height: 1.5 !important; | |||
} | |||
var styleEl = document.createElement('style'); | var styleEl = document.createElement('style'); | ||
| Line 55: | Line 48: | ||
styleEl.appendChild(document.createTextNode(printCss)); | styleEl.appendChild(document.createTextNode(printCss)); | ||
document.head.appendChild(styleEl); | document.head.appendChild(styleEl); | ||
// --- 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) { | if (mw.config.get('wgNamespaceNumber') === 0) { | ||
var $actions = $('.vector-page-toolbar .vector-page-tools .vector-menu-content-list'); | var $actions = $('.vector-page-toolbar .vector-page-tools .vector-menu-content-list'); | ||
if ($actions.length) { | if ($actions.length) { | ||
$actions.find('li').filter(function () { | |||
var t = $(this).text() || ''; | |||
return t.toLowerCase().indexOf('pdf') !== -1; | |||
}).remove(); | |||
$actions.prepend( | $actions.prepend( | ||
'<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download clean PDF">PDF</a></li>' | '<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download clean PDF">PDF</a></li>' | ||
); | ); | ||
$actions.prepend( | $actions.prepend( | ||
'<li class="vector-menu-content-list-item"><a href="javascript:navigator.share | '<li class="vector-menu-content-list-item"><a href="javascript:(function(){if(navigator.share){navigator.share({title:document.title,url:location.href});}else{prompt(\'Copy link:\',location.href);}})()" title="Share this page">Share</a></li>' | ||
); | ); | ||
} | } | ||
} | } | ||
// --- 3. Google Search Results under MediaWiki Search --- | // --- 3. Google Search Results under MediaWiki Search --- | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using('mediawiki.util', function () { | ||
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return; | if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return; | ||
var query = mw.util.getParamValue('search'); | var query = mw.util.getParamValue('search'); | ||
if (!query) return; | if (!query) return; | ||
var container = document.createElement('div'); | var container = document.createElement('div'); | ||
container.id = 'extra-search-results'; | container.id = 'extra-search-results'; | ||
container.style.marginTop = '2em'; | container.style.marginTop = '2em'; | ||
// | // Google Programmable Search | ||
var googlePSE = document.createElement('div'); | var googlePSE = document.createElement('div'); | ||
googlePSE.innerHTML = | googlePSE.id = 'google-pse-block'; | ||
<h2>Google Programmable Search</h2> | googlePSE.innerHTML = | ||
'<h2>Google Programmable Search</h2>' + | |||
'<div class="gcse-searchresults-only"></div>'; | |||
// | // Normale Google Websuche (nur Link, kein iframe) | ||
var googleNormal = document.createElement('div'); | var googleNormal = document.createElement('div'); | ||
googleNormal.innerHTML = | googleNormal.id = 'google-normal-block'; | ||
<h2>Google Websuche</h2> | googleNormal.innerHTML = | ||
< | '<h2>Google Websuche</h2>' + | ||
'<p><a href="https://www.google.com/search?q=' + | |||
encodeURIComponent(query) + | |||
</ | '" target="_blank" rel="noopener noreferrer">' + | ||
'Ergebnisse in Google für „' + query.replace(/"/g, '"') + '“</a></p>'; | |||
var mwResults = document.getElementById('mw-search-results'); | var mwResults = document.getElementById('mw-search-results'); | ||
if (mwResults) { | if (mwResults) { | ||
| Line 119: | Line 102: | ||
container.appendChild(googleNormal); | container.appendChild(googleNormal); | ||
mwResults.parentNode.insertBefore(container, mwResults.nextSibling); | mwResults.parentNode.insertBefore(container, mwResults.nextSibling); | ||
// Google CSE Script einmalig laden | |||
if (!document.getElementById('gcse-script')) { | |||
var s = document.createElement('script'); | |||
s.id = 'gcse-script'; | |||
s.async = true; | |||
s.src = 'https://cse.google.com/cse.js?cx=86021a982e3a14848'; | |||
document.head.appendChild(s); | |||
} | |||
} | } | ||
}); | }); | ||
}); // Ende $(function(){}) | }); // Ende $(function(){}) | ||
Revision as of 00:53, 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;'
+ ' }'
+ ' #content,'
+ ' .mw-body,'
+ ' .mw-content-container,'
+ ' .mw-body-content {'
+ ' margin: 0 !important;'
+ ' padding: 0 !important;'
+ ' width: 100% !important;'
+ ' max-width: none !important;'
+ ' }'
+ ' body,'
+ ' #content {'
+ ' background: white !important;'
+ ' }'
+ ' .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) {
$actions.find('li').filter(function () {
var t = $(this).text() || '';
return t.toLowerCase().indexOf('pdf') !== -1;
}).remove();
$actions.prepend(
'<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download clean PDF">PDF</a></li>'
);
$actions.prepend(
'<li class="vector-menu-content-list-item"><a href="javascript:(function(){if(navigator.share){navigator.share({title:document.title,url:location.href});}else{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 () {
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;
var query = mw.util.getParamValue('search');
if (!query) return;
var container = document.createElement('div');
container.id = 'extra-search-results';
container.style.marginTop = '2em';
// Google Programmable Search
var googlePSE = document.createElement('div');
googlePSE.id = 'google-pse-block';
googlePSE.innerHTML =
'<h2>Google Programmable Search</h2>' +
'<div class="gcse-searchresults-only"></div>';
// Normale Google Websuche (nur Link, kein iframe)
var googleNormal = document.createElement('div');
googleNormal.id = 'google-normal-block';
googleNormal.innerHTML =
'<h2>Google Websuche</h2>' +
'<p><a href="https://www.google.com/search?q=' +
encodeURIComponent(query) +
'" target="_blank" rel="noopener noreferrer">' +
'Ergebnisse in Google für „' + query.replace(/"/g, '"') + '“</a></p>';
var mwResults = document.getElementById('mw-search-results');
if (mwResults) {
container.appendChild(googlePSE);
container.appendChild(googleNormal);
mwResults.parentNode.insertBefore(container, mwResults.nextSibling);
// Google CSE Script einmalig laden
if (!document.getElementById('gcse-script')) {
var s = document.createElement('script');
s.id = 'gcse-script';
s.async = true;
s.src = 'https://cse.google.com/cse.js?cx=86021a982e3a14848';
document.head.appendChild(s);
}
}
});
}); // Ende $(function(){})