Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directory indexing for creating search database #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions code/js/metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2018 The OpenGenus Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var obj = {};

function readDirectory(dirEntry) {
var dirReader = dirEntry.createReader();
dirReader.readEntries(function(entries) {
for(var i = 0; i < entries.length; i++) {
var entry = entries[i];
if (entry.isDirectory){
readDirectory(entry);
}
else if (entry.isFile) {
var filename = entry.name;
var filepath = entry.fullPath.split("/").slice(2,-1).join("/");
if (!obj[filepath]) {
obj[filepath] = [];
}
obj[filepath].push(filename);
}
}
localStorage["metadata"] = JSON.stringify(obj);
});
}

function populate () {
chrome.runtime.getPackageDirectoryEntry(function(storageRootEntry) {
if(storageRootEntry.isDirectory) {
var dirReader = storageRootEntry.createReader();

var readEntries = function() {
dirReader.readEntries(function(entries) {
for(var i = 0; i < entries.length; i++) {
var entry = entries[i];
if (entry.name === "code") {
readDirectory(entry);
break;
}
}

if (!entries.length)
readEntries();
});
};

readEntries();
}
});
}

if (!localStorage["metadata"] || location.hash === "#refresh") {
populate();
}
11 changes: 3 additions & 8 deletions code/js/popup.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions code/popup.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>

<script src="js/metadata.js"></script>
<script src="js/jquery.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
Expand Down Expand Up @@ -53,8 +53,13 @@

<a class="btn float-right" target="_blank" id="favButton" href="javascript:void(0)">Favorites</a>

<button class="btn dropdown-toggle dropdown_button float-right" type="button" data-toggle="dropdown">Settings<span class="caret"></span></button>
<ul class="dropdown-menu" id="main_drop_menu">
<li class="dropdown_button" title="Refresh data">
<a href="?#refresh">Refresh</a>
</li>
</ul>


<div class="dropdown">
<button class="btn dropdown-toggle dropdown_button float-right" type="button" data-toggle="dropdown">More Apps<span class="caret"></span></button>
<ul class="dropdown-menu" id="main_drop_menu">
Expand Down