How to rename text with JQuery?

0

I want to replace certain characters and I do not know how to do it automatically with Tampermonkey. The ideal is to do it with jquery

HTML :

<div class="panel-body" data-loading-overlay="" style="">
<table id="list-files" class="table table-striped table-condensed table-hover">
<thead>
<tr>
<th width="35">
<div class="checkbox-custom checkbox-default">
<input type="checkbox" id="select-all-files" checked="">
<label for="select-all-files"></label>
</div>
</th>
<th>File</th>
<th>Size</th>
</tr>
</thead>
<tbody><tr><td><div class="checkbox-custom checkbox-default"><input name="files[]" checked="" type="checkbox" value="0"><label></label></div></td><td class="pt-none pb-none"><div><div class="pull-left mt-xs mr-xs">*NOEDITABLE*Rambo-First.Blood.1982.Multi.2160p.UHD Bluray.x265.HDR.DTS.5.1-DTOne / </div><div style="overflow:hidden"><input class="form-control input-sm m-none" style="background-color: transparent" type="text" name="rename[0]" value="Rambo-First Blood (1982) Multi 2160p UHD Bluray x265 HDR DTS 5.1-DTOne.mkv"></div></div></td><td>14.5 GiB</td></tr><tr><td><div class="checkbox-custom checkbox-default"><input name="files[]" checked="" type="checkbox" value="1"><label></label></div></td><td class="pt-none pb-none"><div><div class="pull-left mt-xs mr-xs">*NOEDITABLE*Rambo-First.Blood.1982.Multi.2160p.UHD Bluray.x265.HDR.DTS.5.1-DTOne / </div><div style="overflow:hidden"><input class="form-control input-sm m-none" style="background-color: transparent" type="text" name="rename[1]" value="A DT0ne Release !!!.txt"></div></div></td><td>287.0 iB</td></tr><tr><td><div class="checkbox-custom checkbox-default"><input name="files[]" checked="" type="checkbox" value="2"><label></label></div></td><td class="pt-none pb-none"><div><div class="pull-left mt-xs mr-xs">*NOEDITABLE*Rambo-First.Blood.1982.Multi.2160p.UHD Bluray.x265.HDR.DTS.5.1-DTOne / </div><div style="overflow:hidden"><input class="form-control input-sm m-none" style="background-color: transparent" type="text" name="rename[2]" value="File downloaded from TheSite.tv.txt"></div></div></td><td>28.0 iB</td></tr></tbody>
</table>
<div class="loading-overlay" style="background-color: rgba(0, 0, 0, 0); border-radius: 0px 0px 5px 5px;"><div class="bounce-loader"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div></div></div>

Here what I try to do is to replace some characters but only those that correspond to the editable boxes, not what would be HTML but what one can manipulate, eg concrete:

UN EDITED:     value="Rambo-First Blood (1982) Multi 2160p UHD Bluray x265 HDR DTS 5.1-DTOne.mkv"

EDITED:

value="Rambo-First.Blood.1982.ENg-Multi.2160p.Bluray.x265.HDR.DTS.5.1-DTOne.mkv"

In this case the script should only manipulate the editable boxes ..

Mi'script':

$(function(){
  var label_text = $('#list-files').text();

  $('#list-files').text( label_text.replace("(Multi)", "(ENg-Multi)") );
})
//También reemplazaría los espacios por puntos, quitaría los parentesis, etc.

Since it is wrong and it breaks everything, it is clear that it has to be more specific and that is where I can not find it back.

I look forward to your help and it does not matter other methods to achieve it as long as they are with JQuery

    
asked by Stack_qwerty 17.11.2018 в 21:42
source

2 answers

1

You can do it using a regular expression:

// remplazo 

function strRemove(str){
	return str.replace(/[\. ,():-]+/g, ".");
}

var str="Rambo-First Blood (1982) Multi 2160p UHD Bluray x265 HDR DTS 5.1-DTOne.mkv";
alert(strRemove(str));
    
answered by 17.11.2018 в 22:13
1

You can do it in two steps too:

  

get the text of the object $('selector').val() and assign it to a variable, then apply a regex to that variable.

var str = "Visit Microsoft!";
var res = str.replace(/microsoft/i, "W3Schools");
    
answered by 18.11.2018 в 02:10