User blog:Benjaminthewill123123/Adding AJAX to this code

First off I want to add AJAX to the code below so It doesn't refresh the page once it's done but rather adds a confirmation message to the button once it is done removing the red links. I have no idea how to begin, I have tried combining it with other AJAX scripts such as Quick delete and AJAX RC with no luck. Any help would be appreciated! ​/******************************************************/ /* Red Link Fixer                                    */ /* Idea by Madnessfan34537                           */ /* Code by Madnessfan34537 and Monchoman45           */ /******************************************************/ $( '#WikiHeader' ) .append ( '\' Processing...\' ; FixRedlinks;">Fix redlinks' ) ; <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">function FixRedlinks<span class="br0" style="color:rgb(0,153,0);">( <span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{ $.<span class="me1" style="color:rgb(102,0,102);">getJSON <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);">'/api.php?action=query&prop=revisions&titles=' <span class="sy0" style="color:rgb(51,153,51);">+ wgPageName <span class="sy0" style="color:rgb(51,153,51);">+ <span class="st0" style="color:rgb(51,102,204);">'&rvprop=content&indexpageids=1&format=json' <span class="sy0" style="color:rgb(51,153,51);">, <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">function <span class="br0" style="color:rgb(0,153,0);">( result<span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{                     <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var text <span class="sy0" style="color:rgb(51,153,51);">= result.<span class="me1" style="color:rgb(102,0,102);">query .<span class="me1" style="color:rgb(102,0,102);">pages <span class="br0" style="color:rgb(0,153,0);">[ result.<span class="me1" style="color:rgb(102,0,102);">query .<span class="me1" style="color:rgb(102,0,102);">pageids <span class="br0" style="color:rgb(0,153,0);">[ <span class="nu0" style="color:rgb(204,0,0);">0 <span class="br0" style="color:rgb(0,153,0);">] <span class="br0" style="color:rgb(0,153,0);">] .<span class="me1" style="color:rgb(102,0,102);">revisions <span class="br0" style="color:rgb(0,153,0);">[ <span class="nu0" style="color:rgb(204,0,0);">0 <span class="br0" style="color:rgb(0,153,0);">] <span class="br0" style="color:rgb(0,153,0);">[ <span class="st0" style="color:rgb(51,102,204);">'*' <span class="br0" style="color:rgb(0,153,0);">] <span class="sy0" style="color:rgb(51,153,51);">; <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var redlinks <span class="sy0" style="color:rgb(51,153,51);">= $<span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);">'a.new' <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">; <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var ref <span class="sy0" style="color:rgb(51,153,51);">= <span class="nu0" style="color:rgb(204,0,0);">0 <span class="sy0" style="color:rgb(51,153,51);">; while<span class="br0" style="color:rgb(0,153,0);">( text.<span class="me1" style="color:rgb(102,0,102);">indexOf <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);"> <span class="sy0" style="color:rgb(51,153,51);">, ref<span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">!= <span class="sy0" style="color:rgb(51,153,51);">- <span class="nu0" style="color:rgb(204,0,0);">1 <span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{                             <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">if <span class="br0" style="color:rgb(0,153,0);">( text.<span class="me1" style="color:rgb(102,0,102);">indexOf <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);"> <span class="sy0" style="color:rgb(51,153,51);">, text.<span class="me1" style="color:rgb(102,0,102);">indexOf <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);">'[[' <span class="sy0" style="color:rgb(51,153,51);">, ref<span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">!= <span class="sy0" style="color:rgb(51,153,51);">- <span class="nu0" style="color:rgb(204,0,0);">1 <span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var open <span class="sy0" style="color:rgb(51,153,51);">= text.<span class="me1" style="color:rgb(102,0,102);">indexOf <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);"> <span class="sy0" style="color:rgb(51,153,51);">, open<span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var close <span class="sy0" style="color:rgb(51,153,51);">= text.<span class="me1" style="color:rgb(102,0,102);">indexOf <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);"> <span class="sy0" style="color:rgb(51,153,51);">, open<span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">if <span class="br0" style="color:rgb(0,153,0);">( text.<span class="me1" style="color:rgb(102,0,102);">indexOf <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);">' ' <span class="sy0" style="color:rgb(51,153,51);">, open<span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">!= <span class="sy0" style="color:rgb(51,153,51);">- <span class="nu0" style="color:rgb(204,0,0);">1 <span class="sy0" style="color:rgb(51,153,51);">&& text.<span class="me1" style="color:rgb(102,0,102);">indexOf <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);">' ' <span class="sy0" style="color:rgb(51,153,51);">, open<span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">< close<span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{ ref <span class="sy0" style="color:rgb(51,153,51);">= open <span class="sy0" style="color:rgb(51,153,51);">+ <span class="nu0" style="color:rgb(204,0,0);">1 <span class="sy0" style="color:rgb(51,153,51);">; <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">continue <span class="sy0" style="color:rgb(51,153,51);">; <span class="br0" style="color:rgb(0,153,0);">}                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">if <span class="br0" style="color:rgb(0,153,0);">( pipe <span class="sy0" style="color:rgb(51,153,51);">!= <span class="sy0" style="color:rgb(51,153,51);">- <span class="nu0" style="color:rgb(204,0,0);">1 <span class="sy0" style="color:rgb(51,153,51);">&& pipe <span class="sy0" style="color:rgb(51,153,51);">< close<span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{ <span class="co1" style="font-style:italic;color:rgb(0,102,0);">//is display                                              <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">if <span class="br0" style="color:rgb(0,153,0);">( pipe <span class="sy0" style="color:rgb(51,153,51);">== close <span class="sy0" style="color:rgb(51,153,51);">- <span class="nu0" style="color:rgb(204,0,0);">1 <span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{                                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var title <span class="sy0" style="color:rgb(51,153,51);">= text.<span class="me1" style="color:rgb(102,0,102);">substring <span class="br0" style="color:rgb(0,153,0);">( open <span class="sy0" style="color:rgb(51,153,51);">+ <span class="nu0" style="color:rgb(204,0,0);">2 <span class="sy0" style="color:rgb(51,153,51);">, pipe<span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;                                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var display <span class="sy0" style="color:rgb(51,153,51);">= title.<span class="me1" style="color:rgb(102,0,102);">substring <span class="br0" style="color:rgb(0,153,0);">( title.<span class="me1" style="color:rgb(102,0,102);">indexOf <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);">':' <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">+ <span class="nu0" style="color:rgb(204,0,0);">1 <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;                                              <span class="br0" style="color:rgb(0,153,0);">}                                              <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">else <span class="br0" style="color:rgb(0,153,0);">{                                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var title <span class="sy0" style="color:rgb(51,153,51);">= text.<span class="me1" style="color:rgb(102,0,102);">substring <span class="br0" style="color:rgb(0,153,0);">( open <span class="sy0" style="color:rgb(51,153,51);">+ <span class="nu0" style="color:rgb(204,0,0);">2 <span class="sy0" style="color:rgb(51,153,51);">, pipe<span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;                                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var display <span class="sy0" style="color:rgb(51,153,51);">= text.<span class="me1" style="color:rgb(102,0,102);">substring <span class="br0" style="color:rgb(0,153,0);">( pipe <span class="sy0" style="color:rgb(51,153,51);">+ <span class="nu0" style="color:rgb(204,0,0);">1 <span class="sy0" style="color:rgb(51,153,51);">, close<span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;                                              <span class="br0" style="color:rgb(0,153,0);">}                                      <span class="br0" style="color:rgb(0,153,0);">}                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">else <span class="br0" style="color:rgb(0,153,0);">{ <span class="co1" style="font-style:italic;color:rgb(0,102,0);">//is page                                              <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var title <span class="sy0" style="color:rgb(51,153,51);">= text.<span class="me1" style="color:rgb(102,0,102);">substring <span class="br0" style="color:rgb(0,153,0);">( open <span class="sy0" style="color:rgb(51,153,51);">+ <span class="nu0" style="color:rgb(204,0,0);">2 <span class="sy0" style="color:rgb(51,153,51);">, close<span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;                                              <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var display <span class="sy0" style="color:rgb(51,153,51);">= title<span class="sy0" style="color:rgb(51,153,51);">;                                      <span class="br0" style="color:rgb(0,153,0);">}                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">if <span class="br0" style="color:rgb(0,153,0);">( <span class="sy0" style="color:rgb(51,153,51);">! title<span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{ ref <span class="sy0" style="color:rgb(51,153,51);">= open <span class="sy0" style="color:rgb(51,153,51);">+ <span class="nu0" style="color:rgb(204,0,0);">1 <span class="sy0" style="color:rgb(51,153,51);">; <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">continue <span class="sy0" style="color:rgb(51,153,51);">; <span class="br0" style="color:rgb(0,153,0);">} <span class="co1" style="font-style:italic;color:rgb(0,102,0);">//skip  and |                                       <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">for <span class="br0" style="color:rgb(0,153,0);">( <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var i <span class="sy0" style="color:rgb(51,153,51);">= <span class="nu0" style="color:rgb(204,0,0);">0 <span class="sy0" style="color:rgb(51,153,51);">; i <span class="sy0" style="color:rgb(51,153,51);">< redlinks.<span class="me1" style="color:rgb(102,0,102);">length <span class="sy0" style="color:rgb(51,153,51);">; i<span class="sy0" style="color:rgb(51,153,51);">++ <span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{                                              <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var utitle <span class="sy0" style="color:rgb(51,153,51);">= title<span class="br0" style="color:rgb(0,153,0);">[ <span class="nu0" style="color:rgb(204,0,0);">0 <span class="br0" style="color:rgb(0,153,0);">] .<span class="me1" style="color:rgb(102,0,102);">toUpperCase <span class="br0" style="color:rgb(0,153,0);">( <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">+ title.<span class="me1" style="color:rgb(102,0,102);">substring <span class="br0" style="color:rgb(0,153,0);">( <span class="nu0" style="color:rgb(204,0,0);">1 <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;                                              <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">if <span class="br0" style="color:rgb(0,153,0);">( redlinks<span class="br0" style="color:rgb(0,153,0);">[ i<span class="br0" style="color:rgb(0,153,0);">] .<span class="me1" style="color:rgb(102,0,102);">title .<span class="me1" style="color:rgb(102,0,102);">indexOf <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);">' (page does not exist)' <span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{ <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var redlink <span class="sy0" style="color:rgb(51,153,51);">= redlinks<span class="br0" style="color:rgb(0,153,0);">[ i<span class="br0" style="color:rgb(0,153,0);">] .<span class="me1" style="color:rgb(102,0,102);">title .<span class="me1" style="color:rgb(102,0,102);">substring <span class="br0" style="color:rgb(0,153,0);">( <span class="nu0" style="color:rgb(204,0,0);">0 <span class="sy0" style="color:rgb(51,153,51);">, redlinks<span class="br0" style="color:rgb(0,153,0);">[ i<span class="br0" style="color:rgb(0,153,0);">] .<span class="me1" style="color:rgb(102,0,102);">title .<span class="me1" style="color:rgb(102,0,102);">length <span class="sy0" style="color:rgb(51,153,51);">- <span class="nu0" style="color:rgb(204,0,0);">22 <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">; <span class="br0" style="color:rgb(0,153,0);">}                                              <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">else <span class="br0" style="color:rgb(0,153,0);">{ <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var redlink <span class="sy0" style="color:rgb(51,153,51);">= redlinks<span class="br0" style="color:rgb(0,153,0);">[ i<span class="br0" style="color:rgb(0,153,0);">] <span class="sy0" style="color:rgb(51,153,51);">; <span class="br0" style="color:rgb(0,153,0);">}                                              <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">if <span class="br0" style="color:rgb(0,153,0);">( utitle <span class="sy0" style="color:rgb(51,153,51);">== redlink <span class="sy0" style="color:rgb(51,153,51);">|| utitle <span class="sy0" style="color:rgb(51,153,51);">== <span class="st0" style="color:rgb(51,102,204);">':' <span class="sy0" style="color:rgb(51,153,51);">+ redlink<span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{                                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">if <span class="br0" style="color:rgb(0,153,0);">( pipe <span class="sy0" style="color:rgb(51,153,51);">== close <span class="sy0" style="color:rgb(51,153,51);">- <span class="nu0" style="color:rgb(204,0,0);">1 <span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{ <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var show <span class="sy0" style="color:rgb(51,153,51);">= title<span class="sy0" style="color:rgb(51,153,51);">; <span class="br0" style="color:rgb(0,153,0);">}                                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">else <span class="br0" style="color:rgb(0,153,0);">{ <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var show <span class="sy0" style="color:rgb(51,153,51);">= display<span class="sy0" style="color:rgb(51,153,51);">; <span class="br0" style="color:rgb(0,153,0);">}                                                      text <span class="sy0" style="color:rgb(51,153,51);">= text.<span class="me1" style="color:rgb(102,0,102);">substring <span class="br0" style="color:rgb(0,153,0);">( <span class="nu0" style="color:rgb(204,0,0);">0 <span class="sy0" style="color:rgb(51,153,51);">, open<span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">+ show <span class="sy0" style="color:rgb(51,153,51);">+ text.<span class="me1" style="color:rgb(102,0,102);">substring <span class="br0" style="color:rgb(0,153,0);">( close <span class="sy0" style="color:rgb(51,153,51);">+ <span class="nu0" style="color:rgb(204,0,0);">2 <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;                                                      <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">break <span class="sy0" style="color:rgb(51,153,51);">;                                              <span class="br0" style="color:rgb(0,153,0);">}                                      <span class="br0" style="color:rgb(0,153,0);">}                                      ref <span class="sy0" style="color:rgb(51,153,51);">= open <span class="sy0" style="color:rgb(51,153,51);">+ <span class="nu0" style="color:rgb(204,0,0);">2 <span class="sy0" style="color:rgb(51,153,51);">;                              <span class="br0" style="color:rgb(0,153,0);">}                              <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">else <span class="br0" style="color:rgb(0,153,0);">{ <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">break <span class="sy0" style="color:rgb(51,153,51);">; <span class="br0" style="color:rgb(0,153,0);">}                      <span class="br0" style="color:rgb(0,153,0);">}                      $.<span class="me1" style="color:rgb(102,0,102);">getJSON <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);">'/api.php?action=query&prop=info&titles=' <span class="sy0" style="color:rgb(51,153,51);">+ wgPageName <span class="sy0" style="color:rgb(51,153,51);">+ <span class="st0" style="color:rgb(51,102,204);">'&intoken=edit&indexpageids=1&format=json' <span class="sy0" style="color:rgb(51,153,51);">, <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">function <span class="br0" style="color:rgb(0,153,0);">( result<span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{                              <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">var token <span class="sy0" style="color:rgb(51,153,51);">= result.<span class="me1" style="color:rgb(102,0,102);">query .<span class="me1" style="color:rgb(102,0,102);">pages <span class="br0" style="color:rgb(0,153,0);">[ result.<span class="me1" style="color:rgb(102,0,102);">query .<span class="me1" style="color:rgb(102,0,102);">pageids <span class="br0" style="color:rgb(0,153,0);">[ <span class="nu0" style="color:rgb(204,0,0);">0 <span class="br0" style="color:rgb(0,153,0);">] <span class="br0" style="color:rgb(0,153,0);">] .<span class="me1" style="color:rgb(102,0,102);">edittoken <span class="sy0" style="color:rgb(51,153,51);">;                              $.<span class="me1" style="color:rgb(102,0,102);">post <span class="br0" style="color:rgb(0,153,0);">( <span class="st0" style="color:rgb(51,102,204);">'/api.php' <span class="sy0" style="color:rgb(51,153,51);">, <span class="br0" style="color:rgb(0,153,0);">{ action<span class="sy0" style="color:rgb(51,153,51);">: <span class="st0" style="color:rgb(51,102,204);">'edit' <span class="sy0" style="color:rgb(51,153,51);">, title<span class="sy0" style="color:rgb(51,153,51);">: wgPageName<span class="sy0" style="color:rgb(51,153,51);">, text<span class="sy0" style="color:rgb(51,153,51);">: text<span class="sy0" style="color:rgb(51,153,51);">, summary<span class="sy0" style="color:rgb(51,153,51);">: <span class="st0" style="color:rgb(51,102,204);">'Fixing redlinks' <span class="sy0" style="color:rgb(51,153,51);">, token<span class="sy0" style="color:rgb(51,153,51);">: token<span class="br0" style="color:rgb(0,153,0);">} <span class="sy0" style="color:rgb(51,153,51);">, <span class="kw1" style="font-weight:bold;color:rgb(0,0,102);">function <span class="br0" style="color:rgb(0,153,0);">( <span class="br0" style="color:rgb(0,153,0);">) <span class="br0" style="color:rgb(0,153,0);">{ window.<span class="me1" style="color:rgb(102,0,102);">location .<span class="me1" style="color:rgb(102,0,102);">reload <span class="br0" style="color:rgb(0,153,0);">( <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">; <span class="br0" style="color:rgb(0,153,0);">} <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;                      <span class="br0" style="color:rgb(0,153,0);">} <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;              <span class="br0" style="color:rgb(0,153,0);">} <span class="br0" style="color:rgb(0,153,0);">) <span class="sy0" style="color:rgb(51,153,51);">;      <span class="br0" style="color:rgb(0,153,0);">}