Last active
May 18, 2018 11:39
-
-
Save avalanchy/e6d0dc929a1259b903f23c017ba36fb0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ==UserScript== | |
// @name 1337x.to search results have filmweb links | |
// @include http://1337x.to/* | |
// @version 0.1 | |
// @description Add new column in search results that target to Filmweb's movie page. | |
// @author avalanchy | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// add new column with "filmweb" as a header | |
$('thead tr').append('<th>filmweb</th>'); | |
// take selector to all rows from search result | |
var rows = $('tbody tr'); | |
// iterate over rows | |
for (var i=0;i<rows.length;i++) { | |
// bypass closure | |
(function (i) { | |
// take single row | |
var row = $(rows[i]); | |
// take torrent title | |
var raw_title = row.find('.name').text(); | |
// try to parse movie title | |
var title = raw_title.match(/[\w ]+/)[0]; | |
// ask filmweb for the movie ID | |
// .done will be called when the response will came back | |
$.get('http://www.filmweb.pl/search/live?q=' + title) | |
// When the response comes back: | |
.done(function (response) { | |
// parse movie id | |
var id_match = response.match(/\d+/); | |
// oops, no match in filmweb? | |
if (id_match === null) { | |
// let's at least write a dash | |
row.append('<td>-</td>'); | |
// print in console not matched title | |
console.log('Movie not matched in filmweb: ' + title); | |
// bye bye | |
return; | |
} | |
// there is a movie matched! | |
var id = id_match[0]; | |
// generate movie url | |
var url = 'http://www.filmweb.pl/film/-0-' + id; | |
// let's write id with url | |
row.append('<td><a href="'+ url +'">'+ id +'</a></td>'); | |
} | |
); | |
})(i); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment