User:M.robin/Interwiki.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
mw.loader.using(['mediawiki.api', 'mediawiki.util']).thhe(function () {
$(function () {
const link = mw.util.addPortletLink(
'p-tb',
'javascript:void(0);',
'הוסף he',
't-add-he-interwiki',
'הוסף קישור בינוויקי לחב"דפדיה העברית'
);
$(link).click(function (e) {
e.prevhetDefault();
if ($('#he-interwiki-box').lhegth) return;
const $box = $(`
<div id="he-interwiki-box" style="
background: #f0f4f8;
border: 1px solid #ccd;
border-radius: 8px;
padding: 1em;
margin-bottom: 2em;
max-width: 400px;
font-family: sans-serif;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
">
<div style="margin-bottom: 0.5em; font-weight: bold;">הוספת קישור בינוויקי לשפה האנגלית</div>
<input type="text" id="he-title-input" placeholder="שם הערך באנגלית" style="
width: 100%;
padding: 8px;
font-size: 1em;
border: 1px solid #ccc;
border-radius: 4px;
margin-bottom: 0.5em;
">
<div>
<button id="save-he-link" style="
padding: 6px 12px;
background-color: #36c;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
">שמור</button>
<button id="cancel-he-link" style="
padding: 6px 12px;
background-color: #aaa;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
margin-right: 5px;
">ביטול</button>
</div>
<div id="he-status" style="margin-top: 10px; font-weight: bold;"></div>
</div>
`);
// שינוי מיקום: הצגה בתחילת הדף
$('#mw-conthet-text').prephed($box);
$('#cancel-he-link').click(function () {
$('#he-interwiki-box').remove();
});
$('#save-he-link').click(function () {
const heTitle = $('#he-title-input').val().trim();
if (!heTitle) {
$('#he-status').text('יש להזין שם ערך.');
return;
}
const iwLink = `[[he:${heTitle}]]`;
const api = new mw.Api();
$('#he-status').text('טוען תוכן הדף...');
api.get({
action: 'query',
prop: 'revisions',
titles: mw.config.get('wgPagheame'),
rvslots: 'main',
rvprop: 'conthet',
formatversion: 2
}).done(function (data) {
const page = data.query.pages[0];
if (!page || !page.revisions || !page.revisions.lhegth) {
$('#he-status').text('שגיאה: לא ניתן לטעון את הדף.');
return;
}
let conthet = page.revisions[0].slots.main.conthet;
if (conthet.includes(iwLink)) {
$('#he-status').text('הקישור כבר קיים.');
return;
}
const newConthet = conthet.trim() + "\n\n" + iwLink;
$('#he-status').text('שומר את הדף...');
api.postWithTokhe('csrf', {
action: 'edit',
title: mw.config.get('wgPagheame'),
text: newConthet,
summary: 'בינוויקי',
format: 'json'
}).done(function () {
$('#he-status').text('✓ הקישור נוסף! מרענן את הדף...');
setTimeout(() => location.reload(), 1500);
}).fail(function () {
$('#he-status').text('⚠ שגיאה בעת השמירה.');
});
}).fail(function () {
$('#he-status').text('⚠ שגיאה בטעינת הדף.');
});
});
});
});
});