document.addEventListener("DOMContentLoaded", function() {
chrome.storage.sync.get(
{"lists": [
- [
+ ["General",
["Github", "https://github.com"],
["Wikipedia", "https://en.wikipedia.org"],
["Gmail", "https://mail.google.com"]
],
- [
+ ["Productivity",
["Desmos", "https://www.desmos.com/calculator"],
["Wolfram", "https://wolframalpha.com"],
["Hacker News", "https://news.ycombinator.com"]
],
- [
+ ["Social",
["Reddit", "https://www.reddit.com"],
["YouTube", "https://youtube.com"],
["Instagram", "https://instagram.com"]
]
- ],
-"l1name": "General",
-"l2name": "Productivity",
-"l3name": "Social"},
+ ]
+},
userListsCallback);
});
function listToArray(list) {
var l = [];
+ console.log(list);
+ console.log(list.getElementsByClassName('title')[0].getElementsByTagName("p")[0].textContent);
+ l[0] = list.getElementsByClassName('title')[0].getElementsByTagName("p")[0].textContent;
var elem = list.getElementsByTagName("li");
for (var i = 0; i < elem.length; ++i) {
- l[i] = [elem[i].getElementsByTagName("a")[0].innerText, elem[i].getElementsByTagName("a")[0].getAttribute("href")];
+ l[i+1] = [elem[i].getElementsByTagName("a")[0].innerText, elem[i].getElementsByTagName("a")[0].getAttribute("href")];
}
return l;
}
var userListsCallback = function(lists) {
- mainlist = [lists["l1name"],lists["l2name"],lists["l3name"]]
+ console.log(lists);
+ console.log(lists['lists'][0][0]);
+ mainlist = [lists['lists'][0][0],lists['lists'][1][0],lists['lists'][2][0]]
for(var i=0;i<lists["lists"].length;i++) {
var ul = document.createElement("ul");
ul.setAttribute("id", mainlist[i]);
title.insertAdjacentHTML("beforeend", "<span class='add' id='add-"+mainlist[i]+"'>+</span>");
var list = lists["lists"][i];
- for(var j=0;j<lists["lists"][i].length;j++) {
+ for(var j=1;j<lists["lists"][i].length;j++) {
var li = document.createElement("li");
li.setAttribute("id", mainlist[i]+"-"+j);
var siteurl = list[j][1];
};
function dragStart(e) {
- console.log("Drag started for " + this);
console.log(this);
dragSrcEl = this;
e.dataTransfer.effectAllowed = 'move';
}
function dragOver(e) {
- console.log("Object " + this + " is ready to be placed");
if (e.preventDefault) {
e.preventDefault();
}
e.stopPropagation();
}
if (dragSrcEl != this) {
+ console.log(mainlist);
dragSrcEl.innerHTML = this.innerHTML;
this.innerHTML = e.dataTransfer.getData('text/html');
+ save();
}
- console.log("Saving positions");
- save();
return false;
}
save();
} else {
var ul = document.getElementById(r[1]);
- console.log(ul);
if (document.querySelectorAll("#"+r[1]+" .new").length > 0) {
fields = document.querySelector("#"+r[1]+" .new .name");
fields.focus();
function save(l) {
var set = l || JSON.parse(JSON.stringify(mainlist));
+ console.log(set);
d = []
d = set;
console.log("Saving settings");