Skip to content

Commit

Permalink
new feature popup added
Browse files Browse the repository at this point in the history
  • Loading branch information
adeora7 committed Feb 18, 2018
1 parent 966435d commit 29a1dc1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
33 changes: 25 additions & 8 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@ chrome.storage.sync.get('youtube_queue_extension_queue', function(data){
});

//New Feature Popup Starts
//Think about it
//add new feature
chrome.storage.sync.get('youtube_queue_extension_v140', function(data){
if(data['youtube_queue_extension_new_v140'] == undefined)
{
chrome.storage.sync.set({'youtube_queue_extension_v140': '5*Now Drag-Drop the videos in Queue to reorder.'}, function(){

});
}
});

//remove old feature
chrome.storage.sync.get('youtube_queue_extension_v139', function(data){
if(!(data['youtube_queue_extension_v139'] == undefined)){
chrome.storage.sync.remove('youtube_queue_extension_v139', function(){

});
}
});
//New Feature Popup Ends

function saveQueue(currentQueue){
Expand All @@ -34,17 +51,13 @@ function reorderQueue(newPositions){
if(main.songs.length == 1){
return;
}
console.log(newPositions);
console.log("Next video:" + next_video);
if(next_video == 0){
current = main.songs.length-1;
}
else
{
current = next_video-1;
}
console.log("Current Video" + current);
// alert(current);
for(var ghi = 0; ghi<newPositions.length; ghi++){
newPositions[ghi] = parseInt(newPositions[ghi]);
}
Expand All @@ -54,7 +67,6 @@ function reorderQueue(newPositions){
for(var i = 0; i<newPositions.length; i++){
newQueue.push(main.songs[newPositions[i]]);
}
// alert(JSON.stringify(newQueue));
saveQueue(newQueue);
};

Expand Down Expand Up @@ -329,10 +341,15 @@ chrome.runtime.onMessage.addListener(
};
somefunction2("hello", urlObj);
}
else if(request.greeting = "queue_reorder"){
// alert(JSON.stringify(request.newPositions));
else if(request.greeting == "queue_reorder"){
reorderQueue(request.newPositions);
sendResponse({res: "Order Changed"});
}
// else if(request.greeting == "new_feature"){
// chrome.storage.sync.get('youtube_queue_extension_v140', function(data){
// sendResponse({feature: data['youtube_queue_extension_v140']});
// });
// // sendResponse({feature: "drag-drop"});
// }
});

18 changes: 14 additions & 4 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ load_tooltips();

//refresh function starts
function refresh(){
console.log("hello");
chrome.runtime.sendMessage({greeting: "hello"}, function(response) {

localCopy = response.res;
Expand Down Expand Up @@ -557,7 +556,6 @@ function uploadPlaylist(name){
}
}
sgs = JSON.stringify(sgs);
console.log(sgs);
var http = new XMLHttpRequest();
var url = "https://multicultural-drake-14693.herokuapp.com/upload/playlist/";
var params = "name="+name+"&videos="+sgs;
Expand Down Expand Up @@ -873,12 +871,24 @@ var onSortingStop = function( event, ui ) {
newPositions.push(elmnt.firstElementChild.getAttribute('songid'));
}
});
console.log(newPositions);

chrome.runtime.sendMessage({greeting: "queue_reorder", newPositions: newPositions}, function(response){
refresh();
console.log("Reording successful");
});
//send it to background.js to change the order after this. Should be an easy fix now.
};

//New feature starts
chrome.storage.sync.get('youtube_queue_extension_v140', function(data){
if(data['youtube_queue_extension_v140'] != undefined){
var msg = data['youtube_queue_extension_v140'].split("*");
if(Number(msg[0]) > 0){
notif( msg[1]);
var newMsg = Number(msg[0]-1).toString() + "*" + msg[1];
chrome.storage.sync.set({'youtube_queue_extension_v140': newMsg}, function(){

});
}
}
})
//New feature ends

0 comments on commit 29a1dc1

Please sign in to comment.