MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (65 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
$(function () { | $(function () { | ||
const namespace = mw.config.get('wgNamespaceNumber'); | const namespace = mw.config.get('wgNamespaceNumber'); | ||
var message = 'Referując do WikiHum należy używać <b>identyfikatorów Dariah.lab</b> (ang. Dariah.lab. ID). | 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>') | $('<div class="global-site-message">' + message + '</div>') | ||
.prependTo('#content'); | .prependTo('#content'); | ||
*/ | |||
if( namespace === 120 ){ | if( namespace === 120 ){ | ||
const | const pageName = mw.config.get('wgPageName'); | ||
const entityId = mw.config.get('wgTitle'); | const entityId = mw.config.get('wgTitle'); | ||
const propertyId = 'P187'; | 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'), { | $.getJSON(mw.util.wikiScript('api'), { | ||
action: 'query', | action: 'query', | ||
prop: 'revisions', | prop: 'revisions', | ||
titles: | titles: pageName, | ||
rvprop: 'timestamp', | rvprop: 'timestamp', | ||
format: 'json' | format: 'json' | ||
| Line 26: | Line 57: | ||
var page = pages[Object.keys(pages)[0]]; | var page = pages[Object.keys(pages)[0]]; | ||
if (page && page.revisions && page.revisions.length > 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}`; | |||
} | |||
}); | }); | ||
| Line 38: | Line 73: | ||
const entity = data.entities[entityId]; | const entity = data.entities[entityId]; | ||
const claims = entity && entity.claims && entity.claims[propertyId]; | const claims = entity && entity.claims && entity.claims[propertyId]; | ||
if (claims && claims.length > 0) { | 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 finalMessage = '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>.'; | |||
$('<div class="global-site-message">' + finalMessage + '<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; transform: scale(0.95);">⧉</button></div>').prependTo('#content'); | |||
$('#copy-button').on('click', function () { | |||
const plainTextToCopy = $('#copy-target').text(); | |||
const htmlTextToCopy = $('#copy-target').html(); | |||
const blobText = new Blob([plainTextToCopy], { type: 'text/plain' }); | |||
const blobHTML = new Blob([htmlTextToCopy], { type: 'text/html' }); | |||
const item = new ClipboardItem({ | |||
'text/plain': blobText, | |||
'text/html': blobHTML | |||
}); | |||
navigator.clipboard.write([item]).then(() => { | |||
$(this).text('✔'); | |||
setTimeout(() => $(this).text('⧉'), 1500); | |||
}); | |||
}); | }); | ||
}); | |||
} | } | ||
}); | }); | ||
Latest revision as of 14:14, 30 June 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 finalMessage = '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>.';
$('<div class="global-site-message">' + finalMessage + '<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; transform: scale(0.95);">⧉</button></div>').prependTo('#content');
$('#copy-button').on('click', function () {
const plainTextToCopy = $('#copy-target').text();
const htmlTextToCopy = $('#copy-target').html();
const blobText = new Blob([plainTextToCopy], { type: 'text/plain' });
const blobHTML = new Blob([htmlTextToCopy], { type: 'text/html' });
const item = new ClipboardItem({
'text/plain': blobText,
'text/html': blobHTML
});
navigator.clipboard.write([item]).then(() => {
$(this).text('✔');
setTimeout(() => $(this).text('⧉'), 1500);
});
});
});
}
});