您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Adds post links and quote stuff to Dynasty forums
当前为
// ==UserScript== // @name Dynasty Thingifier // @namespace Alice Cheshire // @include http://dynasty-scans.com/* // @version 1.4 // @require http://code.jquery.com/jquery-2.1.4.min.js // @description Adds post links and quote stuff to Dynasty forums // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_listValue // @run-at document-end // ==/UserScript== varinit(); checkpostpage(); genmenu(); menuclicks(); cleardata(); configload(); setuserid(); if (window.isuserpostsurl.match(/http:\/\/dynasty-scans.com\/forum\/posts\?user_id=\d+/)) { window.isuserpostsurl = window.isuserpostsurl.replace(/\d+/, ""); //Replaces the user id in the url } for (i = 0; i < window.postcount; i++){ window.counter = i; var id = window.postids[i].toString(); //Temporarily store the post id under the key of 'i' into a variable to use in our next bit if ($('#thingifier-quote-to-quickreply').is(":checked")) { GM_setValue('quote2quickreply', $('#thingifier-quote-to-quickreply').is(":checked")); var tmp = $('.forum_post .info .row .actions').find("span:first-child a"); var tmphref = tmp.attr('href'); var urltmp = document.location.toString(); urltmp = urltmp.replace(/(http:\/\/dynasty-scans\.com\/forum\/topics\/)(\d+)(.+)/, "$2"); var teststring = "http://dynasty-scans.com/forum/posts/new?quote_id=" + id + "&topic_id=" + urltmp; tmp.replaceWith("<input type=\"button\" class=\"postquote\" id=\"" + tmphref + "\" value=\"Quote\" name=\"post_" + window.counter + "\">"); id = id.replace(/forum_post_/, ""); } if(window.isuserpostsurl !== "http://dynasty-scans.com/forum/posts?user_id=") { $(".time").eq(i).replaceWith("<div class=\"span5 time\"><a class=\"timelink\" href=\"" + window.pageurl + "#" + 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 } window.counter++; } function htmlDecode(input){ var e = document.createElement('div'); e.innerHTML = input; return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue; } var quote = $(".info .row .actions span a").attr('href'); $('a').click(function(e) { //When we click a link run this code if ($(e.target).text() == "Quote") { //Make sure that the clicked link is the quote button var quoteid = $(e.target).parents(); //Gets all the parent elements of our link quoteid = quoteid[4]; //Selects the fourth parent which is the .forum_post parent of the link quoteid = $(quoteid).attr('id'); //Gets the id of the .forum_post parent quoteid = "#" + quoteid; //Adds a url anchor sign to the id quoteid = quoteid.toString(); //Converts it to a string to make sure it cooperates GM_setValue("quoteid", window.pageurl + quoteid); var quotename = $(quoteid).find(".user").text(); //Retrieve the quoted user's name quotename = quotename.replace(/Staff|Moderator|Uploader/, ""); //For staff, mods, and uploaders find and remove their title quotename = $.trim(quotename); //Trim the whitespace/newlines off the beginning and end GM_setValue("quotename", quotename); } else { /*This is where code would run if we were doing anything for clicking other links*/ } }); //Checks if we're on the posting page function checkpostpage() { var quoting = pageurl.replace(/http:\/\/dynasty-scans.com\/forum\//, ""); quoting = quoting.replace(/\?.+/, ""); if (quoting === "posts/new") { var post = GM_getValue("quoteid"); var username = GM_getValue("quotename"); quote = "> [" + username + "](" + post + ") \n> "; message = "\n" + document.getElementById('forum_post_message').value; document.getElementById('forum_post_message').value = quote + message; } } //Initializes our global variables function varinit() { window.pageurl = document.location.toString(); //Stores the entire value of the address bar into a variable window.isuserpostsurl = window.pageurl; //Stores the address variable a second time for use in a different function window.postids = []; //Initializes a blank array for the postids window.quote = []; //Initializes blank array for quotes window.postcount = 0; //Counter to keep track of how many posts are on the current page window.counter = 0; window.pageurl = window.pageurl.replace(/(#.+)/, ""); //Removes any anchors from the stored url so we don't get issues with multiple anchors showing up $('.forum_post').each(function() { window.postids.push(this.id); //For each element of the class forum_post push the element's id to our postids array }); $('.time').each(function(i, obj) { window.postcount++; //This is where we actually count how many posts are on the page }); var tmp; if (GM_getValue("youruserid", undefined) === undefined) { tmp = "Not set"; } else { tmp = GM_getValue("youruserid", "Not set"); } if (tmp.match(/\d+/)) { window.yourid = "http://dynasty-scans.com/forum/posts?user_id=" + GM_getValue("youruserid"); window.useridset = true; } else { window.yourid = "Your user id isn't set!"; window.useridset = false; } window.configmenustate = true; window.fontsize = [3, "one", "two", "three", "four", "five"]; } function genmenu(){ var menustructure = '\ <style>\ #thingifier * { padding: 0; margin: 0; }\ #thingifier {\ float: left;\ position: fixed;\ top: 45%;\ z-index: 1000000;\ }\ #thingifier-options {\ border: 1px solid black;\ padding: 8px;\ background: aliceblue;\ border-bottom-right-radius: 6px;\ border-left-width: 0;\ }\ #thingifier-options ul { list-style-type: none; margin-left: -4px;}\ #thingifier-options ul > li { vertical-align: middle; }\ #thingifier ul li input { padding-right: 4px; }\ #thingifier-font-size { width: 96px; }\ #thingifier-toggle-button {\ position: absolute;\ top: 0;\ left: calc(100% - 1px);\ width: 24px;\ height: 24px;\ border: 1px solid black;\ background-color: aliceblue;\ color: red;\ border-top-right-radius: 6px;\ border-bottom-right-radius: 6px;\ border-left-width: 0;\ }\ .spoilers-disabled {\ background: #666 none repeat scroll 0% 0%;\ color: #fff;\ }\ .navbar-fixed {\ position: fixed;\ z-index: 1000;\ width: 1210px;\ }\ .pull-right-fixed, .nav-collapse-fixed {\ float: right;\ }\ .nav-padding {\ height: 60px;\ width: 1210px;\ }\ .forum_post_one {\ font-size: 10px !important;\ line-height: 12px !important;\ }\ .forum_post_two {\ font-size: 12px !important;\ line-height: 15px !important;\ }\ .forum_post_three {\ font-size: 16px !important;\ line-height: 19px !important;\ }\ .forum_post_four {\ font-size: 20px !important;\ line-height: 23px !important;\ }\ .forum_post_five {\ font-size: 25px !important;\ line-height: 28px !important;\ }\ #thingifier-bbcode {\ margin-bottom: 6px;\ }\ #thingifier-quickreply {\ width: 100% !important;\ background-color: aliceblue !important;\ display: inline-block;\ padding: 4px;\ padding-bottom: 8px;\ border-radius: 8px;\ margin-bottom: 6px;\ }\ </style>\ <div id=\"thingifier\">\ <div id=\"thingifier-options\">\ <ul>\ <li><input type=\"checkbox\" id=\"thingifier-unhide-spoilers\"> Unhide spoilers</li>\ <li><input type=\"checkbox\" id=\"thingifier-fixed-navbar\"> Fixed navbar</li>\ <li><input type=\"checkbox\" id=\"thingifier-pagination\"> Add page selector to top of page</li>\ <li><input type=\"checkbox\" id=\"thingifier-bbcode-buttons\"> Add quick reply and post page bbcode buttons</li>\ <li><input type=\"checkbox\" id=\"thingifier-quote-to-quickreply\"> Quote to quick reply instead of new post page</li>\ <li><input type=\"checkbox\" id=\"thingifier-quote-move-quickreply\"> Move quick reply to under quoted post</li>\ <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>\ <li><a href=\"' + window.yourid + '\" id=\"thingifier-ownposts\"> Your posts</a></li>\ <li><input type="text" id="useridinput"><input type="button" value="Submit user id" id="useridsubmit"></li>\ <li><input type=\"button\" id=\"thingifier-clear\" value=\"Clear stored data\"></li>\ </ul>\ </div>\ <div id=\"thingified-toggle\">\ <input type=\"button" id=\"thingifier-toggle-button\" value=\"X\">\ </div></div>'; window.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>'; $('body').prepend(menustructure); $('#useridinput').hide(); $('#useridsubmit').hide(); if (!window.useridset) { GM_deleteValue("youruserid"); $('#thingifier-ownposts').hide(); $('#useridinput').show(); $('#useridsubmit').show(); setuserid(); } else { //Do nothing } } function setuserid() { $('input#useridsubmit').click(function () { if($("input#useridinput").val().match(/^\d+$/)) { GM_setValue("youruserid", $('input#useridinput').val()); $('#useridinput').hide(); $('#useridsubmit').hide(); $('#thingifier-ownposts').show(); $('#thingifier-ownposts').attr('href', "http://dynasty-scans.com/forum/posts?user_id=" + GM_getValue("youruserid")); } else { GM_deleteValue("youruserid"); $("input#useridinput").val(); $('input#useridinput').val("Invalid user id!"); } }); } function cleardata() { $('#thingifier-clear').click(function() { console.log("Clear button clicked"); var x = window.confirm("Are you sure you want to clear your stored data?"); if (x) { GM_deleteValue("youruserid"); GM_deleteValue("quoteid"); GM_deleteValue("quotename"); GM_deleteValue("spoilers"); GM_deleteValue("navbar"); GM_deleteValue("pagination"); GM_deleteValue("bbcode"); GM_deleteValue("quote2quickreply"); console.log(GM_getValue("youruserid", "Not set")); console.log(GM_getValue("quoteid", "Not set")); console.log(GM_getValue("quotename", "Not set")); console.log(GM_getValue("spoilers", "Not set")); console.log(GM_getValue("navbar", "Not set")); console.log(GM_getValue("pagination", "Not set")); console.log(GM_getValue("bbcode", "Not set")); console.log(GM_getValue("quote2quickreply", "Not set")); document.location.reload(true); } else { console.log("Decided against it"); } }); } function menuclicks() { $('#thingifier-toggle-button').click(function() { $("#thingifier-options").animate({width:'toggle', height:'toggle'},350); window.configmenustate ^= true; if (window.configmenustate) { $('#thingifier-toggle-button').val('▶'); } else { $('#thingifier-toggle-button').val('◀'); } GM_setValue("configmenustate", window.configmenustate); }); $('#thingifier-unhide-spoilers').click(function() { if ($('#thingifier-unhide-spoilers').is(":checked")) { GM_setValue("spoilers", $('#thingifier-unhide-spoilers').is(":checked")); $('.spoilers').addClass('spoilers-disabled'); } else { GM_setValue("spoilers", $('#thingifier-unhide-spoilers').is(":checked")); $('.spoilers').removeClass('spoilers-disabled'); } }); $('#thingifier-fixed-navbar').click(function() { if ($('#thingifier-fixed-navbar').is(":checked")) { GM_setValue("navbar", $('#thingifier-fixed-navbar').is(":checked")); $('.navbar').addClass('navbar-fixed'); $("<div class=\"nav-padding\"></div>").insertAfter(".navbar"); } else { GM_setValue("navbar", $('#thingifier-fixed-navbar').is(":checked")); $('.navbar').removeClass('navbar-fixed'); $('div.nav-padding').remove(); } }); $('#thingifier-pagination').click(function() { if ($('#thingifier-pagination').is(":checked")) { GM_setValue("pagination", $('#thingifier-pagination').is(":checked")); $("div.pagination").wrap('<div class=\"tmp\">').parent().html(); var tmp = $('div.tmp').html(); $("div.pagination").unwrap(); $('#main').prepend(tmp); } else { GM_setValue("pagination", $('#thingifier-pagination').is(":checked")); $("div.pagination").first().remove(); } }); $('#thingifier-bbcode-buttons').click(function() { if ($('#thingifier-bbcode-buttons').is(":checked")) { GM_setValue("bbcode", $('#thingifier-bbcode-buttons').is(":checked")); $("#forum_post_message").prepend(window.bbcode_menu); } else { GM_setValue("bbcode", $('#thingifier-bbcode-buttons').is(":checked")); $("div#thingifier-bbcode").remove(); } }); $('#thingifier-quote-to-quickreply').click(function() { GM_setValue('quote2quickreply', $('#thingifier-quote-to-quickreply').is(":checked")); var tmp = $('.forum_post .info .row .actions').find("span:first-child a"); var tmphref = tmp.attr('href'); var urltmp = document.location.toString(); urltmp = urltmp.replace(/(http:\/\/dynasty-scans\.com\/forum\/topics\/)(\d+)(.+)/, "$2"); var teststring = "http://dynasty-scans.com/forum/posts/new?quote_id=" + id + "&topic_id=" + urltmp; tmp.replaceWith("<input type=\"button\" class=\"postquote\" id=\"" + tmphref + "\" value=\"Quote\" name=\"post_" + window.counter + "\">"); id = id.replace(/forum_post_/, ""); }); $('#thingifier-quote-move-quickreply').click(function() { GM_setValue('movequickreply', $('#thingifier-quote-move-quickreply').is(":checked")); window.quickreply = $('#thingifier-quote-move-quickreply').is(":checked"); }); $('#thingifier-font-size').on('input', function() { window.fontsize[0] = parseInt($(this).val()); $('.message *').removeClass('forum_post_one'); $('.message *').removeClass('forum_post_two'); $('.message *').removeClass('forum_post_three'); $('.message *').removeClass('forum_post_four'); $('.message *').removeClass('forum_post_five'); $('.message *').addClass('forum_post_' + window.fontsize[window.fontsize[0]]); GM_setValue('fontsize', window.fontsize[0]); }); $('#thingifier-reset-font').click(function() { $('.message *').removeClass('forum_post_one'); $('.message *').removeClass('forum_post_two'); $('.message *').removeClass('forum_post_three'); $('.message *').removeClass('forum_post_four'); $('.message *').removeClass('forum_post_five'); $('#thingifier-font-size').val(3); GM_deleteValue('fontsize'); }); } $(document).ready(function(){ if (GM_getValue("navbar", false)) { if(document.location.toString().match(/http:\/\/dynasty-scans.com\/forum\/topics\/.+#forum_post_\d+/)) { window.scrollBy(0, -40); //If the fixed navbar is enabled and we load a linked post then offset the scroll } /*$(".time a").on('click',function(e) { console.log(".time a clicked!"); e.preventDefault(); setTimeout(function() {$(this).scrollIntoView();}, 100); //setTimeout(function() {scrollBy(0, -$(this).height())}, 40); });*/ } $('input.postquote').click(function(e) { window.postid = $(this).parents(); window.postid = $(postid[4]).attr('id'); var quoteid = window.postid; //Gets the id of the .forum_post parent quoteid = "#" + quoteid; //Adds a url anchor sign to the id quoteid = quoteid.toString(); //Converts it to a string to make sure it cooperates GM_setValue("quoteid", window.pageurl + quoteid); var quotename = $(quoteid).find(".user").text(); //Retrieve the quoted user's name quotename = quotename.replace(/Staff|Moderator|Uploader/, ""); //For staff, mods, and uploaders find and remove their title quotename = $.trim(quotename); //Trim the whitespace/newlines off the beginning and end GM_setValue("quotename", quotename); window.postid = window.postid.replace(/forum_post_/, ""); var threadid = document.location.toString(); threadid = threadid.replace(/(http:\/\/dynasty-scans\.com\/forum\/topics\/)(\d+)(\S+)/, "$2"); var postpath = "http://dynasty-scans.com/forum/posts/new?quote_id=\"" + window.postid +"\"&topic_id=\"" + threadid + "\""; postpath = postpath.replace(/"/g, ""); window.postid = window.postid.replace(/post_/, ""); $.ajax({ type: "GET", url: postpath, dataType: "html" }) .done(function(data) { window.quote[window.postid] = data.replace(/([\u0000-\uffff]+<textarea .+ id="forum_post_message".+>)([a-zA-Z0-9&#,!-@; \n]+)(<\/textarea>[\u0000-\uffff]+)/, "$2"); window.quote[window.postid] = htmlDecode(window.quote[window.postid]); $('#forum_post_message').val(window.quote[window.postid]); var post = GM_getValue("quoteid"); var username = GM_getValue("quotename"); quote = "> [" + username + "](" + post + ") \n> "; message = "\n" + document.getElementById('forum_post_message').value; document.getElementById('forum_post_message').value = quote + message; }) .fail(function() { console.log("error"); }); if (window.quickreply) { var replybox; $("#new_forum_post").wrap("<div id=\"thingifier-quickreply\"></div>") if (!replybox) { replybox = $("#thingifier-quickreply").detach(); replybox.appendTo(quoteid); replybox = null; } } }); }); function configload() { window.configmenustate = GM_getValue("configmenustate", 1); if (window.configmenustate) { $("#thingifier-options").animate({width:'toggle', height:'toggle'},0); $('#thingifier-toggle-button').val('▶'); } else { $('#thingifier-toggle-button').val('◀'); } window.configspoiler = GM_getValue("spoilers", false); if (window.configspoiler) { $('.spoilers').addClass('spoilers-disabled'); $('#thingifier-unhide-spoilers').prop('checked', true); } window.confignavbar = GM_getValue("navbar", false); if (window.confignavbar ) { $('.navbar').addClass('navbar-fixed'); $("<div class=\"nav-padding\"></div>").insertAfter(".navbar"); $('#thingifier-fixed-navbar').prop('checked', true); } window.configpagination = GM_getValue("pagination", false); if (window.configpagination ) { $("div.pagination").wrap('<div class=\"tmp\">').parent().html(); var tmp = $('div.tmp').html(); $("div.pagination").unwrap(); $('#main').prepend(tmp); $('#thingifier-pagination').prop('checked', true); } window.fontsize[0] = GM_getValue('fontsize', null); if (window.fontsize[0] != null) { $('#thingifier-font-size').val(window.fontsize[0]); $('.message *').addClass('forum_post_' + window.fontsize[window.fontsize[0]]); } window.bbcode = GM_getValue('bbcode', null); if (window.bbcode) { $("textarea#forum_post_message").before(window.bbcode_menu); $('#thingifier-bbcode-buttons').prop('checked', true); } window.quote2quickreply = GM_getValue('quote2quickreply', null); if (window.quote2quickreply) { $('#thingifier-quote-to-quickreply').prop('checked', true); for (i = 0; i < window.postcount; i++){ var id = window.postids[i].toString(); //Temporarily store the post id under the key of 'i' into a variable to use in our next bit var tmp = $('.forum_post .info .row .actions').find("span:first-child a"); var tmphref = tmp.attr('href'); var urltmp = document.location.toString(); urltmp = urltmp.replace(/(http:\/\/dynasty-scans\.com\/forum\/topics\/)(\d+)(.+)/, "$2"); var teststring = "http://dynasty-scans.com/forum/posts/new?quote_id=" + id + "&topic_id=" + urltmp; tmp.replaceWith("<input type=\"button\" class=\"postquote\" id=\"" + tmphref + "\" value=\"Quote\" name=\"post_" + window.counter + "\">"); id = id.replace(/forum_post_/, ""); } } window.quickreply = GM_getValue('movequickreply', null); if (window.quickreply) { $('#thingifier-quote-move-quickreply').prop('checked', true); } $('#forum_post_message').mousedown(function() { $('body').mousemove(function() { getSel(); window.texttmp = window.sel; window.posttmp = $('#forum_post_message').val(); window.regextmp = new RegExp("("+window.texttmp.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&")+")"); window.posttmp = window.posttmp.replace(window.regextmp, "[BBCODE-HERE]"); }); }); function getSel() // javascript { // obtain the object reference for the <textarea> var txtarea = document.getElementById("forum_post_message"); // obtain the index of the first selected character var start = txtarea.selectionStart; // obtain the index of the last selected character var finish = txtarea.selectionEnd; // obtain the selected text window.sel = txtarea.value.substring(start, finish); // do something with the selected content } $('#thingifier-bbcode-quote').click(function() { window.texttmp = window.texttmp.replace(/(^\S)/gm, "> $1"); bbcode_format(); }); $('#thingifier-bbcode-link').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "[]($1)"); bbcode_format(); }); $('#thingifier-bbcode-image').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, ""); bbcode_format(); }); $('#thingifier-bbcode-spoiler').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "==$1=="); bbcode_format(); }); $('#thingifier-bbcode-hr').click(function() { window.texttmp = window.texttmp.replace(/(^\S)/gm, "\n***\n $1"); bbcode_format(); }); $('#thingifier-bbcode-ul').click(function() { window.texttmp = window.texttmp.replace(/(^\S)/gm, " * $1"); bbcode_format(); }); $('#thingifier-bbcode-ol').click(function() { window.texttmp = window.texttmp.replace(/(^\S)/gm, " 1. $1"); bbcode_format(); }); $('#thingifier-bbcode-italics').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "*$1*"); bbcode_format(); }); $('#thingifier-bbcode-bold').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "**$1**"); bbcode_format(); }); $('#thingifier-bbcode-tag').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "`$1`"); bbcode_format(); }); $('#thingifier-bbcode-codeblock').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, " $1 "); bbcode_format(); }); $('#thingifier-bbcode-h1').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "# $1 #"); bbcode_format(); }); $('#thingifier-bbcode-h2').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "## $1 ##"); bbcode_format(); }); $('#thingifier-bbcode-h3').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "### $1 ###"); bbcode_format(); }); $('#thingifier-bbcode-h4').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "#### $1 ####"); bbcode_format(); }); $('#thingifier-bbcode-h5').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "##### $1 #####"); bbcode_format(); }); $('#thingifier-bbcode-h6').click(function() { window.texttmp = window.texttmp.replace(/(.+)/gm, "###### $1 ######"); bbcode_format(); }); function bbcode_format() { window.posttmp = window.posttmp.replace(/\[BBCODE-HERE\]/, window.texttmp); $('#forum_post_message').val(window.posttmp); } }