// ==UserScript== // @name IMDb List Helper // @namespace imdb // @description Makes creating IMDb lists more efficient and convenient // @version 2.3.0 // @include http://*imdb.com/list/edit* // @require https://cdnjs.cloudflare.com/ajax/libs/jquery-csv/0.71/jquery.csv-0.71.min.js // @downloadURL none // ==/UserScript== var jQuery = unsafeWindow.jQuery; var $ = jQuery; // // CHANGELOG // // 2.3.0 // bugfix: importing ratings works again // // 2.2.0 // added: support for people // // 2.1.1 // added: only show import form if ratings is selected // // 2.1 // added: importers for imdb, rateyourmusic, criticker // // 2.0 // added: import ratings // added: if regex doesn't match, skip entry // // 1.6.1.2 // added: input text suggestion as a placeholder // // 1.6.1.1 // fixed: some entries are skipped when adding imdb ids/urls // // // milliseconds between each request // var REQUEST_DELAY = 1000; function processImdb(file) { var csv_lines = file.split("\n"); for(var i = 1; i < csv_lines.length; ++i) { try { var data = jQuery.csv.toArray(csv_lines[i]); var rating = data[8]; if(rating === "") { continue; } $("#filmList").append(rating + "," + data[1] + "\n"); } catch(e) { console.log("Exception: " + e); console.log("Bad line: " + csv_lines[i]); } } } function processRym(file) { var csv_lines = file.split("\n"); for(var i = 1; i < csv_lines.length; ++i) { try { var data = jQuery.csv.toArray(csv_lines[i]); if(data.length < 6) { continue; } $("#filmList").append(data[4] + "," + data[1] + "\n"); } catch(e) { console.log("Exception: " + e); console.log("Bad line: " + csv_lines[i]); } } } function processCriticker(file) { var lines = file.split("\n"); for(var i = 1; i < lines.length; ++i) { var line = lines[i]; var m = line.match(/([1-9]{1}|10)([0-9])?\t(.+)/); if(m === null) { continue; } var rating = m[1]; var second = m[2]; if(second === undefined) { // If second value is undefined the rating is < 10 (on criticker) // and will be changed to 1 because you can't rate 0 on IMDb rating = "1"; } $("#filmList").append(rating + "," + m[3] + "\n"); } } function handleImport(evt) { var files = evt.target.files; var file = files[0]; var reader = new FileReader(); reader.onload = function(event){ var file = event.target.result; var format = $("select[name=import]").val(); if(format === "none") { alert("Select importer and try again."); return; } else if(format === "imdb") { processImdb(file); } else if(format === "rym") { processRym(file); } else if(format === "criticker") { processCriticker(file); } } reader.readAsText(file); } var ListManager = { regex: "^(.*)$", processRegex: function(rx, cb) { var filmTitle = rx[1]; cb(filmTitle); }, handleSelection: function(imdbId, cb) { cb(); } }; var RatingManager = { rating: 0, regex: "^([1-9]{1}|10),(.*)$", processRegex: function(rx, cb) { RatingManager.rating = rx[1]; var filmTitle = rx[2]; cb(filmTitle); }, handleSelection: function(imdbId, cb) { console.log("RatingManager::handleSelection: Rating " + imdbId); $.get("http://www.imdb.com/title/" + imdbId, function(data) { var authHash = $(data).find("#star-rating-widget").data("auth"); var params = {tconst: imdbId, rating: RatingManager.rating, auth: authHash, tracking_tag: "list", pageId: imdbId, pageType: "title", subPageType: "main"}; $.post("http://www.imdb.com/ratings/_ajax/title", params, function(data) { if(data.status !== 200) { alert("Rating failed. Status code " + data.status); } else { cb(); } }, "json"); }); } }; var App = { manager: ListManager, films: [], regexObj: null, isEmpty: function() { return App.films.length === 0; }, next: function() { return App.films.shift(); }, run: function() { var textEdit = '
Import mode:List' + 'Ratings
' + '