-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IMDB Autocomplete extension code added
- Loading branch information
Showing
6 changed files
with
1,055 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.ac_results { | ||
padding: 0px; | ||
border: 1px solid black; | ||
background-color: white; | ||
overflow: hidden; | ||
z-index: 99999; | ||
} | ||
|
||
.ac_results ul { | ||
width: 100%; | ||
list-style-position: outside; | ||
list-style: none; | ||
padding: 0 !important; | ||
margin: 0; | ||
} | ||
|
||
.ac_results li { | ||
margin: 0px; | ||
padding: 4px 5px; | ||
cursor: default; | ||
display: block; | ||
font: menu; | ||
font-size: 12px; | ||
line-height: 16px; | ||
overflow: hidden; | ||
} | ||
|
||
.ac_results .acyr { | ||
float: right; | ||
} | ||
|
||
.ac_loading { | ||
background: white url('indicator.gif') right center no-repeat; | ||
} | ||
|
||
.ac_odd { | ||
background-color: #eee; | ||
} | ||
|
||
.ac_over { | ||
background-color: #CCBB00; | ||
color: black; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
(function(){ | ||
var data = { | ||
"Link - IMDB Top 250": {type: "Link", name: "IMDB Top 250", url: "/chart/top", year:""}, | ||
}; | ||
|
||
var arr = [], db = localStorage.getItem("imdbac") || "{}"; | ||
db = JSON.parse(db); | ||
function populateDb() { | ||
//Top 250 Page | ||
if(window.location.pathname.indexOf("/chart/top") !== -1) { | ||
var trArray = $("#root #main table tr"); | ||
$(trArray).each(function(index, ele) { | ||
if(index) { | ||
var name = $(ele).find("td").eq(2).find("a").text(); | ||
var url = $(ele).find("td").eq(2).find("a").attr("href"); | ||
var yearText = $(ele).find("td").eq(2).text(); | ||
var l = yearText.length; | ||
var year = yearText.substr(l-5, 4); | ||
insertIntoDb("Movie", name, url, year); | ||
} | ||
}); | ||
} | ||
// Movie Page | ||
if(window.location.pathname.indexOf("/title/") !== -1) { | ||
var splt = $("#tn15title h1").text().split(" ("); | ||
var name = splt[0]; | ||
var url = window.location.pathname; | ||
var year = splt[1].split(")") [0]; | ||
insertIntoDb("Movie", name, url, year); | ||
|
||
//Director | ||
$("#director-info a").each(function(index, node) { | ||
insertIntoDb("Person", $(node).text(), $(node).attr("href"), null); | ||
}); | ||
|
||
//Cast | ||
$("#tn15main .cast .nm a").each(function(index, node) { | ||
insertIntoDb("Person", $(node).text(), $(node).attr("href"), null); | ||
}); | ||
} | ||
//Person Page | ||
if(window.location.pathname.indexOf("/name/") !== -1) { | ||
var name = $("#tn15title h1").text().split(" More at") [0]; | ||
var url = window.location.pathname; | ||
insertIntoDb("Person", name, url, null); | ||
} | ||
} | ||
populateDb(); | ||
function insertIntoDb(type, name, url, year) { | ||
if(!db[type + " - " + name + (year?(" - "+year):"")]) { | ||
var k = {}; | ||
k[type + " - " + name + (year?(" - "+year):"")] = { | ||
type: type, | ||
name: name, | ||
url: url, | ||
year: year | ||
} | ||
db = $.extend(db, k) | ||
} | ||
} | ||
|
||
localStorage.setItem("imdbac", JSON.stringify(db)); | ||
db = jQuery.extend(db, data); | ||
var arr = []; | ||
$.each(db, function(k, v){ | ||
arr.push(v); | ||
}); | ||
|
||
var imdbSearch = $("form input[name=q]"); | ||
imdbSearch.addClass("imdbac"); | ||
imdbSearch.attr("autocomplete", "off"); | ||
imdbSearch.autocomplete(arr, { | ||
formatMatch: function(item) { | ||
return item.name | ||
}, | ||
formatItem: function(item) { | ||
var y = item.year; | ||
return item.name + (y?("<span class='acyr'>"+y+"</span>"):""); | ||
}, | ||
matchContains: true | ||
}).result(function(event, item) { | ||
location.href = "http://www.imdb.com" + item.url; | ||
}); | ||
}()); |
Oops, something went wrong.