Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Radarr] Bulk Import: Compare and Highlight
javascript:var bulkConfig={path:"/movies/",good:0.95,okay:0.75};jQuery.getScript("http://glench.github.io/fuzzyset.js/lib/fuzzyset.js",function(){var e=jQuery;var g=bulkConfig.path;var b=bulkConfig.good;var f=bulkConfig.okay;var c="rgba(0, 255, 0, 0.2)";var a="rgba(255, 255, 0, 0.2)";var d="rgba(255, 0, 0, 0.2)";e("div#x-movies-bulk table tbody tr").each(function(){var i=e(this).find(".series-title-cell");var m=e(i[0]);var j=e(i[1]);var h=m.find("a").text().trim();var l=j.clone().children().remove().end().text().replace(g,"").trim();cleaner=/[^a-z0-9]/ig;h=h.replace(cleaner,"");l=l.replace(cleaner,"");fz=FuzzySet([h]);score=fz.get(l)[0][0];if(!m.find(".score").length){m.append('<span><br><em>Match: <span class="score"></span>%</em></span>')}m.find(".score").text(Math.round(score*100));var k=true;if(score>=b){e(this).css("background-color",c)}else{if(score>=f){e(this).css("background-color",a)}else{k=false;e(this).css("background-color",d)}}$select=e(this).find(".select-row-cell input");if($select.prop("checked")!=k){$select.click()}})});
var bulkConfig = {
path: '/movies/',
good: 0.95,
okay: 0.75
}
jQuery.getScript('http://glench.github.io/fuzzyset.js/lib/fuzzyset.js', function() {
var $ = jQuery
var moviePath = bulkConfig.path
var scoreGood = bulkConfig.good
var scoreOk = bulkConfig.okay
var colorGood = 'rgba(0, 255, 0, 0.2)'
var colorOkay = 'rgba(255, 255, 0, 0.2)'
var colorBad = 'rgba(255, 0, 0, 0.2)'
$('div#x-movies-bulk table tbody tr').each(function() {
var cells = $(this).find('.series-title-cell')
var $movie = $(cells[0])
var $path = $(cells[1])
var movie = $movie.find('a').text().trim()
var path = $path.clone().children().remove().end().text()
.replace(moviePath, '').trim()
cleaner = /[^a-z0-9]/ig
movie = movie.replace(cleaner, '')
path = path.replace(cleaner, '')
fz = FuzzySet([movie])
score = fz.get(path)[0][0]
if (!$movie.find('.score').length) {
$movie.append('<span><br><em>Match: <span class="score"></span>%</em></span>')
}
$movie.find('.score').text(Math.round(score * 100))
var selected = true
if (score >= scoreGood) {
$(this).css('background-color', colorGood)
} else if (score >= scoreOk) {
$(this).css('background-color', colorOkay)
} else {
selected = false
$(this).css('background-color', colorBad)
}
$select = $(this).find('.select-row-cell input')
if ($select.prop('checked') != selected) {
$select.click()
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment