Advertisement
Kraust

xfaqs quick edit 09/30/2014

Sep 30th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        xfaqs quick edit
  3. // @namespace   Kraust
  4. // @description port of the new quick edit script
  5. // @version     1
  6. // @grant       none
  7. // ==/UserScript==
  8.  
  9. // This should work with posts after the "Message Board Overhaul" release.
  10. // Thanks to kirbymuncher for the initial code that helped me design this script.
  11. // If you're interested in more please check out xfaqs @ http://xfaqs.nostlagiasky.pw
  12.  
  13. // Changelog:
  14. // 2014-09-30: Script Created.
  15.  
  16.  
  17. var formatter = '<span class="tagbuttons"> \
  18.                     <input type="button"  value="Bold" class="btn btn_mini btnbold" name="b" tabindex="-1"> \
  19.                     <input type="button"  value="Italic" class="btn btn_mini btnitalic" name="i" tabindex="-1"> \
  20.                     <input type="button"  value="Spoiler" class="btn btn_mini" name="spoiler" tabindex="-1"> \
  21.                     <input type="button"  value="Cite" class="btn btn_mini btncite" name="cite" tabindex="-1"> \
  22.                     <input type="button"  value="Quote" class="btn btn_mini" name="quote" tabindex="-1"> \
  23.                     <input type="button"  value="Code" class="btn btn_mini btncode" name="code" tabindex="-1"> \
  24.                 </span>';
  25.  
  26. var user = $(".welcome").text().slice(0, -1);
  27. var msgCount = $("td.msg").length;
  28. var reg = /\/(\d+)/g;
  29. var boardID = reg.exec(location.href)[1];
  30. var topicID = reg.exec(location.href)[1];  
  31.  
  32. function editCallback(i, messageID) {
  33.     return function() {
  34.         var postUrl = "/boards/post.php?board=" + boardID + "&topic=" + topicID + "&message=" + messageID;
  35.         var msg = $('td.msg').eq(i).html();
  36.  
  37.         $.ajax({
  38.             type: "POST",
  39.             url: postUrl,
  40.             async: false
  41.         }).done(function(response) {
  42.             var content = $(response).find('.body').eq(0).html();
  43.             var textarea = $(response).find('.body textarea').eq(0);
  44.             $(textarea).css("width", "100%");
  45.             var key = response.match(/key" value="([^"]*)"/)[1];
  46.             //var sig = $("[name=custom_sig]").val();   xfaqs rotating sigs
  47.            
  48.            
  49.             $('td.msg').eq(i).html("<form id='qe-" + i + "' method='post' action='" + postUrl + "'><input type='hidden' value='" + key + "' name='key'><input type='hidden' value='Post without Preview' name='post'></form>");
  50.             $("#qe-" + i).append(textarea);
  51.             $("#qe-" + i).prepend(formatter);
  52.             //$("#qe-" + i).append("<textarea type='hidden' name='custom_sig' style='width:100%'>" + sig + "</textarea>"); xfaqs rotating sigs
  53.             $("#qe-" + i).append("<div style='display:block'><button class='btn btn_primary' id='editBtn-" + i + "'>Edit</button> <button class='btn' id='cancelBtn-" + i + "'>Cancel</button></div>");
  54.            
  55.            
  56.             $('[name="b"]').click(function() {txtTagEdit('b');});
  57.             $('[name="i"]').click(function() {txtTagEdit('i');});
  58.             $('[name="spoiler"]').click(function() {txtTagEdit('spoiler');});
  59.             $('[name="cite"]').click(function() {txtTagEdit('cite');});
  60.             $('[name="quote"]').click(function() {txtTagEdit('quote');});
  61.             $('[name="code"]').click(function() {txtTagEdit('code');});
  62.                        
  63.            
  64.             $("#cancelBtn-" + i).click(function() {
  65.                     $('td.msg').eq(i).html(msg);
  66.             });
  67.         }).error(function() {
  68.                     alert("Unable to edit post. This may be because you've edited your post the maximum amount of times, or your time limit has expired");
  69.         });;
  70.     }
  71.  
  72. }
  73.  
  74. for( var i = 0; i < msgCount; i++) {
  75.     if( user == $(".name").eq(i).text() ) {
  76.         var messageID = $(".msg_body").eq(i).attr('name');
  77.        
  78.         if($(".msg_stats_left").size() !== 0) {
  79.             $("a.qq").eq(i).after(" - <a class='edit-" + i + "'>edit</a>");
  80.         } else {
  81.             $("a.qq").eq(i).after(" | <a class='edit-" + i + "'>edit</a>");
  82.         }
  83.    
  84.         $(".edit-" + i).click(editCallback(i, messageID));
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement