Benutzer:RikVII/common.js
aus Wikipedia, der freien Enzyklopädie
< Benutzer:RikVII
Dies ist die aktuelle Version dieser Seite, zuletzt bearbeitet am 10. September 2021 um 15:59 Uhr durch imported>Ladsgroup(567577) (Maintenance: Replacing legacy global variable (phab:T72470)).
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Strg+F5
var asqmReq = false;
if (mw.config.get('wgNamespaceNumber') == 0) {
$('<li id="ca-asqm" style="position: relative;"><span><a onclick="javascript:asqm()">ASQM</a></span>' +
'<div id="asqmContainer" style="visibility: hidden; position:absolute; right: 0; ' +
'font-size: 0.8em; border: 1px solid silver; margin: -5px 0 0 -1px; padding: 10px; ' +
'z-index: 1000; background: white;"></div></li>').insertAfter("#ca-history");
}
function asqm() {
if ($('#asqmContainer').css('visibility') == 'hidden') {
$('#asqmContainer').css('visibility', 'visible');
if (!asqmReq) {
$('#asqmContainer').html('<img src="http://toolserver.org/~render/stools/res/img/load.gif" style="padding: 20px;" />');
$.getJSON("http://toolserver.org/~render/stools/asqm/query/json/id/" +
mw.config.get('wgArticleId') + "/lang/" + mw.config.get('wgPageContentLanguage') + "/asqmid/0f74ca1e?callback=?", function(data) {
var output = "<table>";
$.each(data.asqmResponse, function(key, groupObj) {
output += "<tr><td colspan='2' style='text-align: center; font-weight: bold;'>" + groupObj.title + "</td></tr>";
$.each(groupObj.items, function(itemTitle, value) {
var link = "";
if ($.isArray(value)) {
link = value[1];
value = value[0];
}
if (link && link != "") {
value = "<a href='" + link + "' target='_blank'>" + value + "</a>";
}
output += "<tr><td>" + itemTitle + "</td><td>" + value.replace("|", "<br />") + "</td></tr>";
});
});
output += "</table>";
asqmReq = true;
$('#asqmContainer').html(output);
});
}
} else {
$('#asqmContainer').css('visibility', 'hidden');
}
}
importScript("user:lustiger_seth/unsigned.js");
//Dokumentation unter [[Benutzer:Schnark/js/notizen.js]] <nowiki>
/*global mediaWiki: false */
(function ($, mw) {
mw.messages.set({
'pagetitle': '$1 – {{SITENAME}}',
'brackets': '[$1]',
'wikinotes': 'Wikinotizen',
'wikinotes-minutes': 'Minuten',
'wikinotes-hours': 'Stunden',
'wikinotes-days': 'Tage',
'wikinotes-weeks': 'Wochen',
'wikinotes-months': 'Monate',
'wikinotes-years': 'Jahre',
'wikinotes-date-format': '$1, $2:$3',
'wikinotes-dateformat': 'd. M yy',
'wikinotes-alarm': '<i>$2</i> auf $1',
'wikinotes-disable-alarm': '✓',
'wikinotes-disable-alarm-title': 'Alarm ausschalten',
'wikinotes-delete-note': '✕',
'wikinotes-delete-note-title': 'Notiz löschen',
'wikinotes-alarms': 'Folgende Notizen erfordern Aufmerksamkeit: $1',
'wikinotes-no-notes': 'Du hast noch zu keiner Seite Notizen hinzugefügt.',
'wikinotes-list-head': 'Folgende Notizen hast du zu Seiten hinzugefügt ($1):',
'wikinotes-list-delete-all': 'alle Notizen löschen',
'wikinotes-list-page': 'Seite',
'wikinotes-list-title': 'Titel',
'wikinotes-list-alarm': 'Alarm',
'wikinotes-list-delete': 'Notiz löschen',
'wikinotes-no-alarm': '(kein Alarm)',
'wikinotes-list-alarm-rule': 'regelmäßig alle $1 $2',
'wikinotes-delete-from-list': 'löschen',
'wikinotes-dialog': 'Neue Notiz erstellen',
'wikinotes-dialog-intro': 'Mit diesem Dialog kannst eine neue Notiz erstellen und – falls gewünscht – einen Alarm für sie einrichten.',
'wikinotes-dialog-note': 'Notiz',
'wikinotes-dialog-title': 'Titel:',
'wikinotes-dialog-content': 'Inhalt:',
'wikinotes-dialog-alarm': 'Alarm',
'wikinotes-dialog-alarm-type': 'Art des Alarms:',
'wikinotes-dialog-alarm-type-none': 'kein Alarm',
'wikinotes-dialog-alarm-type-once': 'einmaliger Alarm',
'wikinotes-dialog-alarm-type-regular-times': 'Alarm zu regelmäßigen Zeitpunkten',
'wikinotes-dialog-alarm-type-regular-period': 'Alarm in regelmäßigen Abständen',
'wikinotes-dialog-alarm-time': 'Zeitpunkt:',
'wikinotes-dialog-expire': 'Alarm erlischt nach (0, falls er nicht automatisch erlöschen soll):',
'wikinotes-dialog-rule': 'Häufigkeit des Alarms:',
'wikinotes-dialog-save': 'Speichern',
'wikinotes-dialog-cancel': 'Abbrechen',
'wikinotes-error-date': 'Gib bitte einen korrekten Zeitpunkt an, der in der Zukunft liegt!',
'wikinotes-error-rule': 'Gib bitte eine eine korrekte Zahl für die zeitlichen Abstände des regelmäßigen Alarms an!',
'wikinotes-error-expire': 'Gib bitte eine korrekte Zahl für den automatischen Ablauf des Alarms an!',
'wikinotes-new': 'neue Notiz',
'wikinotes-new-title': 'Öffnet den Dialog zum Erstellen einer neuen Notiz'
});
function getCSS () {
return '#wikinotes-alarm { border: 3px solid red; }' +
'aside.wikinote { display: block; border-radius: 1em; background-color: yellow; padding: 0.2em; margin-right: 2em; min-width: 7em; float: left; }' +
'aside.active-alarm { border: 3px solid red; }' +
'aside.inactive-alarm h5::after { content: "✶"; color: gray; font-size: 150%; }' +
'aside.active-alarm h5::after { content: "✶"; color: red; font-size: 170%; }' +
'aside.wikinote .delete-note { float: right; }' +
'label.disabled { color: #ccc; }';
}
function isCompatible () {
return window.localStorage && window.JSON;
}
function random () {
return String(Math.floor(Math.random() * 10000 + 1));
}
var cachedData;
function getData () {
if (cachedData) {
return cachedData;
}
var data = localStorage.getItem('schnark-wikinotes');
if (data === null) {
data = {};
} else {
data = JSON.parse(data);
}
cachedData = data;
return data;
}
function setData (data) {
cachedData = data;
localStorage.setItem('schnark-wikinotes', JSON.stringify(data));
}
function deleteData () {
cachedData = {};
localStorage.removeItem('schnark-wikinotes');
}
function resetData () {
cachedData = false;
}
function addNote (note) {
var data = getData(), key = random();
while (key in data) {
key += random();
}
note.key = key;
data[key] = note;
setData(data);
return key;
}
function updateNote (key, note) {
var data = getData();
$.extend(data[key], note);
setData(data);
}
function deleteNote (key) {
var data = getData();
delete data[key];
setData(data);
}
function nextTime (start, rule) {
var date, toMS = {
's': 1000,
'm': 1000 * 60,
'h': 1000 * 60 * 60,
'd': 1000 * 60 * 60 * 24,
'w': 1000 * 60 * 60 * 24 * 7
};
if (!rule) {
return false;
}
if (rule.unit in toMS) {
return start + toMS[rule.unit] * rule.count;
}
date = new Date(start);
if (rule.unit === 'M') {
date.setMonth(date.getMonth() + rule.count);
} else {
date.setFullYear(date.getFullYear() + rule.count);
}
return Number(date);
}
function updateExpiredAlarm (alarm) {
do {
alarm.time = nextTime(alarm.time, alarm.rule);
} while (alarm.time && alarm.time + alarm.expire < $.now());
if (!alarm.time) {
return false;
}
return alarm;
}
function updateAlarm (alarm) {
var time = nextTime(alarm.rule && alarm.rule.fromNow ? $.now() : alarm.time, alarm.rule);
if (!time) {
return false;
}
alarm.time = time;
return alarm;
}
function updateAlarmFor (key) {
updateNote(key, {alarm: updateAlarm(getData()[key].alarm)});
}
function updateExpiredNotes () {
var key, data = getData(), note;
for (key in data) {
note = data[key];
if (note.alarm && note.alarm.expire && note.alarm.time + note.alarm.expire < $.now()) {
updateNote(key, {alarm: updateExpiredAlarm(note.alarm)});
}
}
}
function getActiveAlarms () {
var key, data = getData(), note, list = [];
for (key in data) {
note = data[key];
if (note.alarm && note.alarm.time <= $.now()) {
list.push(note);
}
}
return list;
}
function getNotesForPage () {
var key, data = getData(), note, list = [];
for (key in data) {
note = data[key];
if (note.page === mw.config.get('wgPageName')) {
list.push(note);
}
}
return list;
}
function getAllNotes () {
var key, data = getData(), list = [];
for (key in data) {
list.push(data[key]);
}
return list;
}
function formatAlarm (note) {
return mw.html.element('li', {'data-wikinoteskey': note.key}, new mw.html.Raw(
mw.msg('wikinotes-alarm',
mw.html.element('a', {href: mw.util.getUrl(note.page)}, note.page),
note.title
) + ' ' +
mw.html.element('a', {
href: '#',
'class': 'disable-alarm',
title: mw.msg('wikinotes-disable-alarm-title')
}, mw.msg('wikinotes-disable-alarm'))
));
}
function formatNote (note) {
var classes = ['wikinote'];
if (note.alarm) {
if (note.alarm.time <= $.now()) {
classes.push('active-alarm');
} else {
classes.push('inactive-alarm');
}
}
return mw.html.element('aside', {
'class': classes.join(' '),
'data-wikinoteskey': note.key
}, new mw.html.Raw(
mw.html.element('a', {
href: '#',
'class': 'delete-note',
title: mw.msg('wikinotes-delete-note-title')
}, mw.msg('wikinotes-delete-note')) + '\n' +
mw.html.element('h5', {}, note.title) + '\n' +
mw.html.element('div', {}, note.content)
));
}
function formatRow (note) {
var alarm, unitToMsg = {
m: 'wikinotes-minutes',
h: 'wikinotes-hours',
d: 'wikinotes-days',
w: 'wikinotes-weeks',
M: 'wikinotes-months',
Y: 'wikinotes-years'
};
if (!note.alarm) {
alarm = mw.msg('wikinotes-no-alarm');
} else {
alarm = (new Date(note.alarm.time)).toLocaleString();
if (note.alarm.rule) {
alarm += mw.html.element('br', {}) + mw.msg('wikinotes-list-alarm-rule', note.alarm.rule.count, mw.msg(unitToMsg[note.alarm.rule.unit]));
}
}
return mw.html.element('tr', {'data-wikinoteskey': note.key}, new mw.html.Raw([
mw.html.element('td', {}, new mw.html.Raw(
mw.html.element('a', {href: mw.util.getUrl(note.page + (note.section ? '#' + note.section : ''))}, note.page)
)),
mw.html.element('td', {}, note.title),
mw.html.element('td', {}, new mw.html.Raw(alarm)),
mw.html.element('td', {}, new mw.html.Raw(
mw.html.element('a', {href: '#', 'class': 'delete-note'}, mw.msg('wikinotes-delete-from-list'))
))
].join('')));
}
function readFromForm () {
var data = {
title: $('#wikinotes-title').val(),
content: $('#wikinotes-content').val()
}, alarmType, alarm, time, date, hour, minute, expire;
alarmType = $('#wikinotes-alarm-type :selected').val();
if (alarmType === 'none') {
alarm = false;
} else {
date = Number($('#wikinotes-alarm-date-hidden').val());
hour = Number($('#wikinotes-alarm-hour').val());
minute = Number($('#wikinotes-alarm-minute').val());
time = date + (hour * 60 + minute) * 60 * 1000;
if (isNaN(time) || time <= $.now()) {
return {error: mw.msg('wikinotes-error-date')};
}
if (alarmType === 'once') {
alarm = {time: time};
} else {
alarm = {
time: time,
rule: {
count: Number($('#wikinotes-alarm-rule-count').val()),
unit: $('#wikinotes-alarm-rule-unit :selected').val()
}
};
if (isNaN(alarm.rule.count) || alarm.rule.count <= 0) {
return {error: mw.msg('wikinotes-error-rule')};
}
if (alarmType === 'regularPeriod') {
alarm.rule.fromNow = true;
}
}
expire = Number($('#wikinotes-alarm-expire').val()) * $('#wikinotes-alarm-expire-unit :selected').val();
if (isNaN(expire) || expire < 0) {
return {error: mw.msg('wikinotes-error-expire')};
}
if (expire > 0) {
alarm.expire = expire;
}
}
data.alarm = alarm;
return data;
}
function showNotesForPage () {
var i, list = getNotesForPage(), head;
if (list.length === 0) {
return;
}
for (i = 0; i < list.length; i++) {
head = list[i].section && document.getElementById(list[i].section);
if (head) {
$(head).parent().after(formatNote(list[i]));
} else {
$('#mw-content-text').prepend(formatNote(list[i]));
}
}
$('.wikinote .delete-note').click(function (e) {
e.preventDefault();
var $note = $(this).parents('.wikinote');
deleteNote($note.data('wikinoteskey'));
$note.remove();
});
}
function showActiveAlarms () {
var i, list = getActiveAlarms(), html = [];
if (list.length === 0) {
return;
}
for (i = 0; i < list.length; i++) {
html.push(formatAlarm(list[i]));
}
html = mw.html.element('ul', {}, new mw.html.Raw(html.join('')));
html = mw.html.element('div', {id: 'wikinotes-alarm'}, new mw.html.Raw(mw.msg('wikinotes-alarms', html)));
$('#wikinotes-alarm').remove();
$('#content').prepend(html);
$('#wikinotes-alarm .disable-alarm').click(function (e) {
e.preventDefault();
var $this = $(this);
updateAlarmFor($this.parents('li').data('wikinoteskey'));
$this.remove();
});
}
function showAllNotes () {
var i, list = getAllNotes(), html = [];
document.title = mw.msg('pagetitle', mw.msg('wikinotes'));
$('#firstHeading').html(mw.msg('wikinotes'));
if (list.length === 0) {
$('#mw-content-text').html(mw.msg('wikinotes-no-notes'));
return;
}
html.push(mw.html.element('tr', {}, new mw.html.Raw([
mw.html.element('th', {}, mw.msg('wikinotes-list-page')),
mw.html.element('th', {}, mw.msg('wikinotes-list-title')),
mw.html.element('th', {}, mw.msg('wikinotes-list-alarm')),
mw.html.element('th', {}, mw.msg('wikinotes-list-delete'))
].join(''))));
for (i = 0; i < list.length; i++) {
html.push(formatRow(list[i]));
}
html = mw.html.element('table', {id: 'wikinotes-table', 'class': 'wikitable'}, new mw.html.Raw(html.join('')));
html = mw.html.element('p', {}, new mw.html.Raw(
mw.msg('wikinotes-list-head', mw.html.element('a', {id: 'delete-all-notes', href: '#'}, mw.msg('wikinotes-list-delete-all')))
)) + html;
$('#mw-content-text').html(html);
$('tr .delete-note').click(function (e) {
e.preventDefault();
var $tr = $(this).parents('tr');
deleteNote($tr.data('wikinoteskey'));
$tr.remove();
});
$('#delete-all-notes').click(function (e) {
e.preventDefault();
deleteData();
$('#wikinotes-table').remove();
});
}
function showNewNoteDialog (section) {
var html, $dialog;
function onClose () {
var note = readFromForm();
if (note.error) {
window.alert(note.error);
return;
}
note.page = mw.config.get('wgPageName');
if (section) {
note.section = section;
}
addNote(note);
$dialog.remove();
}
function enableDisable () {
var alarmType = $('#wikinotes-alarm-type :selected').val(),
selAlarmInput = '#wikinotes-alarm-date, #wikinotes-alarm-hour, #wikinotes-alarm-minute, #wikinotes-alarm-expire, #wikinotes-alarm-expire-unit',
selRuleInput = '#wikinotes-alarm-rule-count, #wikinotes-alarm-rule-unit',
selAlarmLabel = '[for="wikinotes-alarm-date"], [for="wikinotes-alarm-expire"]',
selRuleLabel = '[for="wikinotes-alarm-rule-count"]';
if (alarmType === 'none') {
$(selAlarmInput + ',' + selRuleInput).prop('disabled', true);
$(selAlarmLabel + ',' + selRuleLabel).addClass('disabled');
} else if (alarmType === 'once') {
$(selAlarmInput).prop('disabled', false);
$(selAlarmLabel).removeClass('disabled');
$(selRuleInput).prop('disabled', true);
$(selRuleLabel).addClass('disabled');
} else {
$(selAlarmInput + ',' + selRuleInput).prop('disabled', false);
$(selAlarmLabel + ',' + selRuleLabel).removeClass('disabled');
}
}
html =
mw.html.element('fieldset', {}, new mw.html.Raw(
mw.html.element('legend', {}, mw.msg('wikinotes-dialog-note')) +
mw.html.element('label', {'for': 'wikinotes-title'}, mw.msg('wikinotes-dialog-title')) + mw.html.element('br', {}) +
mw.html.element('input', {id: 'wikinotes-title', css: 'width: 100%;'}) + mw.html.element('br', {}) +
mw.html.element('label', {'for': 'wikinotes-content'}, mw.msg('wikinotes-dialog-content')) + mw.html.element('br', {}) +
mw.html.element('textarea', {id: 'wikinotes-content'})
)) + mw.html.element('fieldset', {}, new mw.html.Raw(
mw.html.element('legend', {}, mw.msg('wikinotes-dialog-alarm')) +
mw.html.element('label', {'for': 'wikinotes-alarm-type'}, mw.msg('wikinotes-dialog-alarm-type')) + mw.html.element('br', {}) +
mw.html.element('select', {id: 'wikinotes-alarm-type', size: 1}, new mw.html.Raw(
mw.html.element('option', {value: 'none', selected: true}, mw.msg('wikinotes-dialog-alarm-type-none')) +
mw.html.element('option', {value: 'once'}, mw.msg('wikinotes-dialog-alarm-type-once')) +
mw.html.element('option', {value: 'regularTimes'}, mw.msg('wikinotes-dialog-alarm-type-regular-times')) +
mw.html.element('option', {value: 'regularPeriod'}, mw.msg('wikinotes-dialog-alarm-type-regular-period'))
)) + mw.html.element('br', {}) +
mw.html.element('label', {'for': 'wikinotes-alarm-date'}, mw.msg('wikinotes-dialog-alarm-time')) + mw.html.element('br', {}) +
mw.msg('wikinotes-date-format',
mw.html.element('input', {id: 'wikinotes-alarm-date'}),
mw.html.element('input', {id: 'wikinotes-alarm-hour', size: 2, value: '12'}),
mw.html.element('input', {id: 'wikinotes-alarm-minute', size: 2, value: '00'})
) + mw.html.element('input', {id: 'wikinotes-alarm-date-hidden', type: 'hidden'}) + mw.html.element('br', {}) +
mw.html.element('label', {'for': 'wikinotes-alarm-expire'}, mw.msg('wikinotes-dialog-expire')) + mw.html.element('br', {}) +
mw.html.element('input', {id: 'wikinotes-alarm-expire', value: 0, size: 3}) + ' ' + mw.html.element('select', {id: 'wikinotes-alarm-expire-unit', size: 1}, new mw.html.Raw(
mw.html.element('option', {value: 1000 * 60}, mw.msg('wikinotes-minutes')) +
mw.html.element('option', {value: 1000 * 60 * 60}, mw.msg('wikinotes-hours')) +
mw.html.element('option', {value: 1000 * 60 * 60 * 24, selected: true}, mw.msg('wikinotes-days')) +
mw.html.element('option', {value: 1000 * 60 * 60 * 24 * 7}, mw.msg('wikinotes-weeks'))
)) + mw.html.element('br', {}) +
mw.html.element('label', {'for': 'wikinotes-alarm-rule-count'}, mw.msg('wikinotes-dialog-rule')) + mw.html.element('br', {}) +
mw.html.element('input', {id: 'wikinotes-alarm-rule-count', value: 1, size: 3}) + ' ' + mw.html.element('select', {id: 'wikinotes-alarm-rule-unit', size: 1}, new mw.html.Raw(
mw.html.element('option', {value: 'h'}, mw.msg('wikinotes-hours')) +
mw.html.element('option', {value: 'd', selected: true}, mw.msg('wikinotes-days')) +
mw.html.element('option', {value: 'w'}, mw.msg('wikinotes-weeks')) +
mw.html.element('option', {value: 'M'}, mw.msg('wikinotes-months')) +
mw.html.element('option', {value: 'Y'}, mw.msg('wikinotes-years'))
))
));
html = mw.html.element('p', {}, new mw.html.Raw(mw.msg('wikinotes-dialog-intro'))) + mw.html.element('p', {}, new mw.html.Raw(html));
$dialog = $('<div>').html(html);
$dialog.appendTo('body').dialog({
title: mw.msg('wikinotes-dialog'),
modal: true,
width: '47em',
close: function () {
$dialog.remove();
},
buttons: [{
text: mw.msg('wikinotes-dialog-save'),
click: onClose
}, {
text: mw.msg('wikinotes-dialog-cancel'),
click: function () {
$dialog.remove();
}
}]
});
$('#wikinotes-alarm-date').datepicker({
altField: '#wikinotes-alarm-date-hidden',
altFormat: '@',
autoSize: true,
dateFormat: mw.msg('wikinotes-dateformat'),
//defaultDate: 0,
minDate: 0
});
$('#wikinotes-alarm-type').change(enableDisable).change();
}
function addNewNote (e) {
var section = $(this).find('a').data('wikinotessection');
e.preventDefault();
mw.loader.using(['jquery.ui'], function () {
showNewNoteDialog(section);
});
}
function initAlarms () {
updateExpiredNotes();
$(function () {
showActiveAlarms();
window.setInterval(function () {
resetData();
showActiveAlarms();
}, 5 * 60 * 1000);
});
}
function initPage () {
if (mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === 'Wikinotes' || mw.config.get('wgTitle') === mw.msg('wikinotes'))) {
mw.config.set('wgCanonicalSpecialPageName', 'Wikinotes');
showAllNotes();
}
showNotesForPage();
}
function initNew () {
mw.util.$content.find('h1,h2,h3,h4,h5,h6').each(function (i, h) {
var $h = $(h), hash = $h.find('.mw-headline').attr('id') || '';
if (i === 0 || hash !== '') {
$h.append($('<span>')
.addClass('wikinotes-add-new mw-editsection noprint')
.html(mw.msg('brackets', mw.html.element('a', {href: '#', title: mw.msg('wikinotes-new-title'), 'data-wikinotessection': hash}, mw.msg('wikinotes-new'))))
);
}
});
$('.wikinotes-add-new').click(addNewNote);
}
function init () {
mw.util.addCSS(getCSS());
initAlarms();
$(function () {
initPage();
initNew();
});
}
if (mw.config.get('wgAction') === 'view' && isCompatible()) {
mw.loader.using(['mediawiki.util', 'mediawiki.jqueryMsg'], init);
}
})(jQuery, mediaWiki);
//</nowiki>
importScript('Benutzer:APPER/WikiHistory.js');
importScript("user:lustiger_seth/unsigned.js");