MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 85: | Line 85: | ||
const option6 = 'Jeśli chcesz dodać referencję do tego elementu w przypisie lub bibliografii, użyj poniższego formatu zapisu (więcej informacji na stronie -> <a href="https://prunus-208.man.poznan.pl/wiki/Referowanie_do_WikiHum" target="_blank">Referowanie do WikiHum)</a>.'; | const option6 = 'Jeśli chcesz dodać referencję do tego elementu w przypisie lub bibliografii, użyj poniższego formatu zapisu (więcej informacji na stronie -> <a href="https://prunus-208.man.poznan.pl/wiki/Referowanie_do_WikiHum" target="_blank">Referowanie do WikiHum)</a>.'; | ||
$('<div class="global-site-message">' + option6 + '<br><span id="copy-target">' + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</span><button id="copy-button" title="Kopiuj" style="margin-left: 8px; cursor: pointer;"> | $('<div class="global-site-message">' + option6 + '<br><span id="copy-target">' + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</span><button id="copy-button" title="Kopiuj" style="margin-left: 8px; cursor: pointer;">⧉</button></div>').prependTo('#content'); | ||
$('#copy-button').on('click', function () { | $('#copy-button').on('click', function () { | ||
const textToCopy = $('#copy-target').text(); | const textToCopy = $('#copy-target').text(); | ||
navigator.clipboard.writeText(textToCopy).then(() => { | navigator.clipboard.writeText(textToCopy).then(() => { | ||
$(this).text(' | $(this).text('✔'); | ||
setTimeout(() => $(this).text(' | setTimeout(() => $(this).text('⧉'), 1500); | ||
}); | }); | ||
}); | }); | ||
Revision as of 09:51, 28 May 2025
/* Any JavaScript here will be loaded for all users on every page load. */
$(function () {
const namespace = mw.config.get('wgNamespaceNumber');
const now = new Date();
const day = String(now.getDate()).padStart(2, '0');
const month = String(now.getMonth() + 1).padStart(2, '0');
const year = now.getFullYear();
var messageCurrentDate = `${day}.${month}.${year}`;
/* Prepare information about current Namespace Number; namespace_info can be added to the message below and displayed on all of the pages.*/
/*
var namespace_info = 'ID obecnego namespace: ' + namespace;
*/
/* Add a message to all of the pages regardless of the Namespace Number.*/
/*
var message = 'Referując do WikiHum należy używać <b>identyfikatorów Dariah.lab</b> (ang. Dariah.lab. ID).';
$('<div class="global-site-message">' + message + '</div>')
.prependTo('#content');
*/
if( namespace === 120 ){
const pageName = mw.config.get('wgPageName');
const entityId = mw.config.get('wgTitle');
const propertyId = 'P187'; /*ID of the property "Dariah.lab ID"*/
var messageLabel = '';
var messageEdit = '';
var messageDariahLab = '';
const userLang = mw.config.get('wgUserLanguage');
$.getJSON(mw.util.wikiScript('api'), {
action: 'wbgetentities',
ids: entityId,
props: 'labels',
languages: userLang,
format: 'json'
}, function (data) {
const entity = data.entities[entityId];
messageLabel = entity.labels[userLang].value;
/* $('<div class="global-site-message">' + messageLabel + userLang + '</div>').prependTo('#content'); */
});
$.getJSON(mw.util.wikiScript('api'), {
action: 'query',
prop: 'revisions',
titles: pageName,
rvprop: 'timestamp',
format: 'json'
}, function (data) {
var pages = data.query.pages;
var page = pages[Object.keys(pages)[0]];
if (page && page.revisions && page.revisions.length > 0) {
const lastEdit = new Date(page.revisions[0].timestamp);
const editDay = String(lastEdit.getDate()).padStart(2, '0');
const editMonth = String(lastEdit.getMonth() + 1).padStart(2, '0');
const editYear = lastEdit.getFullYear();
messageEdit = `${editDay}.${editMonth}.${editYear}`;
}
});
$.getJSON(mw.util.wikiScript('api'), {
action: 'wbgetentities',
ids: entityId,
format: 'json',
props: 'claims'
}, function (data) {
const entity = data.entities[entityId];
const claims = entity && entity.claims && entity.claims[propertyId];
if (claims && claims.length > 0) {
var dariahLabValue = claims[0].mainsnak.datavalue.value;
messageDariahLab = '<a href="http://hdl.handle.net/' + dariahLabValue + '" target="_blank">http://hdl.handle.net/' + dariahLabValue + '</a>';
}
const option1 = 'Referując do tego elementu użyj poniższego formatu zapisu (więcej informacji na stronie -> <a href="https://prunus-208.man.poznan.pl/wiki/Referowanie_do_WikiHum" target="_blank">Referowanie do WikiHum)</a>.';
const option2 = 'Referując do tego elementu w przypisie lub bibliografii użyj poniższego formatu zapisu (więcej informacji na stronie -> <a href="https://prunus-208.man.poznan.pl/wiki/Referowanie_do_WikiHum" target="_blank">Referowanie do WikiHum)</a>.';
const option3 = 'Referując do tego elementu należy użyć poniższego formatu zapisu (więcej informacji na stronie -> <a href="https://prunus-208.man.poznan.pl/wiki/Referowanie_do_WikiHum" target="_blank">Referowanie do WikiHum)</a>.';
const option4 = 'Referując do tego elementu w przypisie lub bibliografii należy użyć poniższego formatu zapisu (więcej informacji na stronie -> <a href="https://prunus-208.man.poznan.pl/wiki/Referowanie_do_WikiHum" target="_blank">Referowanie do WikiHum)</a>.';
const option5 = 'Jeśli chcesz dodać referencję do tego elementu, użyj poniższego formatu zapisu (więcej informacji na stronie -> <a href="https://prunus-208.man.poznan.pl/wiki/Referowanie_do_WikiHum" target="_blank">Referowanie do WikiHum)</a>.';
const option6 = 'Jeśli chcesz dodać referencję do tego elementu w przypisie lub bibliografii, użyj poniższego formatu zapisu (więcej informacji na stronie -> <a href="https://prunus-208.man.poznan.pl/wiki/Referowanie_do_WikiHum" target="_blank">Referowanie do WikiHum)</a>.';
$('<div class="global-site-message">' + option6 + '<br><span id="copy-target">' + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</span><button id="copy-button" title="Kopiuj" style="margin-left: 8px; cursor: pointer;">⧉</button></div>').prependTo('#content');
$('#copy-button').on('click', function () {
const textToCopy = $('#copy-target').text();
navigator.clipboard.writeText(textToCopy).then(() => {
$(this).text('✔');
setTimeout(() => $(this).text('⧉'), 1500);
});
});
$('<div class="global-site-message">' + option5 + '<br>' + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>').prependTo('#content');
$('<div class="global-site-message">' + option4 + '<br>' + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>').prependTo('#content');
$('<div class="global-site-message">' + option3 + '<br>' + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>').prependTo('#content');
$('<div class="global-site-message">' + option2 + '<br>' + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>').prependTo('#content');
$('<div class="global-site-message">' + option1 + '<br>' + messageLabel + ', ' + messageDariahLab + ', [ostatnia edycja strony: ' + messageEdit + ', dostęp: ' + messageCurrentDate + '].</div>').prependTo('#content');
});
}
});