משתמש:מוטי/סימון גרסאות קודמות.js
מראה
לתשומת ליבך: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
//נכתב על ידי מש:מוטי, תודות למש:איסתרק על הסיוע ישירות ובעקיפין
async function listEdits() {
const rcstart = new Date(Date.now() - 7890000000).toISOString();
const pageName = mw.config.get("wgPageName").replace(/_/g, " ");
try {
const { query } = await new mw.Api().get({
list: "recentchanges",
rclimit: 100,
rcshow: "!patrolled",
rctype: "edit|new",
rcstart: rcstart,
rcdir: "newer",
rcprop: "ids",
rctitle: pageName,
});
const edits = query?.recentchanges;
console.log(edits);
if (!edits || edits.length === 0) {
$("#editform").submit();
return;
}
const rcids = edits.map((item) => item.rcid);
OO.ui
.confirm(
`קיימות לדף זה ${edits.length} גרסאות שלא נבדקו תרצה לסמנן כבדוקות?`
)
.done(async (confirmed) => {
if (confirmed) {
const data = await sendArray(createPatrol(rcids));
const results = data.filter((item) => item.status === "fulfilled");
if (results.length === data.length) {
mw.notify(`כל העריכות בדף ${pageName} סומנו כבדוקות`, {
type: "success",
});
} else if (results.length > 0) {
mw.notify(
`${results.length} עריכות בדף ${pageName} סומנו כבדוקות`,
{ type: "success" }
);
} else {
mw.notify(`העריכות בדף ${pageName} לא סומנו כבדוקות`, {
type: "error",
});
}
}
$("#editform").submit();
});
} catch (error) {
console.error(error);
$("#editform").submit();
}
}
/**
* Patrols a specific RCID.
* @param {string} rcid - The RCID of the item to patrol.
* @return {Promise} A Promise that resolves with the result of the patrol action.
*/
function patrol(rcid) {
var params = {
action: "patrol",
rcid: rcid,
format: "json",
},
api = new mw.Api();
return api.postWithToken("patrol", params);
}
/**
* Creates a new `Patrol` object for each item in the given array.
*
* @param {Array} arr - The array of items to create `Patrol` objects from.
* @return {Array} - The array of `Patrol` objects created from the given array.
*/
function createPatrol(arr) {
return arr.map((item) => patrol(item));
}
/**
* Sends an array of promises and returns the settled values of each promise.
*
* @param {Array<Promise>} arrPromises - An array of promises to be settled.
* @return {Promise<Array<Object>>} - A promise that resolves to an array of settled values.
*/
async function sendArray(arrPromises) {
return Promise.allSettled(arrPromises).then((data) => data);
}
function handleSaveButtonClick() {
const summary = $("#wpSummary").val();
const summaryUpdate = /עדכון מוויקיפדיה/;
const summaryExisting = summaryUpdate.test(summary);
if (summaryExisting) {
listEdits();
} else {
$("#editform").submit();
}
}
if (
mw.config.get("wgAction") === "edit" ||
mw.config.get("wgAction") === "submit"
) {
let catched = false;
//if (catched) return;
$("#editform").submit((e) => {
if (!e.originalEvent || e.originalEvent.submitter.id !== "wpSave") return;
e.preventDefault();
catched = true;
handleSaveButtonClick();
});
}