<commit_before>/**
 * @author chaitanya
 */

function Capture(db) {
    var self = this;
    this.view = function (evt) {
        var viewTabUrl = chrome.extension.getURL("capture.html");
    	var imageid = evt.srcElement.parentNode.getAttribute("screenshot");
        notableapp.dbhandle.transaction(function(tx) {
            tx.executeSql("SELECT id, title, url, image FROM NotableApp WHERE id = ?", [imageid], function(tx, result) {
            	result = result.rows.item(0);
                chrome.tabs.create({url: viewTabUrl, selected: true}, function(tab) {
                	console.log("image data obtained: " + result["image"]);
                    var views = chrome.extension.getViews();
                    for (var i = 0; i < views.length; i++) {
                       var view = views[i];
                       if (view.location.href == viewTabUrl && !view.imageAlreadySet) {
                          view.setScreenshotUrl(result["image"]);
                          view.imageAlreadySet = true;
                          break;
                       }
                    }
                });
            }, function(tx, error){
                console.log('Failed to retrieve notes from database - ' + error.message);
                return;
            });
        });
    };
    this.log = function() {
        console.log("object log: "+ self.title +", "+ self.url);
    };
    this.save = function() {
        var cap = this;
        console.log("object saved: "+ cap.title +", "+ cap.url +", "+ cap.image);
        notableapp.dbhandle.transaction(function(tx){
            tx.executeSql("INSERT INTO NotableApp (title, url, image) VALUES (?, ?, ?)", [cap.title, cap.url, cap.image], function(tx, result) {
		notableapp.updateDisplay("added", null, null);
            });
        });
    };
    this.remove = function(evt) {
    	var imageid = evt.srcElement.parentNode.parentNode.getAttribute("screenshot");
        console.log("remove has been clicked " + imageid);
        notableapp.dbhandle.transaction(function(tx) {
            tx.executeSql("DELETE FROM NotableApp WHERE id = ?", [imageid], function(tx, result) { 
		notableapp.updateDisplay("remove", evt, imageid);
	    });
        });
    };
    return this;
}

Capture.prototype = {
    get id() {
        if (!("_id" in this))
            this._id = 0;
        return this._id;
    },
 
    set id(x) {
        this._id = x;
    },
 
    get title() {
        if (!("_title" in this))
            this._title = 0;
        return this._title;
    },
 
    set title(x) {
        this._title = x;
    },
     
    get url() {
        if (!("_url" in this))
            this._url = 0;
        return this._url;
    },
 
    set url(x) {
        this._url = x;
    },
 
    get image() {
        if (!("_image" in this))
            this._image = 0;
        return this._image;
    },
 
    set image(x) {
        this._image = x;
    }
};

function captureNew () {
    var cap = new Capture(notableapp.dbhandle);
    chrome.tabs.getSelected(null, function(tab) {
        cap.url = tab.url;
        cap.title = tab.title;
    });
    chrome.tabs.captureVisibleTab(null, function(img) {
        cap.image = img;
    });
    window.setTimeout(function(){
       cap.save();
    }, 300);
    notableapp.display(null);
}

