MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
/* Clean Print mode + PDF & Share buttons for Vector-2022 */ | /* Clean Print mode + PDF & Share buttons for Vector-2022 */ | ||
| Line 7: | Line 8: | ||
var printCss = '' | var printCss = '' | ||
+ '@media print {' | + '@media print {' | ||
+ ' | + ' #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; }' | |||
+ ' | |||
+ ' | |||
+ ' | |||
+ ' | |||
+ ' | |||
+ ' | |||
+ '}'; | + '}'; | ||
| Line 53: | Line 27: | ||
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) { | ||
// Entferne alte PDF-Links | |||
$actions.find('li').filter(function () { | $actions.find('li').filter(function () { | ||
var t = $(this).text() || ''; | var t = $(this).text() || ''; | ||
| Line 58: | Line 34: | ||
}).remove(); | }).remove(); | ||
// PDF | |||
$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>' | ||
); | ); | ||
// Share | |||
$actions.prepend( | $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>' | '<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>' | ||
| Line 78: | Line 56: | ||
// CSS für collapsable Menüs | // CSS für collapsable Menüs | ||
var collapseCss = '' | var collapseCss = '' | ||
+ '#extra-search-results { margin-top: 2em; border-top: 1px solid #ddd; padding-top: 1em; }' | + '#extra-search-results { margin-top:2em; border-top:1px solid #ddd; padding-top:1em; }' | ||
+ '.search-collapse-section { margin-bottom: 1.5em; border: 1px solid #e0e0e0; border-radius: 4px; }' | + '.search-collapse-section { margin-bottom:1.5em; border:1px solid #e0e0e0; border-radius:4px; }' | ||
+ '.search-collapse-header { background: #f8f9fa; padding: 12px 15px; cursor: pointer; font-weight: bold; border-radius: 4px 4px 0 0; }' | + '.search-collapse-header { background:#f8f9fa; padding:12px 15px; cursor:pointer; font-weight:bold; border-radius:4px 4px 0 0; }' | ||
+ '.search-collapse-header:hover { background: #e8e9ea; }' | + '.search-collapse-header:hover { background:#e8e9ea; }' | ||
+ '.search-collapse-header::before { content: "▼ "; display: inline-block; transition: transform | + '.search-collapse-header::before { content:"▼ "; display:inline-block; transition:transform .2s; }' | ||
+ '.search-collapse-header.collapsed::before { transform: rotate(-90deg); }' | + '.search-collapse-header.collapsed::before { transform:rotate(-90deg); }' | ||
+ '.search-collapse-content { padding: 15px; display: block; }' | + '.search-collapse-content { padding:15px; display:block; }' | ||
+ '.search-collapse-content.collapsed { display: none; }' | + '.search-collapse-content.collapsed { display:none; }' | ||
+ '.gcse-searchresults-only { min-height: 200px; }' | + '.gcse-searchresults-only { min-height:200px; }' | ||
+ '.search-engine-link { display: block; padding: 8px 0; font-size: 16px; border-bottom: 1px solid #f0f0f0; }' | + '.search-engine-link { display:block; padding:8px 0; font-size:16px; border-bottom:1px solid #f0f0f0; }' | ||
+ '.search-engine-link:last-child { border-bottom: none; }' | + '.search-engine-link:last-child { border-bottom:none; }' | ||
+ '.search-engine-link a { text-decoration: none; color: #0645ad; }' | + '.search-engine-link a { text-decoration:none; color:#0645ad; }' | ||
+ '.search-engine-link a:hover { text-decoration: underline; }' | + '.search-engine-link a:hover { text-decoration:underline; }' | ||
+ '.pse-direct-link { margin-bottom: 15px; padding: 10px; background: #f0f7ff; border-radius: 4px; }' | + '.pse-direct-link { margin-bottom:15px; padding:10px; background:#f0f7ff; border-radius:4px; }' | ||
+ '.pse-direct-link a { font-size: 15px; color: #0066cc; text-decoration: none; }' | + '.pse-direct-link a { font-size:15px; color:#0066cc; text-decoration:none; }' | ||
+ '.pse-direct-link a:hover { text-decoration: underline; }'; | + '.pse-direct-link a:hover { text-decoration:underline; }'; | ||
var collapseStyle = document.createElement('style'); | var collapseStyle = document.createElement('style'); | ||
| Line 99: | Line 77: | ||
document.head.appendChild(collapseStyle); | document.head.appendChild(collapseStyle); | ||
// Finde die Paginierung | // Finde die Paginierung | ||
var pagination = $('.mw-search-pager-bottom, .results-info').last(); | var pagination = $('.mw-search-pager-bottom, .results-info').last(); | ||
var insertPoint = pagination.length ? pagination : $('#mw-search-results'); | var insertPoint = pagination.length ? pagination : $('#mw-search-results'); | ||
if (insertPoint.length) { | if (insertPoint.length) { | ||
var container = document.createElement('div'); | var container = document.createElement('div'); | ||
container.id = 'extra-search-results'; | container.id = 'extra-search-results'; | ||
// | // --- PSE Block --- | ||
var pseSection = document.createElement('div'); | var pseSection = document.createElement('div'); | ||
pseSection.className = 'search-collapse-section'; | pseSection.className = 'search-collapse-section'; | ||
var pseDirectUrl = 'https://cse.google.com/cse?cx=86021a982e3a14848&q=' + encodeURIComponent(query); | var pseDirectUrl = 'https://cse.google.com/cse?cx=86021a982e3a14848&q=' + encodeURIComponent(query); | ||
pseSection.innerHTML = | pseSection.innerHTML = | ||
'<div class="search-collapse-header" data-target="pse-content">Programmable Search Engine</div>' + | '<div class="search-collapse-header" data-target="pse-content">Programmable Search Engine</div>' + | ||
'<div class="search-collapse-content" id="pse-content">' + | '<div class="search-collapse-content" id="pse-content">' + | ||
'<div class="pse-direct-link">' + | '<div class="pse-direct-link">' + | ||
'<a href="' + pseDirectUrl + '" target="_blank" rel="noopener noreferrer"> | '<a href="' + pseDirectUrl + '" target="_blank" rel="noopener noreferrer">🔗 Open in Programmable Search Engine</a>' + | ||
'</div>' + | '</div>' + | ||
'<div class="gcse-searchresults-only" data-queryParameterName="gq"></div>' + | '<div class="gcse-searchresults-only" data-queryParameterName="gq"></div>' + | ||
'</div>'; | '</div>'; | ||
// GitHub Wikis | // --- GitHub Wikis Block (NEU, korrekt integriert) --- | ||
var githubSection = document.createElement('div'); | |||
githubSection.className = 'search-collapse-section'; | |||
var | var githubLinksHtml = ''; | ||
githubLinksHtml += | |||
'<div class="search-engine-link">' + | |||
'<a href="https://github.com/ET-Pioneer/Electric-Technocracy-Pioneers-Community/wiki/search?q=' + encodeURIComponent(query) + '" target="_blank" rel="noopener noreferrer">' + | |||
'📘 Search in Electric Technocracy Pioneers GitHub Wiki' + | |||
'</a>' + | |||
'</div>'; | |||
githubLinksHtml += | githubLinksHtml += | ||
'<div class="search-engine-link">' + | |||
'<a href="https://github.com/MrAnonymousNWO/One_World/wiki/search?q=' + encodeURIComponent(query) + '" target="_blank" rel="noopener noreferrer">' + | |||
'📗 Search in One World GitHub Wiki' + | |||
'</a>' + | |||
'</div>'; | |||
githubSection.innerHTML = | |||
'<div class="search-collapse-header" data-target="github-wikis-content">GitHub Wikis</div>' + | |||
'<div class="search-collapse-content" id="github-wikis-content">' + | |||
githubLinksHtml + | |||
'</div>'; | |||
// --- Alternative Suchmaschinen --- | |||
// Alternative Suchmaschinen | |||
var searchEngines = [ | var searchEngines = [ | ||
{ | { | ||
| Line 189: | Line 163: | ||
var searchSection = document.createElement('div'); | var searchSection = document.createElement('div'); | ||
searchSection.className = 'search-collapse-section'; | searchSection.className = 'search-collapse-section'; | ||
var searchLinksHtml = ''; | var searchLinksHtml = ''; | ||
searchEngines.forEach(function(engine) { | |||
searchLinksHtml += | searchEngines.forEach(function (engine) { | ||
searchLinksHtml += | |||
'<div class="search-engine-link">' + | '<div class="search-engine-link">' + | ||
'<a href="' + engine.url + '" target="_blank" rel="noopener noreferrer">' + | '<a href="' + engine.url + '" target="_blank" rel="noopener noreferrer">' + | ||
engine.icon + ' Search on ' + engine.name + '</a>' + | engine.icon + ' Search on ' + engine.name + | ||
'</a>' + | |||
'</div>'; | '</div>'; | ||
}); | }); | ||
searchSection.innerHTML = | searchSection.innerHTML = | ||
'<div class="search-collapse-header" data-target="search-engines-content">Alternative Search Engines</div>' + | '<div class="search-collapse-header" data-target="search-engines-content">Alternative Search Engines</div>' + | ||
| Line 205: | Line 181: | ||
'</div>'; | '</div>'; | ||
// --- Reihenfolge: PSE → GitHub Wikis → Alternative Engines --- | |||
container.appendChild(pseSection); | |||
container.appendChild(githubSection); | |||
container.appendChild(searchSection); | container.appendChild(searchSection); | ||
// Einfügen nach Paginierung | // Einfügen nach Paginierung | ||
| Line 214: | Line 195: | ||
} | } | ||
// Toggle-Funktionalität | |||
// Toggle-Funktionalität | |||
$('.search-collapse-header').on('click', function () { | $('.search-collapse-header').on('click', function () { | ||
var targetId = $(this).data('target'); | var targetId = $(this).data('target'); | ||
var content = $('#' + targetId); | var content = $('#' + targetId); | ||
$(this).toggleClass('collapsed'); | $(this).toggleClass('collapsed'); | ||
content.toggleClass('collapsed'); | content.toggleClass('collapsed'); | ||
}); | }); | ||
// Google CSE Script laden und Suche ausführen | // Google CSE Script laden und Suche ausführen | ||
if (!window.googleCSELoaded) { | if (!window.googleCSELoaded) { | ||
window.googleCSELoaded = true; | window.googleCSELoaded = true; | ||
window.__gcse = { | window.__gcse = { | ||
parsetags: 'explicit', | parsetags: 'explicit', | ||
callback: function() { | callback: function () { | ||
var element = document.querySelector('.gcse-searchresults-only'); | var element = document.querySelector('.gcse-searchresults-only'); | ||
if (element) { | if (element) { | ||
google.search.cse.element.render({ | google.search.cse.element.render({ | ||
div: element, | div: element, | ||
| Line 239: | Line 221: | ||
gname: 'pse_search' | gname: 'pse_search' | ||
}); | }); | ||
var searchControl = google.search.cse.element.getElement('pse_search'); | var searchControl = google.search.cse.element.getElement('pse_search'); | ||
if (searchControl) { | if (searchControl) { | ||
| Line 248: | Line 229: | ||
} | } | ||
}; | }; | ||
var s = document.createElement('script'); | var s = document.createElement('script'); | ||
s.async = true; | s.async = true; | ||
| Line 256: | Line 237: | ||
} | } | ||
}); | }); | ||
}); | |||
}); // Ende $(function() | } // Ende: if (insertPoint.length) | ||
}); // Ende: mw.loader.using | |||
}); // Ende: $(function()) | |||
Revision as of 19:44, 10 February 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 {'
+ ' #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) {
// Entferne alte PDF-Links
$actions.find('li').filter(function () {
var t = $(this).text() || '';
return t.toLowerCase().indexOf('pdf') !== -1;
}).remove();
// PDF
$actions.prepend(
'<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download clean PDF">PDF</a></li>'
);
// Share
$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;
// CSS für collapsable Menüs
var collapseCss = ''
+ '#extra-search-results { margin-top:2em; border-top:1px solid #ddd; padding-top:1em; }'
+ '.search-collapse-section { margin-bottom:1.5em; border:1px solid #e0e0e0; border-radius:4px; }'
+ '.search-collapse-header { background:#f8f9fa; padding:12px 15px; cursor:pointer; font-weight:bold; border-radius:4px 4px 0 0; }'
+ '.search-collapse-header:hover { background:#e8e9ea; }'
+ '.search-collapse-header::before { content:"▼ "; display:inline-block; transition:transform .2s; }'
+ '.search-collapse-header.collapsed::before { transform:rotate(-90deg); }'
+ '.search-collapse-content { padding:15px; display:block; }'
+ '.search-collapse-content.collapsed { display:none; }'
+ '.gcse-searchresults-only { min-height:200px; }'
+ '.search-engine-link { display:block; padding:8px 0; font-size:16px; border-bottom:1px solid #f0f0f0; }'
+ '.search-engine-link:last-child { border-bottom:none; }'
+ '.search-engine-link a { text-decoration:none; color:#0645ad; }'
+ '.search-engine-link a:hover { text-decoration:underline; }'
+ '.pse-direct-link { margin-bottom:15px; padding:10px; background:#f0f7ff; border-radius:4px; }'
+ '.pse-direct-link a { font-size:15px; color:#0066cc; text-decoration:none; }'
+ '.pse-direct-link a:hover { text-decoration:underline; }';
var collapseStyle = document.createElement('style');
collapseStyle.appendChild(document.createTextNode(collapseCss));
document.head.appendChild(collapseStyle);
// Finde die Paginierung
var pagination = $('.mw-search-pager-bottom, .results-info').last();
var insertPoint = pagination.length ? pagination : $('#mw-search-results');
if (insertPoint.length) {
var container = document.createElement('div');
container.id = 'extra-search-results';
// --- PSE Block ---
var pseSection = document.createElement('div');
pseSection.className = 'search-collapse-section';
var pseDirectUrl = 'https://cse.google.com/cse?cx=86021a982e3a14848&q=' + encodeURIComponent(query);
pseSection.innerHTML =
'<div class="search-collapse-header" data-target="pse-content">Programmable Search Engine</div>' +
'<div class="search-collapse-content" id="pse-content">' +
'<div class="pse-direct-link">' +
'<a href="' + pseDirectUrl + '" target="_blank" rel="noopener noreferrer">🔗 Open in Programmable Search Engine</a>' +
'</div>' +
'<div class="gcse-searchresults-only" data-queryParameterName="gq"></div>' +
'</div>';
// --- GitHub Wikis Block (NEU, korrekt integriert) ---
var githubSection = document.createElement('div');
githubSection.className = 'search-collapse-section';
var githubLinksHtml = '';
githubLinksHtml +=
'<div class="search-engine-link">' +
'<a href="https://github.com/ET-Pioneer/Electric-Technocracy-Pioneers-Community/wiki/search?q=' + encodeURIComponent(query) + '" target="_blank" rel="noopener noreferrer">' +
'📘 Search in Electric Technocracy Pioneers GitHub Wiki' +
'</a>' +
'</div>';
githubLinksHtml +=
'<div class="search-engine-link">' +
'<a href="https://github.com/MrAnonymousNWO/One_World/wiki/search?q=' + encodeURIComponent(query) + '" target="_blank" rel="noopener noreferrer">' +
'📗 Search in One World GitHub Wiki' +
'</a>' +
'</div>';
githubSection.innerHTML =
'<div class="search-collapse-header" data-target="github-wikis-content">GitHub Wikis</div>' +
'<div class="search-collapse-content" id="github-wikis-content">' +
githubLinksHtml +
'</div>';
// --- Alternative Suchmaschinen ---
var searchEngines = [
{
name: 'Google',
url: 'https://www.google.com/search?q=' + encodeURIComponent(query),
icon: '🔍'
},
{
name: 'Bing',
url: 'https://www.bing.com/search?q=' + encodeURIComponent(query),
icon: '🔎'
},
{
name: 'DuckDuckGo',
url: 'https://duckduckgo.com/?q=' + encodeURIComponent(query),
icon: '🦆'
},
{
name: 'Yandex',
url: 'https://yandex.com/search/?text=' + encodeURIComponent(query),
icon: '🔍'
},
{
name: 'Brave Search',
url: 'https://search.brave.com/search?q=' + encodeURIComponent(query),
icon: '🦁'
},
{
name: 'Ecosia',
url: 'https://www.ecosia.org/search?q=' + encodeURIComponent(query),
icon: '🌳'
}
];
var searchSection = document.createElement('div');
searchSection.className = 'search-collapse-section';
var searchLinksHtml = '';
searchEngines.forEach(function (engine) {
searchLinksHtml +=
'<div class="search-engine-link">' +
'<a href="' + engine.url + '" target="_blank" rel="noopener noreferrer">' +
engine.icon + ' Search on ' + engine.name +
'</a>' +
'</div>';
});
searchSection.innerHTML =
'<div class="search-collapse-header" data-target="search-engines-content">Alternative Search Engines</div>' +
'<div class="search-collapse-content" id="search-engines-content">' +
searchLinksHtml +
'</div>';
// --- Reihenfolge: PSE → GitHub Wikis → Alternative Engines ---
container.appendChild(pseSection);
container.appendChild(githubSection);
container.appendChild(searchSection);
// Einfügen nach Paginierung
if (pagination.length) {
pagination.after(container);
} else {
insertPoint.after(container);
}
// Toggle-Funktionalität
$('.search-collapse-header').on('click', function () {
var targetId = $(this).data('target');
var content = $('#' + targetId);
$(this).toggleClass('collapsed');
content.toggleClass('collapsed');
});
// Google CSE Script laden und Suche ausführen
if (!window.googleCSELoaded) {
window.googleCSELoaded = true;
window.__gcse = {
parsetags: 'explicit',
callback: function () {
var element = document.querySelector('.gcse-searchresults-only');
if (element) {
google.search.cse.element.render({
div: element,
tag: 'searchresults-only',
gname: 'pse_search'
});
var searchControl = google.search.cse.element.getElement('pse_search');
if (searchControl) {
searchControl.execute(query);
}
}
}
};
var s = document.createElement('script');
s.async = true;
s.src = 'https://cse.google.com/cse.js?cx=86021a982e3a14848';
document.head.appendChild(s);
}
}
});
});
} // Ende: if (insertPoint.length)
}); // Ende: mw.loader.using
}); // Ende: $(function())