משתמש:Alonzimmer/dfgdfg.js

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

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
(function() {
	
    var link;
    //mw.storage.set('name', 'alon');
    var name = mw.storage.get('name');
    console.log(name);
    var user = document.getElementById('pt-userpage-2');
    var userName = user.children[0].text;
	var isUse = localStorage.getItem(userName + ':' + 'use');
	if(isUse == 0 || isUse == null)
	{
		link = mw.util.addPortletLink('p-tb', '#', 'מעקב למידה - הוספה');
	}
	if(isUse == 1)
	{
		link = mw.util.addPortletLink('p-tb', '#', 'מעקב למידה - הסרה');
		add();
	}
    if(!link) 
    {
        console.log('link error!');
        return;
    }
    var span = link.children[0].children[0];
    span.style.fontSize = "16px";
    span.style.color = "red";
    link.onclick = function(event) {
        //event.preventDefault();
        if(localStorage.getItem(userName + ':' + 'use') == 1)
        {
        	span.textContent = 'מעקב למידה - הוספה';
        	localStorage.setItem(userName + ':' + 'use', 0);
        	remove();
        }
        else
        {
        	span.textContent = 'מעקב למידה - הסרה';
        	localStorage.setItem(userName + ':' + 'use', 1);
        	add();
        }
    };

    function add() {
        var title = $('.firstHeading').text();
        
        /*mw.loader.using( [ 'mw.Api' ], function() {
    		var api = new mw.Api();
		});
        
    	var cats = api.isCategory(title);
    	console.log(cats);*/
        
        var isCategory = title.includes('קטגוריה:');
        if (title == null || (!isCategory && title.includes(':')) || title == 'עמוד ראשי')
        {
            return;
        }
        var user = document.getElementById('pt-userpage-2');
        var userName = user.children[0].text;
/****************************************************************************************************************
/////////////////////////////////////// Category - Page /////////////////////////////////////////////////////////
*****************************************************************************************************************/
        if(isCategory) 
        {
            var clicked = document.getElementById('firstHeading').children;
            if (clicked.length == 1) 
            {
                return;
            }
            title = title.replace('קטגוריה:', '');
            var pages = localStorage.getItem(userName + ':' + title);
            var counter = 0;
            if (pages != null)
            {
                $('#mw-pages').find('li').each(function() {
                    counter++;
                    var a = this.children;
                    var t = a[0].text;
                    //////////////////// if the page sign as done add checked icon next to him ///////////////////
                    if ((pages.includes(t) && !pages.includes('#')) && pages.length == t.length || pages.includes('#' + t) || pages.includes(t + '#'))
                    {
                        //$(this).css({'color':'green', "fontSize":30}).prepend('\u2713');
                        $(this).prepend('<img class="green-v" alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/f/fb/Yes_check.svg/18px-Yes_check.svg.png" decoding="async" width="18" height="18" srcset="//upload.wikimedia.org/wikipedia/en/thumb/f/fb/Yes_check.svg/27px-Yes_check.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/f/fb/Yes_check.svg/36px-Yes_check.svg.png 2x" data-file-width="600" data-file-height="600">');
                    }
                });
            }
			var sub_cat_counter = 0;
			var sub_cat_progress = 0;
            $('#mw-subcategories').find('.CategoryTreeItem').each(function () {
                var a = this.children;
                var arr = a[2].textContent.split(' ');
                var sub_cat_pages;
                //////////////////// get the number of pages in sub-category /////////////////////////////////
                if(arr.length == 4) 
                {
                    sub_cat_pages = parseInt(arr[2]);
                }
                else 
                {
                	if(a[2].textContent.includes('קט'))
                	{
                		sub_cat_pages = 0;
                	}
                	else
                	{
                		sub_cat_pages = parseInt(arr[0].replace('(', ''));
                	}
                }
                if(isNaN(sub_cat_pages))
                {
                    sub_cat_pages = 1;
                }
                sub_cat_counter += sub_cat_pages;
                var t = a[1].text;
                const sub_cat = localStorage.getItem(userName + ':' + t);
                if(sub_cat != null) 
                {
                    var page_arr = sub_cat.split(",");
                    var done_pages = page_arr.length;
                    sub_cat_progress += done_pages;
                    var per = (done_pages / sub_cat_pages) * 100;
                    //////////////////// add small progress bar next to sub-category //////////////////////////////
                    $(this).find('a')
                    .append('<div class="sub-progress" style="font-size: 60%; position:relative; border: 1px solid #000; background-color: #fff; width: 100px; max-width: 100%; height: 10px;"><div style="position: absolute; background-color:#00ff00; width: ' + per + '%; height: 10px;"></div><div style="position: absolute; font-weight: high; width:100%; height: 10px; text-align: center; color: #000;">' + per.toFixed(2) + '%</div></div>');
                }
            });
            //////////////////// progress of the current category /////////////////////////
            if(pages == null && sub_cat_progress == 0)/////no progress
            {
                $('.mw-body-header').append('<div class="main-progress" style="height=8; width:60%; margin:2px; text-align:center;"><p><span style="font-size: 100%;"><b>0%</b></span></p><p style="border:1px solid #c8ccd1; padding:1px; overflow:hidden;"><span style="width: 0%; height: 12px; background:#00af32; float:right;">&nbsp;</span><span style="width: 100%; height: 12px; background:#eaecf0; float:left;">&nbsp;</span></p></div>');
            }
            else if(pages == null)
            {
                var per = (sub_cat_progress / (counter + sub_cat_counter)) * 100;
                //// $('.firstHeading')
                $('.mw-body-header').append('<div class="main-progress" style="height=8; width:60%; margin:2px; text-align:center;"><p><span style="font-size: 100%;"><b>' + '(' + per.toFixed(2) + '%) ' + 'נקראו ' + sub_cat_progress + ' דפים מתוך ' + (counter + sub_cat_counter) + '</b></span></p><p style="border:1px solid #c8ccd1; padding:1px; overflow:hidden;"><span style="width: ' + (per) + '%; height: 12px; background:#00af32; float:right;">&nbsp;</span><span style="width: ' + (100 - per) + '%; height: 12px; background:#eaecf0; float:right;">&nbsp;</span></p></div>');
            }
            else 
            {
                page_arr = pages.split("#");
                done_pages = page_arr.length;
                var per = ((done_pages + sub_cat_progress) / (counter + sub_cat_counter)) * 100;
                //// $('.firstHeading')
                $('.mw-body-header').append('<div class="main-progress" style="height=8; width:60%; margin:2px; text-align:center;"><p><span style="font-size: 100%;"><b>' + '(' + per.toFixed(2) + '%) ' + 'נקראו ' + (done_pages + sub_cat_progress) + ' דפים מתוך ' + (counter + sub_cat_counter) + '</b></span></p><p style="border:1px solid #c8ccd1; padding:1px; overflow:hidden;"><span style="width: ' + (per) + '%; height: 12px; background:#00af32; float:right;">&nbsp;</span><span style="width: ' + (100 - per) + '%; height: 12px; background:#eaecf0; float:right;">&nbsp;</span></p></div>');
            }
        }
/****************************************************************************************************************
/////////////////////////////////////// Normal - Page ///////////////////////////////////////////////////////////
*****************************************************************************************************************/
        else 
        {
            var cat = document.getElementById('mw-normal-catlinks').children;
            var firstCat = cat[1].firstChild.textContent;
            firstCat = userName + ':' + firstCat;
            var pages = localStorage.getItem(firstCat);
            if(pages != null)
            {
                var exist = pages.includes(title);
                if (exist && !pages.includes('#') && title.length == pages.length || pages.includes('#' + title) || pages.includes(title + '#')) 
                {
                    //$('.mw-parser-output')
                    $('.mw-body-header')
    				.append('<label id="label-done"><input id="checkBox" name="done" value="myValue" type="checkbox">קראתי </label>');
                    $("#checkBox").prop("checked", true);
                }
                else 
                {
                    //$('.mw-parser-output')
                    $('.mw-body-header')
    				.append('<label id="label-done"><input id="checkBox" name="done" value="myValue" type="checkbox">קראתי </label>');
                }
            }
            else 
            {
                //$('.mw-parser-output')
                $('.mw-body-header')
    			.append('<label id="label-done"><input id="checkBox" name="done" value="myValue" type="checkbox">קראתי </label>');
            }
        }
/****************************************************************************************************************
/////////////////////////////////////// CheckBox - Click ////////////////////////////////////////////////////////
*****************************************************************************************************************/
        $(document).ready(function() {
            $("#checkBox").click(function() {
                var cat = document.getElementById('mw-normal-catlinks').children;
                const catNames = cat[1];
                var children = catNames.children;
                if($("#checkBox").is(':checked')) //////// sign as 'done' /////////
                {
                    for(var i = 0 ; i < children.length ; i++)
                    {
                        var child = children[i];
                        var name = child.textContent;
                        name = userName + ':' + name;
                        var pages = localStorage.getItem(name);
                        if(pages == null)
                        {
                            localStorage.setItem(name, title);
                        }
                        else 
                        {
                            if(!pages.includes('#' + title) && pages.localeCompare(title) != 0 && !pages.includes(title + '#'))
                            {
                                pages = pages.concat('#', title);
                                localStorage.setItem(name, pages);
                            }
                        }
                    }
                }
                else ////////sign as 'undone' //////////
                {
                    for(var j = 0; j < children.length; j++) {
                        var child = children[j];
                        var name = child.textContent;
                        name = userName + ':' + name;
                        var pages = localStorage.getItem(name);
                        var many_pages = pages.includes(",");
                        if(many_pages) 
                        {
                            pages = pages.replace('#' + title, '');
                            pages = pages.replace(title + '#', '');
                            localStorage.setItem(name, pages);
                        }
                        else 
                        {
                            localStorage.removeItem(name);
                        }
                    }
                }
                //location.reload();
            });
        });
    }
/****************************************************************************************************************
/////////////////////////////////////// REMOVE ////////////////////////////////////////////////////////
*****************************************************************************************************************/
    function remove(){
    	var title = $('.firstHeading').text();
        var isCategory = title.includes('קטגוריה:');
        if (title == null || (!isCategory && title.includes(':')) || title == 'עמוד ראשי')
        {
            return;
        }
        if(isCategory)
        {
        	$('.main-progress').remove();
        	$('.sub-progress').remove();
        	$('.green-v').remove();
        }
        else
        {
        	$('#label-done').remove();
        }
    }
}());