var notableapp = (function () {
	try {
	    db1 = openDatabase("NotableAppDB", "1.0", "NotableApp Captures Table", 20000);
	    db1.transaction (function(tx) {
	        tx.executeSql ("SELECT id FROM NotableApp", [], function(tx, result) { 
	            console.log("records count is " + result.rows.length);
	        },
	        function(tx, error) {
	            tx.executeSql("CREATE TABLE IF NOT EXISTS NotableApp (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, title TEXT, url TEXT, image BLOB)", [], 
	    			function(r) {
	    				console.log("table successfully created. ");
	    			});
	    		}
	       );
	    });
	} catch (err) {
	    console.log("failed to open the db.");
	}

	return {
		dbhandle : db1,
                init : function () {
                     notableapp.updateBadgeText();
                },
		totalCaptures : function () {
			console.log("fetching the total number of captures.");
			return 1;
		},
		updateBadgeText : function () {
			console.log("updating the badge-text.");
			db1.transaction(function(tx) {
			    tx.executeSql("SELECT id FROM NotableApp", [], function(tx, result){
				chrome.browserAction.setBadgeText({
					text: ""+result.rows.length
				});
			    }, function(tx, error){
				console.log('Failed to retrieve notes from database - ' + error.message);
				return;
			    });
			});
		},
                updateDisplay : function (action, evt, imageid) {
                     console.log("action, id : " + action + ", " + imageid );
                     if (action == "remove" && imageid != null) {
                         document.body.removeChild( evt.srcElement.parentNode.parentNode );
                     } else if ( action == "added" ) {
		             var sqlquery = "SELECT * from NotableApp where id = ( select max(id) from NotableApp )";
		             notableapp.display(sqlquery);
                     }
                },
                display : function (sqlquery) {

                        if (sqlquery === null ) {
                            sqlquery = "SELECT id, title, url, image FROM NotableApp";
			}
                        var tmp, scrshot = document.getElementsByClassName("screenshot")[0];
			db1.transaction(function(tx) {
                           tx.executeSql(sqlquery, [], function(tx, result){
				for (var i = 0; i < result.rows.length; ++i) {
				    var row = result.rows.item(i);
				    var cap = new Capture();
				    cap.id  = row['id'];
				    cap.url = row['url'];
				    cap.title = row['title'].substring(0,25);
				    cap.image = row['image'];
				    console.log("object displaying: "+ cap.title +", "+ cap.url +", " + cap.image);<commit_msg>intermediate commit<commit_after>/**
 * @author chaitanya
 */

function Capture(db) {
    var self = this;
    this.view = function (evt) {
        var viewTabUrl = chrome.extension.getURL("capture.html");
    	var imageid = evt.srcElement.parentNode.getAttribute("screenshot");
        notableapp.dbhandle.transaction(function(tx) {
            tx.executeSql("SELECT id, title, url, image FROM NotableApp WHERE id = ?", [imageid], function(tx, result) {
            	result = result.rows.item(0);
                chrome.tabs.create({url: viewTabUrl, selected: true}, function(tab) {
                	console.log("image data obtained: " + result["image"]);
                    var views = chrome.extension.getViews();
                    for (var i = 0; i < views.length; i++) {
                       var view = views[i];
                       if (view.location.href == viewTabUrl && !view.imageAlreadySet) {
                          view.setScreenshotUrl(result["image"]);
                          view.imageAlreadySet = true;
                          break;
                       }
                    }
                });
            }, function(tx, error){
                console.log('Failed to retrieve notes from database - ' + error.message);
                return;
            });
        });
    };
    this.log = function() {
        console.log("object log: "+ self.title +", "+ self.url);
    };
    this.save = function() {
        var cap = this;
        console.log("object saved: "+ cap.title +", "+ cap.url +", "+ cap.image);
        notableapp.dbhandle.transaction(function(tx){
            tx.executeSql("INSERT INTO NotableApp (title, url, image) VALUES (?, ?, ?)", [cap.title, cap.url, cap.image], function(tx, result) {
		notableapp.updateDisplay("added", null, null);
            });
        });
    };
    this.remove = function(evt) {
    	var imageid = evt.srcElement.parentNode.parentNode.getAttribute("screenshot");
        console.log("remove has been clicked " + imageid);
        notableapp.dbhandle.transaction(function(tx) {
            tx.executeSql("DELETE FROM NotableApp WHERE id = ?", [imageid], function(tx, result) { 
		notableapp.updateDisplay("remove", evt, imageid);
	    });
        });
    };
    return this;
}

Capture.prototype = {
    get id() {
        if (!("_id" in this))
            this._id = 0;
        return this._id;
    },
 
    set id(x) {
        this._id = x;
    },
 
    get title() {
        if (!("_title" in this))
            this._title = 0;
        return this._title;
    },
 
    set title(x) {
        this._title = x;
    },
     
    get url() {
        if (!("_url" in this))
            this._url = 0;
        return this._url;
    },
 
    set url(x) {
        this._url = x;
    },
 
    get image() {
        if (!("_image" in this))
            this._image = 0;
        return this._image;
    },
 
    set image(x) {
        this._image = x;
    }
};

function captureNew () {
    var cap = new Capture(notableapp.dbhandle);
    chrome.tabs.getSelected(null, function(tab) {
        cap.url = tab.url;
        cap.title = tab.title;
    });
    chrome.tabs.captureVisibleTab(null, function(img) {
        cap.image = img;
    });
    window.setTimeout(function(){
       cap.save();
    }, 300);
    notableapp.display(null);
}

var notableapp = (function () {
	try {
	    db1 = openDatabase("NotableAppDB", "1.0", "NotableApp Captures Table", 20000);
	    db1.transaction (function(tx) {
	        tx.executeSql ("SELECT id FROM NotableApp", [], function(tx, result) { 
	            console.log("records count is " + result.rows.length);
	        },
	        function(tx, error) {
	            tx.executeSql("CREATE TABLE IF NOT EXISTS NotableApp (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, title TEXT, url TEXT, image BLOB)", [], 
	    			function(r) {
	    				console.log("table successfully created. ");
	    			});
	    		}
	       );
	    });
	} catch (err) {
	    console.log("failed to open the db.");
	}

	return {
		dbhandle : db1,
                init : function () {
                     notableapp.updateBadgeText();
                },
		totalCaptures : function () {
			console.log("fetching the total number of captures.");
			return 1;
		},
		updateBadgeText : function () {
			console.log("updating the badge-text.");
			db1.transaction(function(tx) {
			    tx.executeSql("SELECT id FROM NotableApp", [], function(tx, result){
				chrome.browserAction.setBadgeText({
					text: ""+result.rows.length
				});
			    }, function(tx, error){
				console.log('Failed to retrieve notes from database - ' + error.message);
				return;
			    });
			});
		},
                updateDisplay : function (action, evt, imageid) {
                     console.log("action, id : " + action + ", " + imageid );
                     if (action == "remove" && imageid != null) {
                         document.body.removeChild( evt.srcElement.parentNode.parentNode );
                     } else if ( action == "added" ) {
		             var sqlquery = "SELECT * from NotableApp where id = ( select max(id) from NotableApp )";
		             notableapp.display(sqlquery);
                     }
                },
                display : function (sqlquery) {

                        if (sqlquery === null ) {
                            sqlquery = "SELECT id, title, url, image FROM NotableApp";
			}
                        var tmp, scrshot = document.getElementsByClassName("screenshot")[0];
			db1.transaction(function(tx) {
                           tx.executeSql(sqlquery, [], function(tx, result){
				for (var i = 0; i < result.rows.length; ++i) {
				    var row = result.rows.item(i);
				    var cap = new Capture();
				    cap.id  = row['id'];
				    cap.url = row['url'];
				    cap.title = row['title'].substring(0,25);
				    cap.image = row['image'];
//				    console.log("object displaying: "+ cap.title +", "+ cap.url +", " + cap.image);
{'fraction_non_alphanumeric': 0.14345637583892618, 'fraction_numerical': 0.004530201342281879, 'mean_word_length': 1.795731707317073, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '779591', 'n_tokens_mistral': 3730, 'n_tokens_neox': 3424, 'n_words': 766}