<commit_before>(function($, can, chrome, window){
	"use strict";


	var backgroundPage = chrome.extension.getBackgroundPage(),
        popup = {
            refreshTime:3000,// how often to check the background page for changes
            checkingCounter:0,
			changed: true,
            items:[],
			authorItems:[],
			snoozeItem: function(e){
				var id = $(e.target).closest("[data-id]").attr("data-id");
				if (id && backgroundPage.kmj.snoozedItems.indexOf(parseInt(id)) === -1){
					$(e.target).closest("[data-id]").addClass("item--snoozed");
					document.querySelector("[data-id='"+id+"']").removeAttribute("open");
					backgroundPage.kmj.addSnoozed(id);
				} else if (id){
					$(e.target).closest("[data-id]").removeClass("item--snoozed");
					backgroundPage.kmj.addSnoozed(id, true);
				}
				return false;
			},
            isLastPage: backgroundPage.kmj.json.isLastPage,
            dateFormat: backgroundPage.kmj.getLocalStore("PopupDateformat"),
			showAuthored: backgroundPage.kmj.getLocalStore("AuthorTabEnabled","true","boolean"),
            messages:{
                noIssues:"You have 0 reviews queued.<br/>",
				noIssuesMessage:"",
                unknown:'Either you are not <a class="login" href="#">logged in</a>, or the connection failed for some reason :(',
                noConf:'Please check the <a href="options.html">configuration page</a>.',
				setNoIssuesMessage: function(){
					var niceThings = ["Nothing to review, take the rest of the day off!","Time to catch up on some paperwork?","Time for a well earned tea!","Time for a quick power nap!","Time to pop to the gym!","Relax...."];
					popup.messages.noIssuesMessage = popup.messages.noIssues + niceThings[ Math.floor( Math.random() * niceThings.length) ];
				}
            },
            init:function() {
                var manifest = chrome.runtime.getManifest(),
                    url = backgroundPage.kmj.urlCleaner( backgroundPage.kmj.getLocalStore("URL") + backgroundPage.kmj.getLocalStore("PopupTitleLink","") ),
                    items = backgroundPage.kmj.items,
					authorItems = backgroundPage.kmj.authorItems ;
				popup.messages.setNoIssuesMessage();

                popup.items = new can.Observe.List( items );
				popup.authorItems = new can.Observe.List( authorItems );

                can.$("#template").html( backgroundPage.kmj.getLocalStore("PopupTemplate") );

                $("body")
                    .addClass('is-last-page-'+ popup.isLastPage)
	                .addClass('is-author-visible-'+ backgroundPage.kmj.getLocalStore("AuthorTabEnabled","true","string"))
                    .addClass('differentiate-approved-'+ backgroundPage.kmj.getLocalStore("DifferentiateApproved","true","string") )
                    .removeClass('loading');
                $(".h1").html( '<a href="'+ url +'">'+ backgroundPage.kmj.getLocalStore("PopupTitle") +'</a>' );

                $(".extensionLink")
					.text(manifest.name + ' ('+manifest.version+')')
					.attr("title", manifest.name + ' ('+manifest.version+')');

                popup.render();
            },
            render:function(){
                var url = backgroundPage.kmj.getLocalStore("URL"),
                    html,
                    template = can.view("#template", {stash: popup.items }, {date: function(val){
                        var d = new Date(val());
                        return  d.toString(popup.dateFormat)
                    }}),
					authorTemplate = can.view("#template", {stash: popup.authorItems }, {date: function(val){
                        var d = new Date(val());
                        return  d.toString(popup.dateFormat)
                    }});

                can.$(".display").append(template);
				can.$(".author__display").append(authorTemplate);
				$("body").attr("author-items-length", popup.authorItems.length);

				if (backgroundPage.kmj.connected === false){
					if (backgroundPage.kmj.getLocalStore("URL") === DEFAULT_VALUES["URL"]){
                        html = popup.messages.noConf;
                    } else {
                        html = popup.messages.unknown + "<br/>" + popup.messages.noConf;
                    }
					$('footer a.login').text("Login");
					$("body").addClass("logged-in-false").removeClass("logged-in-true");
                    $("p.message").html( html );
					return;
				} else {
					$('footer a.login').text("Stash");
					$("body").addClass("logged-in-true").removeClass("logged-in-false");
				}
                if (popup.items.length > 0 || (popup.showAuthored && popup.authorItems.length > 0) ) {
					// something to show
                    $("p.message").empty();
					console.log("1 popup.items.length > 0 || (popup.showAuthored && popup.authorItems.length > 0) true");
                }
				if (backgroundPage.kmj.items.length === 0){
					// connected but no main items
					$("p.message").html( popup.messages.noIssuesMessage );
					console.log("2 backgroundPage.kmj.items.length === 0 && backgroundPage.kmj.connected === true -- true");
                }
            },
            monitor:function(){
                // not used, just check for updates if the user clicks the refresh button.
				$("body").removeClass("loading");
				$("p.message").empty();
				if (popup.checking){
					clearTimeout(popup.checking);
				}
                if (backgroundPage.kmj.items.length !== popup.items.length){/* don't refresh unless something has been added or removed */
                    popup.changed = true;
					popup.items.replace(backgroundPage.kmj.items);
                }
                if (backgroundPage.kmj.items.length === 0){
					var html = (backgroundPage.kmj.connected) ? popup.messages.noIssuesMessage : popup.messages.unknown;
                    $("p.message").html( html );
                }
				popup.checking = window.setTimeout(function(){popup.monitor();}, popup.refreshTime);
            }
        };

    $(window).on('load', function(){
        popup.init();
        //var mon;
        $("#refresh").on('click',function(){
            popup.checkingCounter = 0;
            popup.items.replace( [] );
            popup.authorItems.replace( [] );
            $("body").addClass("loading");
            $("p.message").empty();
            backgroundPage.kmj.init(function(){ popup.init() });
            if (popup.checking){
                window.clearTimeout(popup.checking);
            }
        });
        $(document).on('click', 'a.login', function(e){<commit_msg>Update improve popup refresh<commit_after>(function($, can, chrome, window){
	"use strict";


	var backgroundPage = chrome.extension.getBackgroundPage(),
        popup = {
            refreshTime:3000,// how often to check the background page for changes
            checkingCounter:0,
			changed: true,
            items:[],
			authorItems:[],
			snoozeItem: function(e){
				var id = $(e.target).closest("[data-id]").attr("data-id");
				if (id && backgroundPage.kmj.snoozedItems.indexOf(parseInt(id)) === -1){
					$(e.target).closest("[data-id]").addClass("item--snoozed");
					document.querySelector("[data-id='"+id+"']").removeAttribute("open");
					backgroundPage.kmj.addSnoozed(id);
				} else if (id){
					$(e.target).closest("[data-id]").removeClass("item--snoozed");
					backgroundPage.kmj.addSnoozed(id, true);
				}
				return false;
			},
            isLastPage: backgroundPage.kmj.json.isLastPage,
            dateFormat: backgroundPage.kmj.getLocalStore("PopupDateformat"),
			showAuthored: backgroundPage.kmj.getLocalStore("AuthorTabEnabled","true","boolean"),
            messages:{
                noIssues:"You have 0 reviews queued.<br/>",
				noIssuesMessage:"",
                unknown:'Either you are not <a class="login" href="#">logged in</a>, or the connection failed for some reason :(',
                noConf:'Please check the <a href="options.html">configuration page</a>.',
				setNoIssuesMessage: function(){
					var niceThings = ["Nothing to review, take the rest of the day off!","Time to catch up on some paperwork?","Time for a well earned tea!","Time for a quick power nap!","Time to pop to the gym!","Relax...."];
					popup.messages.noIssuesMessage = popup.messages.noIssues + niceThings[ Math.floor( Math.random() * niceThings.length) ];
				}
            },
            init:function() {
                var manifest = chrome.runtime.getManifest(),
                    url = backgroundPage.kmj.urlCleaner( backgroundPage.kmj.getLocalStore("URL") + backgroundPage.kmj.getLocalStore("PopupTitleLink","") ),
                    items = backgroundPage.kmj.items,
					authorItems = backgroundPage.kmj.authorItems ;
				popup.messages.setNoIssuesMessage();

                popup.items = new can.Observe.List( items );
				popup.authorItems = new can.Observe.List( authorItems );

                can.$("#template").html( backgroundPage.kmj.getLocalStore("PopupTemplate") );

                $("body")
                    .addClass('is-last-page-'+ popup.isLastPage)
	                .addClass('is-author-visible-'+ backgroundPage.kmj.getLocalStore("AuthorTabEnabled","true","string"))
                    .addClass('differentiate-approved-'+ backgroundPage.kmj.getLocalStore("DifferentiateApproved","true","string") )
                    .removeClass('loading');
                $(".h1").html( '<a href="'+ url +'">'+ backgroundPage.kmj.getLocalStore("PopupTitle") +'</a>' );

                $(".extensionLink")
					.text(manifest.name + ' ('+manifest.version+')')
					.attr("title", manifest.name + ' ('+manifest.version+')');

                popup.render();
            },
            render:function(){
                var url = backgroundPage.kmj.getLocalStore("URL"),
                    html,
                    template = can.view("#template", {stash: popup.items }, {date: function(val){
                        var d = new Date(val());
                        return  d.toString(popup.dateFormat)
                    }}),
					authorTemplate = can.view("#template", {stash: popup.authorItems }, {date: function(val){
                        var d = new Date(val());
                        return  d.toString(popup.dateFormat)
                    }});

                can.$(".display").append(template);
				can.$(".author__display").append(authorTemplate);
				$("body").attr("author-items-length", popup.authorItems.length);

				if (backgroundPage.kmj.connected === false){
					if (backgroundPage.kmj.getLocalStore("URL") === DEFAULT_VALUES["URL"]){
                        html = popup.messages.noConf;
                    } else {
                        html = popup.messages.unknown + "<br/>" + popup.messages.noConf;
                    }
					$('footer a.login').text("Login");
					$("body").addClass("logged-in-false").removeClass("logged-in-true");
                    $("p.message").html( html );
					return;
				} else {
					$('footer a.login').text("Stash");
					$("body").addClass("logged-in-true").removeClass("logged-in-false");
				}
                if (popup.items.length > 0 || (popup.showAuthored && popup.authorItems.length > 0) ) {
					// something to show
                    $("p.message").empty();
					console.log("1 popup.items.length > 0 || (popup.showAuthored && popup.authorItems.length > 0) true");
                }
				if (backgroundPage.kmj.items.length === 0){
					// connected but no main items
					$("p.message").html( popup.messages.noIssuesMessage );
					console.log("2 backgroundPage.kmj.items.length === 0 && backgroundPage.kmj.connected === true -- true");
                }
            },
            monitor:function(){
                // check for updates if the user clicks the refresh button.
				$("body").removeClass("loading");
				$("p.message").empty();
				if (popup.checking){
					clearTimeout(popup.checking);
				}
                if (backgroundPage.kmj.items.length !== popup.items.length){/* don't refresh unless something has been added or removed */
                    popup.changed = true;
					popup.items.replace(backgroundPage.kmj.items);
                }
                if (backgroundPage.kmj.items.length === 0){
					var html = (backgroundPage.kmj.connected) ? popup.messages.noIssuesMessage : popup.messages.unknown;
                    $("p.message").html( html );
                }
				popup.checking = window.setTimeout(function(){popup.monitor();}, popup.refreshTime);
            }
        };

    $(window).on('load', function(){
        popup.init();
        //var mon;
        $("#refresh").on('click',function(){
            popup.checkingCounter = 0;
            popup.items.replace( [] );
            popup.authorItems.replace( [] );
            $("body").addClass("loading");
            $("p.message").empty();
            backgroundPage.kmj.init(function(){ popup.init() });
            if (popup.checking){
                window.clearTimeout(popup.checking);
            }
            popup.checking = window.setTimeout(function(){popup.monitor();}, popup.refreshTime);
        });
        $(document).on('click', 'a.login', function(e){
{'fraction_non_alphanumeric': 0.16296126518450607, 'fraction_numerical': 0.0027504011001604402, 'mean_word_length': 2.2265220606359377, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3573367', 'n_tokens_mistral': 4083, 'n_tokens_neox': 3528, 'n_words': 642}