Skip to content

Commit

Permalink
drag drop added and many other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adeora7 committed Feb 16, 2018
1 parent 8c437bd commit 966435d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
62 changes: 55 additions & 7 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,58 @@ var main = {
chrome.storage.sync.get('youtube_queue_extension_queue', function(data){
if(data['youtube_queue_extension_queue'] == undefined)
{
data['youtube_queue_extension_queue'] = [];
// data['youtube_queue_extension_queue'] = [];
saveQueue([]);
}
else{
main.songs = data['youtube_queue_extension_queue'];
}
});

//New Feature Popup Starts
//Think about it
//New Feature Popup Ends

function saveQueue(currentQueue){
chrome.storage.sync.set({'youtube_queue_extension_queue': currentQueue}, function(){

main.songs = currentQueue;
});
}
};


var tabId = 0;
var next_video = 1;

function reorderQueue(newPositions){
//change
var current = 0;
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]);
}
current = newPositions.indexOf(current);
next_video = (current+1)%main.songs.length;
var newQueue = [];
for(var i = 0; i<newPositions.length; i++){
newQueue.push(main.songs[newPositions[i]]);
}
// alert(JSON.stringify(newQueue));
saveQueue(newQueue);
};

function createTab(){
if(main.songs.length > 0){
chrome.tabs.create({'url': main.songs[0].url}, function(tab) {
Expand Down Expand Up @@ -74,22 +110,29 @@ function playSpecificVideo(songnum){
chrome.browserAction.setBadgeBackgroundColor({ color: [0, 0, 0, 255] });
chrome.browserAction.setBadgeText({text: left.toString()});
}
else{
next_video = 0;
}
}
function removeCertainVideo(songnum){
//songnum is index
var curr = next_video-1;
if(curr == -1)
curr = main.songs.length-1;
var n = Number(songnum);
var n = Number(songnum);
if(n>=0 && n<main.songs.length)
{
main.songs.splice(n,1);
if(n == curr && n == main.songs.length)
if(n == curr && n == main.songs.length){
playSpecificVideo(n-1);
else if( n == curr )
}
else if( n == curr ){
playSpecificVideo(n);
}
else if(n<curr){
next_video = next_video-1;
if(next_video == -1){
next_video = 0;
}
}
}
saveQueue(main.songs);
Expand Down Expand Up @@ -286,5 +329,10 @@ chrome.runtime.onMessage.addListener(
};
somefunction2("hello", urlObj);
}
else if(request.greeting = "queue_reorder"){
// alert(JSON.stringify(request.newPositions));
reorderQueue(request.newPositions);
sendResponse({res: "Order Changed"});
}
});

5 changes: 5 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,11 @@ var onSortingStop = function( event, ui ) {
}
});
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.
};

4 changes: 3 additions & 1 deletion inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ function addIcon(){
node.onmouseup = function(){
this.style.backgroundColor = "red";
}
node.onclick = function(){
node.onclick = function(event){
// console.log(event);
event.stopPropagation();
var link = this.getAttribute("href");
chrome.runtime.sendMessage({greeting: "addIconClicked", link : link}, function(res) {
//Request sent to add video to queue
Expand Down

0 comments on commit 966435d

Please sign in to comment.