i need uncheck many files from this HTML
with JQuery
HTML:
<div class="well">
<h2>Select you files</h2>
<table id="list-files" class="table table-bordered table-striped table-condensed table-hover">
<tbody>
<tr>
<th width="10px"><input type="checkbox" id="select-all-files" checked="checked"></th>
<th>File</th>
<th>Size</th>
</tr>
<tr class="selectedFiles" style="display: table-row;">
<td><input type="checkbox" name="files[]" value="0" checked=""></td>
<td>
<div><span class="pull-left">The.Blind.Side.2009.1080p.BluRay.x264.DTS-FGT/</span><span style="padding-top:1px;padding: 0 2px;display:block;overflow:hidden"><input style="width:100%;color:#c8c8c8;background-color:transparent;padding:0px;margin:0px" type="text" name="rename[0]" value="Visit thist Web.com.txt"></span></div>
</td>
<td>34.0 iB</td>
</tr>
<tr class="selectedFiles" style="display: table-row;">
<td><input type="checkbox" name="files[]" value="1" checked=""></td>
<td>
<div><span class="pull-left">The.Blind.Side.2009.1080p.BluRay.x264.DTS-FGT/</span><span style="padding-top:1px;padding: 0 2px;display:block;overflow:hidden"><input style="width:100%;color:#c8c8c8;background-color:transparent;padding:0px;margin:0px" type="text" name="rename[1]" value="The.Blind.Side.2009.1080p.BluRay.x264.DTS-FGT.mkv"></span></div>
</td>
<td>8.8 GiB</td>
</tr>
<tr class="selectedFiles" style="display: table-row;">
<td><input type="checkbox" name="files[]" value="2" checked=""></td>
<td>
<div><span class="pull-left">The.Blind.Side.2009.1080p.BluRay.x264.DTS-FGT/</span><span style="padding-top:1px;padding: 0 2px;display:block;overflow:hidden"><input style="width:100%;color:#c8c8c8;background-color:transparent;padding:0px;margin:0px" type="text" name="rename[2]" value="The.Blind.Side.2009.1080p.BluRay.x264.DTS-FGT.nfo"></span></div>
</td>
<td>5.4 KiB</td>
</tr>
</tbody>
</table>
</div>
SCRIPT:
var inp=$("tr input");
var r="Visit thist Web.com.txt";
for (i = 0; i < inp.length; i++) {
if(inp[i].value == r){
inp[i-1].checked = false;
}
}
How to improve this code?
This script
uncheck only var r="Visit thist Web.com.txt";
and i need uncheck all files with .txt! it's true this example only has one .txt, but that usually changes, even the order.
I would also like to unmark files with .nfo, .url, jpg, gif that's why I suppose it would be best to do it with regex
for tampermonkey
on chrome
Thank
You can use the Jquery filter
function with a regex. The regex:
/\.txt$/gi
The regex will match the literal string: '.txt'
at the end.
How to use:
var inp=$("tr input").filter( function (index)
{
return /\.txt$/gi.test($(this).val());
}).closest('tr').find('td:first-child input').prop('checked', false);
This will set the checked property to false on matched elements.
To uncheck other file types, you can change the regex to:
/\.txt$|\.nfo$|\.url$|\.jpg$|\.gif$/gi
Edit: I have studied your html a bit closer and changed my code, hope it Works now.
Edit2:
Actually you can also use your original code extended to include regex:
var inp=$("tr input");
var regex = /\.txt$|\.nfo$|\.url$|\.jpg$|\.gif$/gi;
for (i = 0; i < inp.length; i++) {
if (regex.test(inp[i].value)) {
inp[i-1].checked = false;
}
}