// ==UserScript== // @name goontube playlist scraper // @namespace http://use.i.E.your.homepage/ // @version 0.1 // @description enter something useful // @match http://www.goontu.be/ // @match http://www.goontu.be/# // @match *goontu.be/* // @match http://goontu.be/# // @copyright 2015+, kormak // ==/UserScript== (function () { var jA = document.createElement('script'); jA.setAttribute('type', 'text/javascript'); jA.setAttribute('src', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'); document.body.appendChild(jA); //$('head').append(''); //save_playlist_to_cookie(); setInterval(save_playlist_to_cookie, 5000); $("#fullscreentog").after(''); $("#banner").css("background-color", "#222"); $('body').css("background-color", "#222"); $("#dump_playlist").click(function(){ dump_playlist(); }); }() ); unsafeWindow.playlist_urls = [] function uniquify(collection){ unique_collection = []; old_collection = []; $.each(collection, function(index, value) { old_collection.push(JSON.stringify(value)); }); $.each(old_collection, function(index, value) { if ($.inArray(value, unique_collection)==-1) { unique_collection.push(value); } }); restored_collection = []; $.each(unique_collection, function(index, value) { restored_collection.push(JSON.parse(value)); }); return restored_collection; } unsafeWindow.uniquify = uniquify; function save_playlist_to_cookie() { dump_playlist(); var playlist_urls_stringified = JSON.stringify(playlist_urls); //first off, read the cookie stashed_infos = get_local_storage("gtub_stashed_playlist_infos") if(stashed_infos == "" || stashed_infos == null){ stashed_playlist_info = []; }else{ stashed_playlist_info = JSON.parse(stashed_infos); } //stashed_playlist_info = JSON.parse(get_cookie("gtub_stashed_playlist_infos")); complete_playlist_info = $.merge(stashed_playlist_info, playlist_urls); complete_playlist_info = uniquify(complete_playlist_info); playlist_urls_stringified = JSON.stringify(complete_playlist_info); set_local_storage("gtub_stashed_playlist_infos", playlist_urls_stringified); return playlist_urls_stringified; } unsafeWindow.save_playlist_to_cookie = save_playlist_to_cookie; //JSON.stringify(JSON.parse(get_cookie("gtub_stashed_playlist_infos"))[9]) == JSON.stringify(JSON.parse(get_cookie("gtub_stashed_playlist_infos"))[0]) function dump_playlist(){ //cool oneliner. thanks spacecheif, thpeif $.each(pl, function(i, v) { _info = [(v.video_provider == "vm" ? "http://www.vimeo.com/" : "http://www.youtube.com/watch/") + v.video_id, v.title, v.dur/60000]; playlist_urls.push(_info); }) var playlist_urls_text = playlist_urls.join("
"); } unsafeWindow.dump_playlist = dump_playlist; function dump_playlist_to_console(){ save_playlist_to_cookie(); stashed_infos = get_local_storage("gtub_stashed_playlist_infos") if(stashed_infos == ""){ stashed_playlist_info = []; }else{ stashed_playlist_info = JSON.parse(stashed_infos); } playlist_urls_text = ""; $.each(stashed_playlist_info, function(i, value){ playlist_urls_text += value.join(" - ") + "\n"; }); //var playlist_urls_text = stashed_playlist_info.join("
"); console.log(playlist_urls_text); } unsafeWindow.dump_playlist_to_console = dump_playlist_to_console; function show_dumped_playlist(){ var modal_content = "" + ""; video_list_modal = $('').appendTo("body"); video_list_modal = video_list_modal.modal({show: true, backdrop: 'static'}); video_list_modal.html(modal_content); $(".modal-body", video_list_modal).first().html(playlist_urls_text); } unsafeWindow.show_dumped_playlist = show_dumped_playlist; function set_cookie(name, value, days) { /* This function is building the contents that will create the cookie. The if statement is checking to see if "days" has a value, if so, it is calculating the expiration date for the cookie. If "days" does not have a value, the cookie is set to expire when the browser closes. Once the expiration is calculated the cookie is created by adding name, value, and calculated expiration(expires) */ if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); // this equation converts the days variable into milliseconds days(variable)*24(hours in a day)*60(minutes in an hour)*60(seconds in //a minute)*1000(miliseconds in a second) and adds that value to the current datetime var expires = "; expires="+date.toGMTString(); } else { var expires = ""; } document.cookie = name+"="+value+expires; } unsafeWindow.set_cookie = set_cookie; function get_cookie(existing_name) { // This function takes the cookies and turns them into an array, then compares cookie names to the variable existing_name. If there is //a match between cookie and existing_name then the function saves that cookie and value to output. If no cookie exists the default output //value of "" is retained. The variable output is then returned var existing_cookie = existing_name + "="; var cookies = document.cookie.split(';'); var output = ""; for(var i=0; i