משתמש:בוט גאון הירדן/קטגוריות מבוקשות.js
מראה
לתשומת ליבך: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
mw.loader.using(["mediawiki.api", "ext.gadget.mw-import"]).then(async () => {
if (
mw.config.get("wgPageName") == "מיוחד:קטגוריות_מבוקשות" &&
(mw.config.get("wgUserGroups").indexOf("bot") !== -1 ||
mw.config.get("wgUserId") === 4436)
) {
const num = prompt("כמה קטגוריות לקבל?");
const offset = prompt("מיקום התחלה (אופציונלי)")
if (!num) return;
const api = new mw.Api();
const importer = new mw.import();
const queryParams = {
list: "querypage",
qppage: "Wantedcategories",
qplimit: num,
};
if (offset) queryParams.qpoffset = offset;
const { query } = await api.get(queryParams);
if (!query) {
console.log("no response");
return;
}
console.log("טוען קטגוריות...");
const categoriesData = [];
for (const cat of query.querypage.results) {
try {
const { text, summary } = await importer.importWikitext({ page: cat.title });
categoriesData.push({
title: cat.title,
text: text,
summary: summary,
imported: false
});
} catch (error) {
console.error(`שגיאה בטעינת ${cat.title}:`, error);
categoriesData.push({
title: cat.title,
text: null,
summary: null,
error: error.message,
imported: false
});
}
}
const tableHtml = `
<div style="margin: 20px; direction: rtl;">
<table class="wikitable" style="width: 100%;">
<thead>
<tr>
<th style="width: 50%;">שם הקטגוריה</th>
<th style="width: 40%;">תוכן</th>
<th style="width: 10%;">פעולות</th>
</tr>
</thead>
<tbody id="categories-table-body">
${categoriesData.map((cat, index) => `
<tr id="cat-row-${index}">
<td><strong>${cat.title}</strong></td>
<td style="max-width: 300px; overflow: auto; font-size: 0.9em;">
${cat.text ? cat.text.substring(0, 200) + (cat.text.length > 200 ? '...' : '') : '<span style="color: red;">שגיאה בטעינה</span>'}
</td>
<td>
<button class="import-btn" data-index="${index}" ${!cat.text ? 'disabled' : ''}>
ייבא
</button>
</td>
</tr>
`).join('')}
</tbody>
</table>
</div>
`;
const $content = $(tableHtml);
$('#mw-content-text').prepend($content);
$content.on('click', '.import-btn', async function() {
const index = $(this).data('index');
const cat = categoriesData[index];
if (cat.imported) {
return;
}
try {
$(this).prop('disabled', true).text('מייבא...');
await api.postWithEditToken({
action: "edit",
format: "json",
bot: true,
title: cat.title,
text: cat.text,
summary: cat.summary,
});
cat.imported = true;
$(`#cat-row-${index}`).css('background-color', '#d4edda');
$(this).text('✓ ייובא').css('color', 'green');
console.log(`ייובא בהצלחה: ${cat.title}`);
} catch (error) {
console.error(`שגיאה בייבוא ${cat.title}:`, error);
$(this).prop('disabled', false).text('ייבא');
}
});
}
});