Skip to content

Commit

Permalink
added shuffle queue option
Browse files Browse the repository at this point in the history
  • Loading branch information
adeora7 committed Sep 13, 2018
1 parent 94bfe5c commit c078b55
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
32 changes: 26 additions & 6 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ var main = {

var showIconsToggle = "yes";

function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;

while (0 !== currentIndex) {

randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}

return array;
}

function updateShowIconsVariable(){
chrome.storage.sync.get( "youtube_queue_extension_show_icons", function(data){
if( data["youtube_queue_extension_show_icons"] != undefined)
Expand All @@ -26,19 +42,19 @@ chrome.storage.sync.get('youtube_queue_extension_queue', function(data){

//New Feature Popup Starts
//add new feature
chrome.storage.sync.get('youtube_queue_extension_v140', function(data){
if(data['youtube_queue_extension_new_v140'] == undefined)
chrome.storage.sync.get('youtube_queue_extension_v142', function(data){
if(data['youtube_queue_extension_new_v142'] == undefined)
{
chrome.storage.sync.set({'youtube_queue_extension_v140': '5*Now Drag-Drop the videos in Queue to reorder.'}, function(){
chrome.storage.sync.set({'youtube_queue_extension_v142': '5*Shuffle Queue option added.'}, 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(){
chrome.storage.sync.get('youtube_queue_extension_v140', function(data){
if(!(data['youtube_queue_extension_v140'] == undefined)){
chrome.storage.sync.remove('youtube_queue_extension_v140', function(){

});
}
Expand Down Expand Up @@ -335,6 +351,7 @@ chrome.runtime.onMessage.addListener(
}
else if(request.greeting == "empty_queue"){
empty_queue();
// main.songs = shuffle(main.songs);
sendResponse({res: "Queue is now empty."});
}
else if(request.greeting == "playFeatured"){
Expand All @@ -361,6 +378,9 @@ chrome.runtime.onMessage.addListener(
else if(request.greeting == "updatedShowIcons"){
updateShowIconsVariable();
}
else if(request.greeting == "shuffle"){
main.songs = shuffle(main.songs);
}
// else if(request.greeting == "new_feature"){
// chrome.storage.sync.get('youtube_queue_extension_v140', function(data){
// sendResponse({feature: data['youtube_queue_extension_v140']});
Expand Down
17 changes: 13 additions & 4 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ var songToAdd = -1;
document.getElementById("play_next").addEventListener('click', play_next, false);
document.getElementById("pause_play").addEventListener('click', play_pause, false);
document.getElementById("play_previous").addEventListener('click', play_previous, false);

//player options
document.getElementById("settings").addEventListener('click', open_settings, false);
document.getElementById("empty").addEventListener('click', empty_queue, false);
document.getElementById("shuffle").addEventListener('click', shuffle, false);

// settings listeners
document.getElementById("repeatAll").addEventListener('click', toggle_loop, false);
Expand Down Expand Up @@ -49,6 +52,12 @@ function empty_queue(){
})
}

function shuffle(){
chrome.runtime.sendMessage({greeting : "shuffle"}, function(response){
refresh();
})
}

//in video controls end


Expand Down Expand Up @@ -942,13 +951,13 @@ var onSortingStop = function( event, ui ) {
};

//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("*");
chrome.storage.sync.get('youtube_queue_extension_v142', function(data){
if(data['youtube_queue_extension_v142'] != undefined){
var msg = data['youtube_queue_extension_v142'].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(){
chrome.storage.sync.set({'youtube_queue_extension_v142': newMsg}, function(){

});
}
Expand Down
Binary file added images/shuffle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Youtube Queue",
"description": "Allows you to queue youtube videos and plays them for you.",
"version": "1.41",
"version": "1.42",
"permissions": ["contextMenus", "tabs", "<all_urls>", "storage"],
"browser_action" : {
"default_icon" : "icon48.png",
Expand Down
3 changes: 3 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<div class="control-icon tooltipped" data-position="bottom" data-delay="50" data-tooltip="Settings" id="settings">
<img src="images/settings.png">
</div>
<div class="control-icon tooltipped" data-position="bottom" data-delay="50" data-tooltip="Shuffle Queue" id="shuffle">
<img src="images/shuffle.png">
</div>
<div class="control-icon tooltipped" data-position="bottom" data-delay="50" data-tooltip="Empty Queue" id="empty">
<img src="images/empty.png">
</div>
Expand Down

0 comments on commit c078b55

Please sign in to comment.