انتقل إلى المحتوى

مستخدم:ASammour/conflict-revisions.js

من ويكيبيديا، الموسوعة الحرة

ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.

$("#pagehistory>li>.flaggedrevs-pending").each(function (){
  $(this).append("<span rev-id = " +$(this).parent().attr("data-mw-revid")+ " style = 'font-family:calibri;'><a class = 'approve-rev-id' href = '#' style = 'color:green;font-weight:900;'> قبول </a> أو <a href = '#' class = 'unapprove-rev-id' style = 'color:red;font-weight:900;'> رفض </a> </span> ");
});


if ($("#firstHeading").text().includes ("الفرق بين النسختين") && $(".fr-diff-ratings>tbody>tr>td:nth-child(2)").text() == "[نسخة معلقة]"){
  $("#mw-diff-ntitle1").append("<span rev-id = " +$("#mw-diff-ntitle1>strong>a").attr("href").split("&oldid=")[1]+ " style = 'font-family:calibri;'><a class = 'approve-rev-id' href = '#' style = 'color:green;font-weight:900;'> قبول </a> أو <a href = '#' class = 'unapprove-rev-id' style = 'color:red;font-weight:900;'> رفض </a> </span> ");
}

$("head").append(`<style>
  .loading {
      position: fixed;
      top: 0; right: 0;
      bottom: 0; left: 0;
      background: #54545469;
  }
  .loader {
      left: 50%;
      margin-left: -4em;
      font-size: 10px;
      border: .8em solid rgba(218, 219, 223, 1);
      border-left: .8em solid rgba(58, 166, 165, 1);
      animation: spin 1.1s infinite linear;
  }
  .loader, .loader:after {
      border-radius: 50%;
      width: 8em;
      height: 8em;
      display: block;
      position: absolute;
      top: 50%;
      margin-top: -4.05em;
  }

  @keyframes spin {
    0% {
      transform: rotate(360deg);
    }
    100% {
      transform: rotate(0deg);
    }
  }
</style>`);

$("body").append (`<div class="loading" style = "display:none;"><div class="loader"></div></div>`);

$(".approve-rev-id").click (function (){
      //Get Rev ID
      var revId = $(this).parent().attr("rev-id");


      var myApi = new mw.Api();

      var token = "";
      $(".loading").show();

      //Get Token
      new mw.Api().get({
    	"action": "query",
    	"format": "json",
    	"meta": "tokens",
    	"type": "csrf"
      }).then(function(ret) {
          token =  ret.query.tokens.csrftoken;

          //Trigger the Approve for that Rev ID
          new mw.Api().post({
            	"action": "review",
            	"format": "json",
            	"revid": revId,
            	"comment": "Ok",
            	"flag_accuracy": "1",
            	"token": token
          }).then(function(ret1) {
              $(".loading").hide();
              //Check if the process done successfully
              if (ret1.review.result == "Success"){
                alert("تم قبول المراجعة بنجاح!");

                //Refresh the page
                location.reload();
              }
          }, function ( code, data ) {
              $(".loading").hide();
              alert("حصل خطأ أثناء عملية المراجعة!، يرجى المحاولة لاحقا");

              //Refresh the page
              location.reload();
          });
    });
});



$(".unapprove-rev-id").click (function (){
      //Get Rev ID
      var revId = $(this).parent().attr("rev-id");

      var token = "";

      $(".loading").show();

      //Get Token
      new mw.Api().get({
    	"action": "query",
    	"format": "json",
    	"meta": "tokens",
    	"type": "csrf"
      }).then(function(ret2) {
          token =  ret2.query.tokens.csrftoken;

          //Trigger the Approve for that Rev ID
          new mw.Api().post({
          	"action": "edit",
          	"format": "json",
          	"title": mw.config.get('wgPageName') ,
          	"undo": revId,
          	"token": token
          }).then(function(ret3) {
              $(".loading").hide();
              //Check if the process done successfully
              if (ret3.edit.result == "Success"){
                alert("تم رفض المراجعة بنجاح");

                //Refresh the page
                location.reload();
              }
          }, function ( code, data ) {
              $(".loading").hide();
              alert("حصل خطأ أثناء عملية المراجعة!، يرجى المحاولة لاحقا");

              //Refresh the page
              location.reload();
          });
    });
});