// ==UserScript==
// @name Turkdigo FlicksIO Helper
// @author Turkdigo
// @namespace Turkdigo
// @description FlicksIO helper; adds some stuff on Google and IMDb to make searching and submitting (slightly, ever so slightly) less of a problem.
// @match https://flicksio.com/mturk*
// @match https://www.google.com/*
// @match http://www.imdb.com/*
// @require http://code.jquery.com/jquery-latest.min.js
// @version 1.2
// @grant GM_log
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @downloadURL none
// ==/UserScript==
if (window.location.href.indexOf("flicksio.com") > -1) { // Start internal HIT code
GM_deleteValue("inject");
GM_deleteValue("url");
GM_deleteValue("count");
GM_deleteValue("title");
GM_deleteValue("episode");
GM_deleteValue("show");
GM_deleteValue("season");
var inject = [];
var url = [];
var title = [];
var count = 0;
var episode = [];
var show = [];
var season = [];
$("h1").each(function(index){
title.push($(this).text().trim());
var epget = title[index].substr(0, title[index].indexOf('('));
var shwget = title[index].substr(title[index].indexOf('("') + 2);
epget = epget.slice(0, -1);
shwget = shwget.slice(0, -2);
var showtru = shwget.substring(0, shwget.indexOf(','));
var ssntru = shwget.substring( shwget.indexOf(',') + 2);
episode.push(epget.trim());
show.push(showtru.trim());
season.push(ssntru.trim());
});
$("a[href^='https://www.google.com/search']").each(function( index ) { // Grab Pre-populated Google Search
url.push( $( this ).attr('href'));
});
GM_setValue("url", JSON.stringify(url));
GM_setValue("count", count);
GM_setValue("title", JSON.stringify(title));
GM_setValue("show", JSON.stringify(show));
GM_setValue("episode", JSON.stringify(episode));
GM_setValue("season", JSON.stringify(season));
GM_setValue("inject", JSON.stringify(inject));
window.open(url[0]);
$("input[type=submit]").before('').hide(); // Add Inject before Submit
$(window).keypress(function(e) {
if (e.keyCode == 115) {
$("#inject").click();
$("input[type=submit]").click();
}
});
$( "button#inject" ).click(function() {
var inject = JSON.parse(GM_getValue("inject"));
$("input[placeholder='Enter IMDb URL']:eq(0)").val(inject[0]);
$("input[placeholder='Enter IMDb URL']:eq(1)").val(inject[1]);
$(this).hide();
$("input[type=submit]").show();
});
}
if (window.location.href.indexOf("google.com/search") > -1) { // Start Google code
var inject = JSON.parse(GM_getValue("inject"));
var url = JSON.parse(GM_getValue("url"));
var title = JSON.parse(GM_getValue("title"));
var show = JSON.parse(GM_getValue("show"));
var episode = JSON.parse(GM_getValue("episode"));
var season = JSON.parse(GM_getValue("season"));
if (GM_getValue("count")!=1){
$("div#top_nav").append('