לדלג לתוכן

משתמש:איסתרק/עדכון מקטגוריה.js

מתוך המכלול, האנציקלופדיה היהודית

לתשומת ליבך: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
if (mw.config.get("wgUserId") === 6136){
var buttonInsert = ('<button onclick ="appendBottons();">הצג כפתורי עדכון</button>'); 
$('#bodyContent').prepend(buttonInsert);

function appendBottons(){
const setOf = '<div><span>'+
    '<input type="checkbox" id="shemesh" name="shemesh">' +
    '<label for="shemesh"> בוט ייבוא</label></span>' +
    '<span><select id="selectbut" disabled>' +
    '<option value="">בחר</option>' +
    '<option value="ספורט">ספורט</option>' +
    '<option value="תרבות ובידור">תרבות ובידור</option>' +
    '<option value="ספרות">ספרות</option>' +
    '<option value="סרטים">סרטים</option>' + '<option value="שחקנים">שחקנים</option>' +
    '<option value="מוזיקאים">מוזיקאים</option>' +
    '<option value="סופרים">סופרים</option>' +
    '<option value="מוזיקה">מוזיקה</option>' +
    '<option value="טלוויזיה">טלוויזיה</option>' +'<option value="קולנוע">קולנוע</option>' +
   +'<option value="אלבומים">אלבומים</option>' +
    +'<option value="משחקי מחשב">משחקי מחשב</option>' 
+ "</select></div>";
$('#bodyContent').append(setOf);
    const but = 
document.getElementById("shemesh");
const selecto = document.getElementById("selectbut");
    const eventListen1 = () => {
      
      selecto.disabled = false;
      
    };

    but.addEventListener("click", eventListen1);

var hadCat = $("#firstHeading").text();
$('#mw-pages').find('li').each(function() {
var nameSen  = this.childNodes[0].title;
var nameS = nameSen.replace(/_/g, " ").replace(/^רבי\s/, "").replace(/^הרב\s/, "").replace(/ה\"קדושה\"/g, 'הקדושה').replace(/ה\"קדוש\"/g, 'הקדוש').replace(/ה\"קדושים\"/g, 'הקדושים').replace(/אישיות_מהתנ\"ך/g, 'דמות מקראית' );
$(this)
		.append(' (')
			.append(
			$('<a>')
			.text('עדכון')
			.click(function() {

var pointA = 'https://he.wikipedia.org/w/api.php?';
var dataWik= {
action:'parse',
page:nameSen,
format:'json',
prop:'revid|properties|wikitext',
utf8:'1',
origin:'*'
};
var request = $.ajax({
url:pointA,
data:dataWik,
dataType:"json"
})
    .done(function (result) {
if(result && result.parse){
var isShort = document.getElementById("shemesh").checked === true;
          var select = document.getElementById("selectbut").value;
          var textpage = isShort
            ? getPageText(result.parse.wikitext["*"])
            : result.parse.wikitext["*"];
          var girsa = result.parse.revid;
          var parit = getProperties(result);
          var summary =  "עדכון מוויקיפדיה גרסה " + girsa;
          var added = "";
          if (isShort) summary +=  ', בוט ' + select;
          
          var rating = [
            "מיון ויקיפדיה",
            "דף=" + result.parse.title,
            "גרסה=" + girsa,
            "פריט=" + parit,
          ];
          if (isShort) {
            var ni = "\n{{בוט " + select + "}}\n";
          } else {
            var ni =
               "\n{{וח}}\n";
          }
          added = ni + "{{" + rating.join("|") + "}}";

textpage =  textpage + added;

 var $form = $("<form>");

		var actionUrl = "https://www.hamichlol.org.il/w/index.php?title=" + encodeURIComponent(nameS) + "&action=submit";

		$form
			.attr("target",  "_blank")
			.attr("action", actionUrl)
			.attr("enctype", "multipart/form-data")
			.attr("method", "post"); 
var params = [];
		params.push(["wpTextbox1", textpage]);
		if (isShort) { params.push(["wpSummary", "עדכון מוויקיפדיה גרסה" + " " + girsa +', בוט '+ select]);
	} else {
	params.push(["wpSummary", "עדכון מוויקיפדיה גרסה" + " " + girsa ]);
}
		params.push(["wpAntispam", ""]);

		params.push(["wpSection", ""]);
		params.push(["wpStarttime", ""]);
		params.push(["wpEdittime", ""]);
		params.push(["editRevId", ""]);
		params.push(["wpScrolltop", "0"]);
		params.push(["oldid", "0"]);
		params.push(["parentRevId", "0"]);
		params.push(["format", "text/x-wiki"]);
		params.push(["model", "wikitext"]);
		params.push(["mode", "preview"]);
		params.push(["wpUltimateParam", "1"]);
	if(hadCat.indexOf('לטיפול')>-1){	params.push(["wpPreview", "תצוגה מקדימה"]);
 }else{
params.push(["wpDiff", "הצגת שינויים"]);
}
		params.forEach(item => {
			$("<input>").attr("type", "hidden").attr("name", item[0]).val(item[1]).appendTo($form);
		});
 		$form.appendTo($('body'));
 		$form.submit();
}else if(result && result.error&& result.error.code =='missingtitle'){
mw.notify('לא קיים')
}else{ 
mw.notify(result.error.code)
}
}).fail(function (request, exception) {
        // Our error logic here
        var msg = '';
        if (request.status === 0) {
            msg = 'Not connect.\n Verify Network.';
        } else if (request.status == 404) {
            msg = 'Requested page not found. [404]';
        } else if (request.status == 418) {
            msg = 'הייבוא או העדכון נחסם על ידי ספק הרשת';
        } else if (request.status == 500) {
            msg = 'Internal Server Error [500].';
        } else if (exception === 'parsererror') {
            msg = 'Requested JSON parse failed.';
        } else if (exception === 'timeout') {
            msg = 'Time out error.';
        } else if (exception === 'abort') {
            msg = 'Ajax request aborted.';
        } else {
            msg = 'Uncaught Error.\n' + request.responseText;
        }
        mw.notify(msg);
    });
})
).append(')')
})
}
function getProperties(result){
var parit = " ";
        if (!result.parse.properties[0]){
        	parit= " ";
        }else if(result.parse.properties[0]["name"] == "wikibase_item"){
        	parit= result.parse.properties[0]["*"];
        }else if(result.parse.properties[0]["name"] != "wikibase_item" && result.parse.properties.length <= 1){
        	parit= " ";
        }else if(result.parse.properties[0]["name"] != "wikibase_item" && result.parse.properties.length > 1){
        	for(let pa = 0; pa < result.parse.properties.length; pa++){
        		if (result.parse.properties[pa]["name"] == "wikibase_item"){
        			parit= result.parse.properties[pa]["*"];
        		}else continue;
        	}
        }
return parit;
}
function getPageText(member) {
    var wikiList = [];
    var textList;
    var regex1 = /==.*==/g;
    var regex2 = /\n\n/;
    var regex3 = /\[\[קטגוריה\:[^\]]*?\]\]/g;
    var categoriesToAdd;
    var newText;
    var first;
    var last = 0;
    let parsedText = member;
    textList = parsedText.split(regex1);

    if (textList.length < 3) {
      textList = parsedText.split(regex2);

      first = textList[0];
      
      last = textList.length - 1;
      categoriesToAdd = textList[last].match(regex3);
      newText = first + "\n\n" + categoriesToAdd.join("\n");
    } else {
      first = textList[0];
      
      last = textList.length - 1;
      categoriesToAdd = textList[last].match(regex3);
      newText = first + "\n\n" + categoriesToAdd.join("\n");
    }

    return newText;
  }
}