Nowadays, Wikipedia:WikiProject User scripts/Scripts/Single column diffs is a topic that has gained great relevance in society. Since its emergence, it has aroused the interest of specialists, academics and the general public due to its impact on different areas of daily life. Its influence has spread globally, generating debates, reflections and actions that seek to understand its scope and consequences. In this article, we will explore Wikipedia:WikiProject User scripts/Scripts/Single column diffs in depth, examining its origins, evolution, and the implications it represents today. Through detailed analysis, we will seek to shed light on this topic and offer a critical perspective that allows our readers to understand its importance and its relationship with the world around us.
//
// By User:Pile0nades.
// Makes the diff page display as a single column, instead of two.
addOnloadHook(function(){
// ==UserScript==
// @name Wikipedia single column diffs
// @namespace http://mywebsite.com/myscripts
// @description Make Wikipedia diff pages read like patch-format diffs, only one column needed
// @include http://en.wikipedia.org/w/index.php?*&diff=*
// ==/UserScript==
// remove the header for the previous revision, and add the next/prev links to the second header
var prevHeader = get("//table/tbody/tr/td");
var nextHeader = get("//table/tbody/tr/td");
var oldedit = get("//table/tbody/tr/td/a");
var newedit = get("//table/tbody/tr/td/a");
for(var i = 0; i < prevHeader.snapshotLength; i++) {
if(oldedit.snapshotLength != 0) {
nextHeader.snapshotItem(i).appendChild(oldedit.snapshotItem(0));
}
if(oldedit.snapshotLength != 0 && newedit.snapshotLength != 0) {
nextHeader.snapshotItem(i).appendChild(document.createTextNode(" | "));
}
if(newedit.snapshotLength != 0) {
nextHeader.snapshotItem(i).appendChild(newedit.snapshotItem(0));
}
remove(prevHeader.snapshotItem(i));
}
// clone rows where the line changed but wasn't added/deleted, and delete where appropriate
var changedLines = get("//table/tbody/tr/td/../td")
for(var i = 0; i < changedLines.snapshotLength; i++) {
var cell = changedLines.snapshotItem(i);
cell.parentNode.parentNode.insertBefore(
cell.parentNode.cloneNode(true),
cell.parentNode
);
remove(cell.previousSibling.previousSibling);
remove(cell);
}
// delete blank cells in the first column to move the added lines into the first column
var blankcells = get("//table/tbody/tr/td");
for(var i = 0; i < blankcells.snapshotLength; i++) {
if(blankcells.snapshotItem(i).innerHTML == " ") {
remove(blankcells.snapshotItem(i));
}
}
// delete everything past the second td in each column
var waste = get("//table/tbody/tr/td");
for(var i = 0; i < waste.snapshotLength; i++) {
while(waste.snapshotItem(i).nextSibling) {
remove(waste.snapshotItem(i).nextSibling);
}
}
// delete the 2nd line number cell in each column
var line = get("//table/tbody/tr/td");
for(var i = 0; i < line.snapshotLength; i++) {
remove(line.snapshotItem(i));
}
// delete the extra cols
var cols = get("//table/col");
for(var i = 0; i < cols.snapshotLength; i++) {
var col = cols.snapshotItem(i);
if(col.className == "diff-content") {
col.style.width = "98%";
col.removeAttribute("class");
}
if(i > 1) remove(col);
}
// shorthand function to remove nodes
function remove(node) {
node.parentNode.removeChild(node);
}
// xpath function
function get(query) {
return document.evaluate(
query,
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
);
}
});
//