Content deleted Content added
fix grammar, and check for identical versions |
m Maintenance: Fixing deprecated call to addPortletLink (mw:ResourceLoader/Migration_guide_(users)#addPortletLink) |
||
(16 intermediate revisions by one other user not shown) | |||
Line 1:
//<pre>
// Summarizes the differences between two page versions in pop-up windows
// Perhaps calculate fractional change in document?
//
// To use this script, add "importScript('User:Proteins/quickdiffs.js');" to your monobook.js subpage
// under your user page, as you can see at User:Proteins/monobook.js
function quickDiffs() {
Line 38 ⟶ 42:
var diff_new_version_info; //className = "diff-ntitle"
var mw_diff_otitle1
var
var mw_diff_otitle1_grandchild;
var
var
var
var mw_diff_otitle2_grandchild;
var
var mw_diff_otitle3;
var mw_diff_otitle3_child;
var mw_diff_otitle3_grandchild;
var mw_diff_otitle3_text = "";
var mw_diff_otitle4;
var mw_diff_otitle4_child;
var mw_diff_otitle4_grandchild;
var mw_diff_otitle4_text = "";
var mw_diff_ntitle1;
var mw_diff_ntitle1_child;
var mw_diff_ntitle1_grandchild;
var mw_diff_ntitle1_text = "";
var mw_diff_ntitle2;
var mw_diff_ntitle2_child;
var mw_diff_ntitle2_grandchild;
var mw_diff_ntitle2_text = "";
var mw_diff_ntitle3;
var mw_diff_ntitle3_child;
var mw_diff_ntitle3_grandchild;
var mw_diff_ntitle3_text = "";
var mw_diff_ntitle4;
var mw_diff_ntitle4_child;
var mw_diff_ntitle4_grandchild;
var mw_diff_ntitle4_text = "";
var revisions = "";
var num_revisions = 0;
Line 184 ⟶ 217:
}
// Get header texts for older version
mw_diff_otitle1_text = "";
mw_diff_otitle1 = document.getElementById('mw-diff-otitle1');
if (!mw_diff_otitle1) {
window.alert("ERROR: This article has no element with id \"mw-diff-otitle1\".\n\n");
} else {
mw_diff_otitle1_child = mw_diff_otitle1.firstChild;
if (!mw_diff_otitle1_child) {
window.alert("ERROR: The \"mw-diff-otitle1\" element has no child node.\n\n");
} else {
mw_diff_otitle1_grandchild = mw_diff_otitle1_child.firstChild;
if (!mw_diff_otitle1_grandchild) {
window.alert("ERROR: The \"mw-diff-otitle1\" element has no grandchild node.\n\n");
} else {
mw_diff_otitle1_text = mw_diff_otitle1_grandchild.innerHTML;
} // closes check for grandchild node
} // closes check for child node
} // closes check for mw_diff_otitle1 node
// window.alert("The mw_diff_otitle1_text is " + mw_diff_otitle1_text + "\n");
mw_diff_otitle2_text = "";
mw_diff_otitle2 = document.getElementById('mw-diff-otitle2');
if (!mw_diff_otitle2) {
window.alert("ERROR: This article has no element with id \"mw-diff-otitle2\".\n\n");
} else {
mw_diff_otitle2_child = mw_diff_otitle2.firstChild;
if (!mw_diff_otitle2_child) {
window.alert("ERROR: The \"mw-diff-otitle2\" element has no child node.\n\n");
} else {
mw_diff_otitle2_text = mw_diff_otitle2_child.innerHTML;
} // closes check for child node
} // closes check for mw_diff_otitle2 node
// window.alert("The mw_diff_otitle2_text is " + mw_diff_otitle2_text + "\n");
mw_diff_otitle3_text = "";
mw_diff_otitle3 = document.getElementById('mw-diff-otitle3');
if (!mw_diff_otitle3) {
window.alert("ERROR: This article has no element with id \"mw-diff-otitle3\".\n\n");
} else {
mw_diff_otitle3_text = mw_diff_otitle3.innerHTML;
mw_diff_otitle3_text = mw_diff_otitle3_text.replace(/>/ig, ">");
mw_diff_otitle3_text = mw_diff_otitle3_text.replace(/</ig, "<");
mw_diff_otitle3_text = mw_diff_otitle3_text.replace(/(<([^>]+)>)/ig,"");
} // closes check for mw_diff_otitle3 node
// window.alert("The mw_diff_otitle3_text is " + mw_diff_otitle3_text + "\n");
// Possibly add code for mw_diff_otitle4 here, but seems unneeded
// Get header texts for newer version
mw_diff_ntitle1_text = "";
mw_diff_ntitle1 = document.getElementById('mw-diff-ntitle1');
if (!mw_diff_ntitle1) {
window.alert("ERROR: This article has no element with id \"mw-diff-ntitle1\".\n\n");
} else {
mw_diff_ntitle1_child = mw_diff_ntitle1.firstChild;
if (!mw_diff_ntitle1_child) {
window.alert("ERROR: The \"mw-diff-ntitle1\" element has no child node.\n\n");
} else {
mw_diff_ntitle1_grandchild = mw_diff_ntitle1_child.firstChild;
if (!mw_diff_ntitle1_grandchild) {
window.alert("ERROR: The \"mw-diff-ntitle1\" element has no grandchild node.\n\n");
} else {
mw_diff_ntitle1_text = mw_diff_ntitle1_grandchild.innerHTML;
} // closes check for grandchild node
} // closes check for child node
} // closes check for mw_diff_ntitle1 node
// window.alert("The mw_diff_ntitle1_text is " + mw_diff_ntitle1_text + "\n");
mw_diff_ntitle2_text = "";
mw_diff_ntitle2 = document.getElementById('mw-diff-ntitle2');
if (!mw_diff_ntitle2) {
window.alert("ERROR: This article has no element with id \"mw-diff-ntitle2\".\n\n");
} else {
mw_diff_ntitle2_child = mw_diff_ntitle2.firstChild;
if (!mw_diff_ntitle2_child) {
window.alert("ERROR: The \"mw-diff-ntitle2\" element has no child node.\n\n");
} else {
mw_diff_ntitle2_text = mw_diff_ntitle2_child.innerHTML;
} // closes check for child node
} // closes check for mw_diff_ntitle2 node
// window.alert("The mw_diff_ntitle2_text is " + mw_diff_ntitle2_text + "\n");
mw_diff_ntitle3_text = "";
mw_diff_ntitle3 = document.getElementById('mw-diff-ntitle3');
if (!mw_diff_ntitle3) {
window.alert("ERROR: This article has no element with id \"mw-diff-ntitle3\".\n\n");
} else {
mw_diff_ntitle3_text = mw_diff_ntitle3.innerHTML;
mw_diff_ntitle3_text = mw_diff_ntitle3_text.replace(/>/ig, ">");
mw_diff_ntitle3_text = mw_diff_ntitle3_text.replace(/</ig, "<");
mw_diff_ntitle3_text = mw_diff_ntitle3_text.replace(/(<([^>]+)>)/ig,"");
} // closes check for mw_diff_ntitle3 node
// window.alert("The mw_diff_ntitle3_text is " + mw_diff_ntitle3_text + "\n");
// Possibly add code for mw_diff_ntitle4 here, but seems unneeded
// Loop over the rows in the difference table
num_alert_strings = 0;
alert_string_list[0] = "NONE";
Line 238 ⟶ 368:
if (!temp_table_datum_text_node) { continue; }
if (temp_table_datum_text_node.nodeType == 3) {
num_revisions = 0; // to flag for errors
temp_table_datum_text = temp_table_datum_text_node.data;
num_revisions = 2;
} else {
temp_table_datum_text = temp_table_datum_text.replace(/[^0-9]*/ig, "");
if (temp_table_datum_text) {
num_revisions = temp_table_datum_text;
}
}
if (num_revisions == 1) { // should never happen, but...
revisions = "The newer version is separated from the older version by one revision.";
} else {
revisions = "The newer version is separated from the older version by " + num_revisions + " revisions.";
}
} // closes check that the first child node is a text node
} else if (temp_table_datum.className == "diff-context") {
num_diff_context_lines++;
Line 272 ⟶ 407:
temp_added_line = temp_added_line.replace(/ /ig, " ");
temp_added_line = temp_added_line.replace(/ /ig, " ");
temp_added_line = temp_added_line.replace(/\'\'\'/ig, "");
temp_added_line = temp_added_line.replace(/\'\'/ig, "");
temp_added_line = temp_added_line.replace(/\s+/ig, " ");
} else { temp_added_line = ""; }
if (temp_added_line.replace(/\s/ig, "").length < 1) { num_diff_addedlines = 0; continue; }
added_span_nodes = temp_table_datum.getElementsByTagName("SPAN");
if (!added_span_nodes) { num_added_spans = 0; continue; }
Line 311 ⟶ 449:
temp_deleted_line = temp_deleted_line.replace(/ /ig, " ");
temp_deleted_line = temp_deleted_line.replace(/ /ig, " ");
temp_deleted_line = temp_deleted_line.replace(/\'\'\'/ig, "");
temp_deleted_line = temp_deleted_line.replace(/\'\'/ig, "");
temp_deleted_line = temp_deleted_line.replace(/\s+/ig, " ");
} else { temp_deleted_line = ""; }
if (temp_deleted_line.replace(/\s/ig, "").length < 1) { num_diff_deletedlines = 0; continue; }
deleted_span_nodes = temp_table_datum.getElementsByTagName("SPAN");
if (!deleted_span_nodes) { num_deleted_spans = 0; continue; }
Line 338 ⟶ 479:
} // closes loop over the data within a table row
if ((num_diff_addedlines > 0) && (temp_added_line) && (num_diff_deletedlines > 0) && (temp_deleted_line)) {
current_new_line_number++;
current_old_line_number++;
Line 391 ⟶ 532:
current_old_line_number++;
} // closes classification change as addition, deletion or replacement
} // closes loop over the table rows
Line 415 ⟶ 553:
if (num_additions>0) {
if (num_additions == num_changes) {
alert_string += ".\n\n"
} else if ((num_deletions == 0) || (num_replacements == 0)) {
alert_string += " and ";
Line 436 ⟶ 574:
if (num_replacements == 1) {
alert_string += "one replacement.\n\n";
} else if (
alert_string += num_replacements + " replacements.\n\n";
}
Line 455 ⟶ 593:
addOnloadHook(function () {
mw.util.addPortletLink('p-cactions', 'javascript:quickDiffs()', 'qd', 'ca-
});
|