From 2e81abb3bc2237dabfaeccebdbe19fafea1a8ed3 Mon Sep 17 00:00:00 2001 From: kilo Date: Mon, 17 Jul 2017 22:05:49 +0200 Subject: [PATCH] Automatically add flag based on keyword (#1219) * add VOSTFR * Update kilo.js * debounce * add [eng] keyword * add [jp] keyword * add [jpn] keyword * add ' eng ' and '[english]' --- public/js/kilo.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/public/js/kilo.js b/public/js/kilo.js index cf814128..2183b193 100644 --- a/public/js/kilo.js +++ b/public/js/kilo.js @@ -101,10 +101,30 @@ var Kilo = function (params) { var el = e.target self.setRemake(el.checked) } + var updatePreviewTorrentName = function (e) { var el = e.target self.setName(el.value) + addKeywordFlags(el.value); } + + var addKeywordFlags = debounce(function(e) { + var Keywords_flags= [ + ["vostfr","vosfr", "[ita]", "[eng]", " eng ", "[english]", "[jp]", "[jpn]"], + ["fr","fr", "it", "en", "en", "en", "ja", "ja"]; + + var torrentLowerCaseName = e.toLowerCase(), + updateLang = false; + + for(var KeywordIndex = 0; KeywordIndex < Keywords_flags[0].length; KeywordIndex++) + if(torrentLowerCaseName.includes(Keywords_flags[0][KeywordIndex])) { + document.getElementById("upload-lang-" + Keywords_flags[1][KeywordIndex]).checked = true; + updateLang = true; + } + + if(updateLang) updateTorrentLang(); + }, 300); + var updateHidden = function (e) { var el = e.target self.setHidden(el.checked) @@ -132,4 +152,19 @@ var Kilo = function (params) { document.getElementsByClassName('table-torrent-flag')[0].className = 'table-torrent-flag flag flag-' + langCat document.getElementsByClassName('table-torrent-flag')[0].title = langTitle } -} \ No newline at end of file +} + +function debounce(func, wait, immediate) { + var timeout; + return function() { + var context = this, args = arguments; + var later = function() { + timeout = null; + if (!immediate) func.apply(context, args); + }; + var callNow = immediate && !timeout; + clearTimeout(timeout); + timeout = setTimeout(later, wait); + if (callNow) func.apply(context, args); + }; +};