Advertisement
Onyx3173

Dynasty Thingifier

Dec 8th, 2015
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 23.39 KB | None | 0 0
  1. // ==UserScript==
  2. // @name        Dynasty Thingifier
  3. // @namespace   Alice Cheshire
  4. // @include     http://dynasty-scans.com/*
  5. // @exclude     http://dynasty-scans.com/system/images_images/*
  6. // @version     2.0
  7. // @require     http://code.jquery.com/jquery-2.1.4.min.js
  8. // @description Adds post links and quote stuff to Dynasty forums
  9. // @grant       GM_setValue
  10. // @grant       GM_getValue
  11. // @grant       GM_deleteValue
  12. // @grant       GM_listValue
  13. // @run-at document-end
  14. // ==/UserScript==
  15. (function() {
  16.   "use strict";
  17.   var pageurl = document.location.toString().replace(/(#.+)/, ""), //Stores page url and removes any anchors from the stored url so we don't get issues with multiple anchors showing up
  18.       isuserpostsurl = document.location.toString(), //Stores the address variable a second time for use in a different function
  19.       postids = [], //Initializes a blank array for the postids
  20.       quote = [], //Initializes blank array for quotes
  21.       postcount = 0, //Counter to keep track of how many posts are on the current page
  22.       counter = 0,
  23.       configmenustate = GM_getValue("configmenustate", true), //Init our menu state's varaiable
  24.       yourid = GM_getValue("youruserid"), //Set our user id variable
  25.       fontsize = [3, "one", "two", "three", "four", "five"],
  26.       bbcode_menu = '<div id="thingifier-bbcode"><div class="thingifier-bbcode-first-row"><input type="button" id="thingifier-bbcode-quote" value="Quote"><input type="button" id="thingifier-bbcode-link" value="Link"><input type="button" id="thingifier-bbcode-image" value="Image"><input type="button" id="thingifier-bbcode-spoiler" value="Spoiler"><input type="button" id="thingifier-bbcode-ul" value="List"><input type="button" id="thingifier-bbcode-ol" value="Numbered List"><input type="button" id="thingifier-bbcode-italics" value="Italics"><input type="button" id="thingifier-bbcode-bold" value="Bold"></div><div class="thingifier-bbcode-second-row"><input type="button" id="thingifier-bbcode-tag" value="Tags"><input type="button" id="thingifier-bbcode-hr" value="Horizontal Rule"><input type="button" id="thingifier-bbcode-codeblock" value="Code Block"><input type="button" id="thingifier-bbcode-h1" value="H1"><input type="button" id="thingifier-bbcode-h2" value="H2"><input type="button" id="thingifier-bbcode-h3" value="H3"><input type="button" id="thingifier-bbcode-h4" value="H4"><input type="button" id="thingifier-bbcode-h5" value="H5"><input type="button" id="thingifier-bbcode-h6" value="H6"></div></div>', //The html code for our bbcode buttons
  27.       quickreply;
  28.  
  29.   init();
  30.  
  31.   //Initialize Script
  32.   function init() {
  33.     //Load our config
  34.     configload();
  35.  
  36.     //Populate Menu
  37.     $('body').append('<style> @import url(http://alice-cheshire.rocks/Dynasty%20Thingifier.css);</style>');
  38.     $('body').prepend('<div id="thingifier"></div>');
  39.     $('#thingifier').append('<div id="thingifier-options"></div>');
  40.     $('#thingifier-options').append('<ul><li><input type="checkbox" id="thingifier-unhide-spoilers"> Unhide spoilers</li></ul>');
  41.     $('#thingifier-options ul').append('<li><input type="checkbox" id="thingifier-fixed-navbar"> Fixed navbar</li>');
  42.     $('#thingifier-options ul').append('<li><input type="checkbox" id="thingifier-pagination"> Add page selector to top of page</li>');
  43.     $('#thingifier-options ul').append('<li><input type="checkbox" id="thingifier-bbcode-buttons"> Add quick reply and post page bbcode buttons</li>');
  44.     $('#thingifier-options ul').append('<li><input type="checkbox" id="thingifier-quote-to-quickreply"> Quote to quick reply instead of new post page</li>');
  45.     $('#thingifier-options ul').append('<li><input type="checkbox" id="thingifier-quote-move-quickreply"> Move quick reply to under quoted post</li>');
  46.     $('#thingifier-options ul').append('<li><input type="range" id="thingifier-font-size" min="1" max="5"> Change font size <input type="button" id="thingifier-reset-font" value="Reset Font Size"></li>');
  47.     $('#thingifier-options ul').append('<li><a href="http://dynasty-scans.com/forum/posts?user_id=' + yourid + '" id="thingifier-ownposts"> Your posts</a></li>');
  48.     $('#thingifier-options ul').append('<li><input type="text" id="useridinput"><input type="button" value="Submit user id" id="useridsubmit"></li>');
  49.     $('#thingifier-options ul').append('<li><input type="button" id="thingifier-clear" value="Clear stored data"></li>');
  50.     $('#thingifier').append('<div id="thingified-toggle"><input type="button" id="thingifier-toggle-button" value="X"></div>');
  51.  
  52.     //Setup own posts link stuff
  53.     $('#useridinput').hide();
  54.     $('#useridsubmit').hide();
  55.     if (GM_getValue("youruserid", "Not Set") == "Not Set") {
  56.       //GM_getValue("youruserid", "Not Set");
  57.       $('#thingifier-ownposts').hide();
  58.       $('#useridinput').show();
  59.       $('#useridsubmit').show();
  60.       setuserid();
  61.     }
  62.  
  63.     //Check we're viewing a thread
  64.     if (pageurl.match(/forum\/topics/)) {
  65.       $('.forum_post').each(function() {
  66.         postids.push(this.id); //For each element of the class forum_post push the element's id to our postids array
  67.       });
  68.       $('.time').each(function(i, obj) {
  69.         postcount++; //This is where we actually count how many posts are on the page
  70.       });
  71.  
  72.       //Retrieve your user id
  73.       if (GM_getValue("youruserid", "Not set").match(/\d+/)) {
  74.         console.log("Retrieved user id: " + GM_getValue("youruserid"));
  75.         yourid = "http://dynasty-scans.com/forum/posts?user_id=" + GM_getValue("youruserid");
  76.       } else {
  77.         console.log("User id not set!");
  78.         yourid = "Your user id isn't set!";
  79.       }
  80.       //console.log(JSON.stringify(postids));
  81.     }
  82.   }
  83.  
  84.   //Set user ID for own posts link
  85.   function setuserid() {
  86.     $('input#useridsubmit').click(function () {
  87.       console.log("User id submitted");
  88.       if($("input#useridinput").val().match(/^\d+$/)) {
  89.         GM_setValue("youruserid", $('input#useridinput').val());
  90.         $('#useridinput').hide();
  91.         $('#useridsubmit').hide();
  92.         $('#thingifier-ownposts').show();
  93.         $('#thingifier-ownposts').attr('href', "http://dynasty-scans.com/forum/posts?user_id=" + GM_getValue("youruserid"));
  94.       } else {
  95.         GM_deleteValue("youruserid");
  96.         $("input#useridinput").val();
  97.         $('input#useridinput').val("Invalid user id!");
  98.       }
  99.     });
  100.   }
  101.  
  102.  
  103.   //Menu close/open
  104.   $('input#thingifier-toggle-button').click(function() {
  105.     menuclose("click");
  106.   });
  107.  
  108.   //Unhide spoilers option
  109.   $('#thingifier-unhide-spoilers').click(function() {
  110.     if ($('#thingifier-unhide-spoilers').is(":checked")) {
  111.       $('.spoilers').addClass('spoilers-disabled');
  112.     } else {
  113.       $('.spoilers').removeClass('spoilers-disabled');
  114.     }
  115.     GM_setValue("spoilers", $('#thingifier-unhide-spoilers').is(":checked"));
  116.   });
  117.  
  118.   //Fixed navbar option
  119.   $('#thingifier-fixed-navbar').click(function() {
  120.     if ($('#thingifier-fixed-navbar').is(":checked")) {
  121.       GM_setValue("navbar", $('#thingifier-fixed-navbar').is(":checked"));
  122.       $('.navbar').addClass('navbar-fixed');
  123.       $('div.forum_post').css("padding-top", 40);
  124.       $("<div class=\"nav-padding\"></div>").insertAfter(".navbar");
  125.     } else {
  126.       GM_setValue("navbar", $('#thingifier-fixed-navbar').is(":checked"));
  127.       $('.navbar').removeClass('navbar-fixed');
  128.       $('div.forum_post').css("padding-top", 0);
  129.       $('div.nav-padding').remove();
  130.     }
  131.   });
  132.  
  133.   //Pagination option
  134.   $('#thingifier-pagination').click(function() {
  135.     if ($('#thingifier-pagination').is(":checked")) {
  136.       GM_setValue("pagination", $('#thingifier-pagination').is(":checked"));
  137.       $("div.pagination").wrap('<div class=\"tmp\">').parent().html();
  138.       var tmp = $('div.tmp').html();
  139.       $("div.pagination").unwrap();
  140.       $('#main').prepend(tmp);
  141.     } else {
  142.       GM_setValue("pagination", $('#thingifier-pagination').is(":checked"));
  143.       $("div.pagination").first().remove();
  144.     }
  145.   });
  146.  
  147.   //Add bbcode buttons to post page and quick reply
  148.   $('#thingifier-bbcode-buttons').click(function() {
  149.     if ($('#thingifier-bbcode-buttons').is(":checked")) {
  150.       GM_setValue("bbcode", $('#thingifier-bbcode-buttons').is(":checked"));
  151.       $("#forum_post_message").parent().prepend(bbcode_menu);
  152.     } else {
  153.       GM_setValue("bbcode", $('#thingifier-bbcode-buttons').is(":checked"));
  154.       $("div#thingifier-bbcode").remove();
  155.     }
  156.   });
  157.  
  158.   //Move the quick reply box to the current post
  159.   $('#thingifier-quote-move-quickreply').click(function() {
  160.     GM_setValue('movequickreply', $('#thingifier-quote-move-quickreply').is(":checked"));
  161.     quickreply = $('#thingifier-quote-move-quickreply').is(":checked");
  162.   });
  163.  
  164.   //Font size slider
  165.   $('#thingifier-font-size').on('input', function() {
  166.     fontsize[0] = parseInt($(this).val());
  167.     $('.message *').removeClass('forum_post_one');
  168.     $('.message *').removeClass('forum_post_two');
  169.     $('.message *').removeClass('forum_post_three');
  170.     $('.message *').removeClass('forum_post_four');
  171.     $('.message *').removeClass('forum_post_five');
  172.     $('.message *').addClass('forum_post_' + fontsize[fontsize[0]]);
  173.     GM_setValue('fontsize', fontsize[0]);
  174.   });
  175.  
  176.   //Reset font size
  177.   $('#thingifier-reset-font').click(function() {
  178.     $('.message *').removeClass('forum_post_one');
  179.     $('.message *').removeClass('forum_post_two');
  180.     $('.message *').removeClass('forum_post_three');
  181.     $('.message *').removeClass('forum_post_four');
  182.     $('.message *').removeClass('forum_post_five');
  183.     $('#thingifier-font-size').val(3);
  184.     GM_deleteValue('fontsize');
  185.   });
  186.  
  187.   //Clear saved data
  188.   $('#thingifier-clear').click(function() {
  189.     var x = window.confirm("Are you sure you want to clear your stored data?");
  190.     if (x) {
  191.       GM_deleteValue("youruserid");
  192.       GM_deleteValue("quoteid");
  193.       GM_deleteValue("quotename");
  194.       GM_deleteValue("spoilers");
  195.       GM_deleteValue("navbar");
  196.       GM_deleteValue("pagination");
  197.       GM_deleteValue("bbcode");
  198.       GM_deleteValue("quote2quickreply");
  199.       console.log(GM_getValue("youruserid", "Not set"));
  200.       console.log(GM_getValue("quoteid", "Not set"));
  201.       console.log(GM_getValue("quotename", "Not set"));
  202.       console.log(GM_getValue("spoilers", "Not set"));
  203.       console.log(GM_getValue("navbar", "Not set"));
  204.       console.log(GM_getValue("pagination", "Not set"));
  205.       console.log(GM_getValue("bbcode", "Not set"));
  206.       console.log(GM_getValue("quote2quickreply", "Not set"));
  207.       document.location.reload(true);
  208.     } else {
  209.       console.log("Decided against it");
  210.     }
  211.   });
  212.  
  213.   //Load our config
  214.   function configload() {
  215.     //Only run once the page is loaded
  216.     $(document).ready(function() {
  217.       //Deal with our current menu state
  218.       menuclose("load");
  219.  
  220.       //Check if spoilers are unhidden
  221.       if (!!GM_getValue("spoilers", false)) {
  222.         $('#thingifier-unhide-spoilers').click();
  223.       }
  224.  
  225.       //Check if the fixed navbar is enabled
  226.       if (!!GM_getValue("navbar", false)) {
  227.         $('#thingifier-fixed-navbar').click();
  228.       }
  229.  
  230.       //Check if pagination option is enabled
  231.       if (!!GM_getValue("pagination", false)) {
  232.         $('#thingifier-pagination').click();
  233.       }
  234.  
  235.       //Check if we've changed the font size and retrieve it
  236.       fontsize[0] = GM_getValue('fontsize', null);
  237.       if (fontsize[0] !== null) {
  238.         $('#thingifier-font-size').val(fontsize[0]);
  239.         $('.message *').addClass('forum_post_' + fontsize[fontsize[0]]);
  240.       }
  241.  
  242.       //Check if bbcode buttons are enabled
  243.       if (!!GM_getValue('bbcode', null)) {
  244.         $('#thingifier-bbcode-buttons').click();
  245.       }
  246.  
  247.       //Check if quote to quick reply option is enabled
  248.       if (!!GM_getValue('quote2quickreply', null)) {
  249.         $('#thingifier-quote-to-quickreply').click();
  250.       }
  251.  
  252.       //Check if the move quick reply box option is enabled
  253.       if (!!GM_getValue('movequickreply', null)) {
  254.         $('#thingifier-quote-move-quickreply').click();
  255.       }
  256.  
  257.       bbcode();
  258.     });
  259.   }
  260.  
  261.   function menuclose(sender) {
  262.     //Only runs when loading a page
  263.     if (sender === "load") {
  264.       configmenustate = GM_getValue("configmenustate", true); //Load our menu state
  265.       if (!configmenustate) { //If it's true collapse the menu
  266.         $("#thingifier-options").animate({width:'toggle', height:'toggle'},0);
  267.       }
  268.  
  269.       //Runs when clicking the button
  270.     } else if (sender === "click") {
  271.       configmenustate = !!configmenustate ? false : true; //XOR our menu state, can also use ^=
  272.       $("#thingifier-options").animate({width:'toggle', height:'toggle'},350); //Toggle the menu
  273.       GM_setValue("configmenustate", !!configmenustate); //Store the value
  274.     }
  275.  
  276.     //Controls the button's icon
  277.     if (!configmenustate) {
  278.       $('#thingifier-toggle-button').val('â–¶');
  279.     } else {
  280.       $('#thingifier-toggle-button').val('â—€');
  281.     }
  282.   }
  283.  
  284.   function bbcode() {
  285.     var texttmp,
  286.         sel,
  287.         posttmp,
  288.         regextmp,
  289.         txtbegin,
  290.         txtend;
  291.     $('#forum_post_message').mousedown(function() {
  292.       $('body').mouseup(function() {
  293.         getSel();
  294.         texttmp = sel;
  295.         posttmp = $('#forum_post_message').val();
  296.         regextmp = new RegExp("("+texttmp.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&")+")");
  297.         posttmp = posttmp.replace(regextmp, "[BBCODE-HERE]");
  298.       });
  299.     });
  300.     function getSel() // javascript
  301.     {
  302.       // obtain the object reference for the <textarea>
  303.       var txtarea = document.getElementById("forum_post_message");
  304.       // obtain the index of the first selected character
  305.       var start = txtarea.selectionStart;
  306.       // obtain the index of the last selected character
  307.       var finish = txtarea.selectionEnd;
  308.       // obtain the selected text
  309.       sel = txtarea.value.substring(start, finish);
  310.       txtbegin = txtarea.value.substring(0, start);
  311.       txtend = txtarea.value.substring(finish);
  312.       // do something with the selected content
  313.     }
  314.     $('#thingifier-bbcode-quote').click(function() {
  315.       texttmp = texttmp.replace(/(^\S)/gm, "> $1");
  316.       bbcode_format();
  317.     });
  318.     $('#thingifier-bbcode-link').click(function() {
  319.       if (sel.length === 0) {
  320.         texttmp = texttmp.replace(/(.*)/gm, "[]($1)");
  321.       } else {
  322.         texttmp = texttmp.replace(/(.+)/gm, "[]($1)");
  323.       }
  324.       bbcode_format();
  325.     });
  326.     $('#thingifier-bbcode-image').click(function() {
  327.       if (sel.length === 0) {
  328.         texttmp = texttmp.replace(/(.*)/gm, "![]($1)");
  329.       } else {
  330.         texttmp = texttmp.replace(/(.+)/gm, "![]($1)");
  331.       }
  332.       bbcode_format();
  333.     });
  334.     $('#thingifier-bbcode-spoiler').click(function() {
  335.       if (sel.length === 0) {
  336.         texttmp = texttmp.replace(/(.*)/gm, "==$1==");
  337.       } else {
  338.         texttmp = texttmp.replace(/(.+)/gm, "==$1==");
  339.       }
  340.       bbcode_format();
  341.     });
  342.     $('#thingifier-bbcode-hr').click(function() {
  343.       texttmp = texttmp.replace(/(^\S)/gm, "\n***\n $1");
  344.       bbcode_format();
  345.     });
  346.     $('#thingifier-bbcode-ul').click(function() {
  347.       texttmp = texttmp.replace(/(^\S)/gm, " * $1");
  348.       bbcode_format();
  349.     });
  350.     $('#thingifier-bbcode-ol').click(function() {
  351.       texttmp = texttmp.replace(/(^\S)/gm, " 1. $1");
  352.       bbcode_format();
  353.     });
  354.     $('#thingifier-bbcode-italics').click(function() {
  355.       if (sel.length === 0) {
  356.         texttmp = texttmp.replace(/(.*)/gm, "*$1*");
  357.       } else {
  358.         texttmp = texttmp.replace(/(.+)/gm, "*$1*");
  359.       }
  360.       bbcode_format();
  361.     });
  362.     $('#thingifier-bbcode-bold').click(function() {
  363.       if (sel.length === 0) {
  364.         texttmp = texttmp.replace(/(.*)/gm, "**$1**");
  365.       } else {
  366.         texttmp = texttmp.replace(/(.+)/gm, "**$1**");
  367.       }
  368.       bbcode_format();
  369.     });
  370.     $('#thingifier-bbcode-tag').click(function() {
  371.       if (sel.length === 0) {
  372.         texttmp = texttmp.replace(/(.*)/gm, "`$1`");
  373.       } else {
  374.         texttmp = texttmp.replace(/(.+)/gm, "`$1`");
  375.       }
  376.       bbcode_format();
  377.     });
  378.     $('#thingifier-bbcode-codeblock').click(function() {
  379.       if (sel.length === 0) {
  380.         texttmp = texttmp.replace(/(.*)/gm, "    $1    ");
  381.       } else {
  382.         texttmp = texttmp.replace(/(.+)/gm, "    $1    ");
  383.       }
  384.       bbcode_format();
  385.     });
  386.     $('#thingifier-bbcode-h1').click(function() {
  387.       if (sel.length === 0) {
  388.         texttmp = texttmp.replace(/(.*)/gm, "# $1 #");
  389.       } else {
  390.         texttmp = texttmp.replace(/(.+)/gm, "# $1 #");
  391.       }
  392.       bbcode_format();
  393.     });
  394.     $('#thingifier-bbcode-h2').click(function() {
  395.       if (sel.length === 0) {
  396.         texttmp = texttmp.replace(/(.*)/gm, "## $1 ##");
  397.       } else {
  398.         texttmp = texttmp.replace(/(.+)/gm, "## $1 ##");
  399.       }
  400.       bbcode_format();
  401.     });
  402.     $('#thingifier-bbcode-h3').click(function() {
  403.       if (sel.length === 0) {
  404.         texttmp = texttmp.replace(/(.*)/gm, "### $1 ###");
  405.       } else {
  406.         texttmp = texttmp.replace(/(.+)/gm, "### $1 ###");
  407.       }
  408.       bbcode_format();
  409.     });
  410.     $('#thingifier-bbcode-h4').click(function() {
  411.       if (sel.length === 0) {
  412.         texttmp = texttmp.replace(/(.*)/gm, "#### $1 ####");
  413.       } else {
  414.         texttmp = texttmp.replace(/(.+)/gm, "#### $1 ####");
  415.       }
  416.       bbcode_format();
  417.     });
  418.     $('#thingifier-bbcode-h5').click(function() {
  419.       if (sel.length === 0) {
  420.         texttmp = texttmp.replace(/(.*)/gm, "##### $1 #####");
  421.       } else {
  422.         texttmp = texttmp.replace(/(.+)/gm, "##### $1 #####");
  423.       }
  424.       bbcode_format();
  425.     });
  426.     $('#thingifier-bbcode-h6').click(function() {
  427.       if (sel.length === 0) {
  428.         texttmp = texttmp.replace(/(.*)/gm, "###### $1 ######");
  429.       } else {
  430.         texttmp = texttmp.replace(/(.+)/gm, "###### $1 ######");
  431.       }
  432.       bbcode_format();
  433.     });
  434.     function bbcode_format() {
  435.       var tmp = txtbegin + texttmp.replace(/\[BBCODE-HERE\]/, tmp) + txtend;
  436.       $('#forum_post_message').val(tmp);
  437.     }
  438.   }
  439.   $(document).ready(function() {
  440.     if (isuserpostsurl.match(/http:\/\/dynasty-scans.com\/forum\/posts\?user_id=\d+/)) {
  441.       isuserpostsurl = isuserpostsurl.replace(/\d+/, ""); //Replaces the user id in the url
  442.     }
  443.     for (var i = 0; i < postcount; i++){
  444.       counter = i;
  445.       var id = postids[i].toString(); //Temporarily store the post id under the key of 'i' into a variable to use in our next bit
  446.       if ($('#thingifier-quote-to-quickreply').is(":checked")) {
  447.         GM_setValue('quote2quickreply', $('#thingifier-quote-to-quickreply').is(":checked"));
  448.         var tmp = $('.forum_post .info .row .actions').find("span:first-child a");
  449.         var tmphref = tmp.attr('href');
  450.         var urltmp = document.location.toString();
  451.         urltmp = urltmp.replace(/(http:\/\/dynasty-scans\.com\/forum\/topics\/)(\d+)(.+)/, "$2");
  452.         $('.forum_post .info .row .actions:eq(' + counter + ')').prepend("<input type=\"button\" class=\"postquote\" id=\"" + tmphref + "\" value=\"Quick Quote\" name=\"post_" + counter + "\">");
  453.         //tmp.replaceWith("<input type=\"button\" class=\"postquote\" id=\"" + tmphref + "\" value=\"Quote\" name=\"post_" + counter + "\">");
  454.         id = id.replace(/forum_post_/, "");
  455.       }
  456.       if(isuserpostsurl !== "http://dynasty-scans.com/forum/posts?user_id=") {
  457.         $(".time").eq(i).replaceWith("<div class=\"span5 time\"><a class=\"timelink\" href=\"" + pageurl + "#forum_post_" + id + "\">" + $(".time").eq(i).text() + "</a></div>"); //If we're not on the user posts page then we turn all post timestamps on a page into an anchor link
  458.       }
  459.       counter++;
  460.     }
  461.     $('input.postquote').mouseup(function(e) {
  462.       var postid = $($(this).parents()[3]).attr('id');
  463.       var quoteid = postid; //Gets the id of the .forum_post parent
  464.       quoteid = "#" + quoteid; //Adds a url anchor sign to the id
  465.       quoteid = quoteid.toString(); //Converts it to a string to make sure it cooperates
  466.       GM_setValue("quoteid", pageurl + quoteid);
  467.       var quotename = $.trim($(quoteid).find(".user").text().replace(/Staff|Moderator|Uploader/, "")); //Retrieve the quoted user's name
  468.       //For staff, mods, and uploaders find and remove their title, then trim the whitespace/newlines off the beginning and end
  469.       GM_setValue("quotename", quotename);
  470.       postid = postid.replace(/forum_post_/, "");
  471.       var threadid = document.location.toString();
  472.       threadid = threadid.replace(/(http:\/\/dynasty-scans\.com\/forum\/topics\/)(\d+)(\S+)/, "$2");
  473.       var postpath = "http://dynasty-scans.com/forum/posts/new?quote_id=\"" + postid +"\"&topic_id=\"" + threadid + "\"";
  474.       postpath = postpath.replace(/"/g, "");
  475.       postid = postid.replace(/post_/, "");
  476.       $.ajax({
  477.         type: "GET",
  478.         url: postpath,
  479.         dataType: "html"
  480.       })
  481.       .done(function(data) {
  482.         quote[postid] = data.replace(/([\u0000-\uffff]+<textarea .+ id="forum_post_message".+>)([\u0000-\uffff]+)(<\/textarea>[\u0000-\uffff]+)/, "$2");
  483.         quote[postid] = htmlDecode(quote[postid]);
  484.         $('#forum_post_message').val(quote[postid]);
  485.         var post = GM_getValue("quoteid");
  486.         var username = GM_getValue("quotename");
  487.         quote = "> [" + username + "](" + post + ") \n> ";
  488.         var message = document.getElementById('forum_post_message').value;
  489.         document.getElementById('forum_post_message').value = quote + message;
  490.       })
  491.       .fail(function() {
  492.         console.log("error");
  493.       });
  494.       if (quickreply) {
  495.         var replybox;
  496.         if ($("#thingifier-quickreply").length < 1) {
  497.           $("#new_forum_post").wrap("<div id=\"thingifier-quickreply\"></div>");
  498.         }
  499.         if (!replybox) {
  500.           replybox = $("#thingifier-quickreply").detach();
  501.           replybox.appendTo(quoteid);
  502.           replybox = null;
  503.         }
  504.       }
  505.     });
  506.  
  507.     function htmlDecode(input){
  508.       var e = document.createElement('div');
  509.       e.innerHTML = input;
  510.       return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
  511.     }
  512.  
  513.     $('a').click(function(e) { //When we click a link run this code
  514.       if ($(e.target).text() == "Quote") { //Make sure that the clicked link is the quote button
  515.         var quoteid = $(e.target).parents(); //Gets all the parent elements of our link
  516.         quoteid = quoteid[4]; //Selects the fourth parent which is the .forum_post parent of the link
  517.         quoteid = $(quoteid).attr('id'); //Gets the id of the .forum_post parent
  518.         quoteid = "#" + quoteid; //Adds a url anchor sign to the id
  519.         quoteid = quoteid.toString(); //Converts it to a string to make sure it cooperates
  520.         GM_setValue("quoteid", window.pageurl + quoteid);
  521.         var quotename = $(quoteid).find(".user").text(); //Retrieve the quoted user's name
  522.         quotename = quotename.replace(/Staff|Moderator|Uploader/, ""); //For staff, mods, and uploaders find and remove their title
  523.         quotename = $.trim(quotename); //Trim the whitespace/newlines off the beginning and end
  524.         GM_setValue("quotename", quotename);
  525.       } else { /*This is where code would run if we were doing anything for clicking other links*/ }
  526.     });
  527.  
  528.     if (pageurl.match(/posts\/new/)) {
  529.       var post = GM_getValue("quoteid");
  530.       var username = GM_getValue("quotename");
  531.       quote = "> [" + username + "](" + post + ") \n> ";
  532.       console.log(quote);
  533.       var message = "\n" + document.getElementById('forum_post_message').val;
  534.       console.log(message);
  535.       document.getElementById('forum_post_message').value = quote + message;
  536.     }
  537.   });
  538. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement