Jump to content

User:SiBr4/DiffApostrophes.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*

This script adds 0.1em of padding around apostrophes ('') in
diffs, to ease distinguishing them from quotation marks ("). See
[[Wikipedia:Village pump (technical)/Archive 139#Is there a better way to illustrate a " --> '' change in the diff view?]].

Install by adding the following row to your [[Special:MyPage/common.js]] or [[Special:MyPage/skin.js]]:

importScript('User:SiBr4/DiffApostrophes.js');

*/

function repapos(elem) {
  elem.innerHTML = elem.innerHTML.replace(/(?<!<[^>]+)\'/g,"<span style=\"padding:0 0.1em;\">'</span>");
}
var diff = document.getElementsByClassName("diff")[0];
if (diff) {
  var del = diff.getElementsByClassName("diff-deletedline");
  for (i=0; i<Math.min(del.length,50); i++) {repapos(del[i]);}
  var add = diff.getElementsByClassName("diff-addedline");
  for (i=0; i<Math.min(add.length,50); i++) {repapos(add[i]);}
  var ctx = diff.getElementsByClassName("diff-context");
  for (i=0; i<Math.min(ctx.length,50); i++) {repapos(ctx[i]);}
}