Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 

















User:Writ Keeper/Scripts/commonHistory.js

















User page
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
User contributions
User logs
View user groups
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

< User:Writ Keeper | Scripts

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.
if (typeof inspectText == "undefined")
{
 inspectText = "inspect&nbsp;diff";
}
if (typeof showText == "undefined")
{
 showText = "show&nbsp;diff";
}
if (typeof hideText == "undefined")
{
 hideText = "hide&nbsp;diff";
}
var specialPageName = mw.config.get("wgCanonicalSpecialPageName");
if (specialPageName  == "Watchlist" ||
 specialPageName  == "Recentchanges" ||
 specialPageName  == "Contributions" ||
 mw.config.get("wgAction") == "history" || 
 specialPageName == "Recentchangeslinked" ||
 (specialPageName == "Blankpage" && mw.config.get("wgTitle").indexOf("section-watchlist") > 0))
{
 function inspectionEachHelper(index, element)
 {
  var findString;
  if (mw.config.get("wgAction") == "history" || $(element).hasClass("mw-enhanced-rc-nested"))
  {
   findString = 'a:contains("prev")';
  }
  else
  {
   findString = 'a:contains("diff")';
  }

  var regex;

  if (specialPageName == "Contributions")
  {
   regex = /&oldid=(\d+)$/;

  }
  else
  {
   regex = /(?:&diff=(\d+)&oldid=|&diff=prev&oldid=(\d+))/;
  }
  var diffLink = $(element).find(findString);
  if (diffLink.length > 0)
  {
   var regexResult = regex.exec(diffLink[0].href);
   if (regexResult != null && regexResult.length >= 2)
   {
    var diffID = regexResult[1] || regexResult[2];
    //don't re-add if it already exists
    if ($("#" + diffID).length > 0)
    {
     return;
    }
    var inlineDiffButton;
    if (typeof inlineDiffBigUI === "undefined")
    {
     inlineDiffButton = document.createElement("a");
     inlineDiffButton.href = "#";
     inlineDiffButton.innerHTML = '<b><span style="color:black;"> [</span><span style="color:#008A00;">' + inspectText + '</span><span style="color:black;">] </span></b>';
    }
    else
    {
     inlineDiffButton = document.createElement("input");
     inlineDiffButton.type = "button";
     inlineDiffButton.value = "Inspect edit";
    }
    inlineDiffButton.id = diffID;
    $(inlineDiffButton).addClass("inspectDiffButton");
    $(inlineDiffButton).click(function ()
    {
     return inspectWatchlistDiff(this);
    }
    );
    if ($(element).find("tr:first").length == 0)
    {
     $(element).find(".mw-changeslist-separator:first").css("padding-right", 0);
     $(inlineDiffButton).insertAfter($(element).find(".mw-changeslist-separator:first"));
    }
    else
    {
     $(inlineDiffButton).insertBefore($(element).find(".mw-title"));
     $(inlineDiffButton).addClass("mw-enhanced-rc-diff");
     /*
     $(element).find("tr:first").append("<td></td>");
     $(element).find("tr:first>td:last").append(inlineDiffButton);
     */
    }
   }
  }
 }
 function addWatchlistInspectionBoxes()
 {
  mw.loader.using("mediawiki.diff.styles").done(function()
  {
   var entries = $("#mw-content-text table.mw-enhanced-rc");
   if (entries.length == 0)
   {
    $("#mw-content-text ul").each(function (ind, el)
    {
     $(el).children("li").each(inspectionEachHelper);
    });
   }
   else
   {
    entries.each(inspectionEachHelper);
    $("td.mw-enhanced-rc-nested").each(inspectionEachHelper);
   }
  });
 }

 function inspectWatchlistDiff(button)
 {
  mw.loader.using(['mediawiki.api']).done(function ()
  {
   var mwApi = new mw.Api();
   mwApi.get(
   {
    action: "query",
    prop: "revisions",
    format: "json",
    rvprop: "timestamp",
    rvdiffto: "prev",
    revids: button.id
   }
   ).done(function (response)
   {
    if (response == null)
    {
     alert("Request failed!");
     return false;
    }

    var diffString = response.query.pages[Object.keys(response.query.pages)[0]].revisions[0].diff["*"];

    if (diffString == null)
    {
     alert("Request failed!");
     return false;
    }

    var newTable = document.createElement("table");
    newTable.className = "diff";
    $(newTable).html('<colgroup><col class="diff-marker"><col class="diff-content"><col class="diff-marker"><col class="diff-content"></colgroup>');

    $(newTable).append(diffString);
    diffParent = null;
    if ($("#" + button.id).hasClass("mw-enhanced-rc-diff"))
    {
     $("#" + button.id).parents("table").after(newTable);
    }
    else
    {
     diffParent = $("#" + button.id).parent();
     diffParent.append(newTable);
    }
    newTable.id = button.id + "display";

    mw.hook('new-diff-table').fire(newTable);

    $(button).unbind("click");
    if (typeof inlineDiffBigUI === "undefined")
    {
     $(button).html('<b><span style="color:black;"> [</span><span style="color:#008A00;">' + hideText + '</span><span style="color:black;">] </span></b>');
     $(button).click(function ()
     {
      return hideSmallEditInspection(this);
     }
     );
    }
    else
    {
     $(button).attr("value", "Hide edit");
     $(button).click(function ()
     {
      return hideEditInspection(this);
     }
     );
    }
    if (typeof markAsViewed != "undefined" && markAsViewed)
    {
     mwApi.postWithToken('csrf',
     {
      action: "setnotificationtimestamp",
      revids: button.id
     }
     ).done(function (data)
     {
      if (diffParent != null)
      {
       diffParent.removeClass("mw-changeslist-line-watched");
       diffParent.addClass("mw-changeslist-line-not-watched");
      }
     }
     );
    }
   }
   );
  }
  );
  return false;
 }

 function showEditInspection(button)
 {
  $("#" + button.id + "display").css("display", "");
  $(button).attr("value", "Hide edit");
  $(button).unbind("click");
  $(button).click(function ()
  {
   return hideEditInspection(this);
  }
  );
  return false;
 }

 function hideEditInspection(button)
 {
  $("#" + button.id + "display").css("display", "none");
  $(button).attr("value", "Show edit");
  $(button).unbind("click");
  $(button).click(function ()
  {
   return showEditInspection(this);
  }
  );
  return false;
 }

 function showSmallEditInspection(button)
 {
  $("#" + button.id + "display").css("display", "");
  $(button).html('<b><span style="color:black;"> [</span><span style="color:#008A00;">' + hideText + '</span><span style="color:black;">] </span></b>');
  $(button).unbind("click");
  $(button).click(function ()
  {
   return hideSmallEditInspection(this);
  }
  );
  return false;
 }

 function hideSmallEditInspection(button)
 {
  $("#" + button.id + "display").css("display", "none");
  $(button).html('<b><span style="color:black;"> [</span><span style="color:#008A00;">' + showText + '</span><span style="color:black;">] </span></b>');
  $(button).unbind("click");
  $(button).click(function ()
  {
   return showSmallEditInspection(this);
  }
  );
  return false;
 }

 mw.hook('wikipage.content').add(addWatchlistInspectionBoxes);
}

Retrieved from "https://en.wikipedia.org/w/index.php?title=User:Writ_Keeper/Scripts/commonHistory.js&oldid=981877063"





This page was last edited on 4 October 2020, at 23:08 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki