Участник:Skmp/EditPopups.js
Перейти к навигации
Перейти к поиску
let edit_popups_diffs = {};
const edit_popup_styles = "position: absolute; box-sizing: border-box; padding: 6px; z-index: 10000; width: 700px; height: 450px; background: white; box-shadow: 0 2px 5px hsl(0, 0%, 75%); border-radius: 3px; overflow: auto; margin: 25px 0 0 30px; top: 0; left: 0; cursor: pointer";
const edit_popup_html = '<table class="diff" style="font-size: 14px;">\
<colgroup>\
<col class="diff-marker">\
<col class="diff-content">\
<col class="diff-marker">\
<col class="diff-content">\
</colgroup>\
<tbody class="diff-container"></tbody>\
</table>';
function hidePopupEdit() {
const popups = document.getElementsByClassName("edit-preview-popup");
for(const popup of popups) {
popup.remove();
}
}
function showPopupEdit(el, revid) {
let popup = document.createElement("div");
popup.className = "edit-preview-popup";
popup.style.cssText = edit_popup_styles;
popup.innerHTML = edit_popup_html;
popup.onclick = hidePopupEdit;
popup.addEventListener("mouseleave", hidePopupEdit, false);
el.appendChild(popup);
if(edit_popups_diffs[revid]) {
popup.getElementsByClassName("diff-container")[0].innerHTML = edit_popups_diffs[revid];
} else {
$.post(mw.config.get('wgScriptPath') + "/api.php?action=compare&format=json", {
fromrev: revid,
torelative: "prev",
prop: "diff|parsedcomment"
}, function(response) {
edit_popups_diffs[revid] = response.compare["*"];
popup.getElementsByClassName("diff-container")[0].innerHTML = response.compare["*"];
});
}
}
function ep_createLink(el) {
let links = el.getElementsByClassName("mw-changeslist-links")[0];
links.style.position = "relative";
let new_el = document.createElement("a");
new_el.href = "javascript:hidePopupEdit()";
new_el.addEventListener("mouseenter", () => {
new_el.innerText = "×××";
hidePopupEdit();
showPopupEdit(links, el.dataset.mwRevid);
}, false);
new_el.addEventListener("mouseleave", () => {
new_el.innerText = "см.";
}, false);
new_el.className = "mw-changeslist-diff";
new_el.style.cssText = "font-family: monospace; font-size: 1em";
new_el.innerText = "см.";
links.prepend(new_el);
}
mw.loader.using('mediawiki.util').done(function() {
// Загрузка стилей
let mediawiki_css = document.createElement("link");
mediawiki_css.href = "https://www.mediawiki.org/w/load.php?modules=mediawiki.legacy.shared|mediawiki.diff.styles&only=styles";
mediawiki_css.rel = "stylesheet";
document.head.appendChild(mediawiki_css);
const edits = document.querySelectorAll(".mw-contributions-list > li, #pagehistory > li");
for(const edit of edits) {
ep_createLink(edit);
}
});